Skip to content

Commit

Permalink
Merge pull request #15 from ace-design/dev
Browse files Browse the repository at this point in the history
Cleanup code and small fixes.
  • Loading branch information
AlexandreLachanceGit authored Jul 7, 2023
2 parents ee65854 + f26323a commit 3ff9c45
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 327 deletions.
2 changes: 1 addition & 1 deletion examples/basic.p4
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
HashAlgorithm.csum16);
}
}
ad

/*************************************************************************
*********************** D E P A R S E R *******************************
*************************************************************************/
Expand Down
4 changes: 1 addition & 3 deletions src/features/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ pub fn get_list(
.build(),
)
}
None => {
return default(position, query);
}
None => default(position, query),
}
}
4 changes: 2 additions & 2 deletions src/features/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod diagnostics;
mod parse;
mod provider;

pub use diagnostics::{get_full_diagnostics, get_quick_diagnostics};
pub use provider::{get_full_diagnostics, get_quick_diagnostics};
4 changes: 2 additions & 2 deletions src/features/diagnostics/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
use crate::metadata::{AstQuery, NodeKind, SymbolTableQuery, VisitNode, Visitable};
use tower_lsp::lsp_types::{Diagnostic, DiagnosticSeverity};

use super::diagnostics::DiagnosticProvider;
use super::provider::DiagnosticProvider;

pub struct Parse {}

Expand All @@ -17,7 +17,7 @@ impl DiagnosticProvider for Parse {
let mut errors: Vec<VisitNode> = vec![];
for node in root.get_descendants() {
if let NodeKind::Error = node.get().kind {
errors.push(node.clone())
errors.push(node)
};
}

Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions src/features/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ pub fn get_tokens(ast_query: &Arc<Mutex<impl AstQuery>>) -> SemanticTokensResult

prev = item.line;
//If line is greater than 0 then we save the temp array of tokens
if line > 0 && temp_array.len() > 0 {
if line > 0 && !temp_array.is_empty() {
let mut max_val = 0;
temp_array.sort_by_key(|&token| token.delta_start); //sorting the start pos
//setting the first deltaline to conatin the diff value (line) and setting all other to 0
for i in 0..temp_array.len() {
if temp_array[i].delta_line > max_val {
max_val = temp_array[i].delta_line;
for item in &mut temp_array {
if item.delta_line > max_val {
max_val = item.delta_line;
}
temp_array[i].delta_line = 0;
item.delta_line = 0;
}
temp_array[0].delta_line = max_val;

Expand All @@ -67,14 +67,14 @@ pub fn get_tokens(ast_query: &Arc<Mutex<impl AstQuery>>) -> SemanticTokensResult
.map(|token| {
let temp_token = SemanticToken {
delta_line: token.delta_line,
delta_start: token.delta_start - prev_start.clone(),
delta_start: token.delta_start - prev_start,
length: token.length,
token_type: token.token_type,
token_modifiers_bitset: 0,
};

prev_start = token.delta_start;
return temp_token;
temp_token
})
.collect();

Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn get_visit_nodes(visit_node: VisitNode) -> Vec<ColorData> {
let childrens = visit_node.get_children();
let mut array: Vec<ColorData> = Vec::new();
for child in &childrens {
array.append(&mut get_visit_nodes(child.clone()));
array.append(&mut get_visit_nodes(*child));
}

//Setting the node kidn with associated index from token type vector
Expand Down Expand Up @@ -155,14 +155,14 @@ pub fn get_visit_nodes(visit_node: VisitNode) -> Vec<ColorData> {
if node_type != temp_cmp {
let temp_length = ((node_visit.range.end.character - node_visit.range.start.character)
as i32)
.abs() as u32;
.unsigned_abs();
array.push(ColorData {
length: temp_length,
start: node_visit.range.start.character,
line: node_visit.range.start.line,
node_type: node_type,
node_type,
});
}

return array;
array
}
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ impl LanguageServer for Backend {

self.plugin_manager.write().unwrap().load_plugins();

let mut completion_temp = CompletionOptions::default();
completion_temp.trigger_characters = Some(vec![".".to_string()]);
Ok(InitializeResult {
capabilities: ServerCapabilities {
semantic_tokens_provider: Some(
Expand All @@ -76,7 +74,10 @@ impl LanguageServer for Backend {
),
),
hover_provider: Some(HoverProviderCapability::Simple(true)),
completion_provider: Some(completion_temp),
completion_provider: Some(CompletionOptions {
trigger_characters: Some(vec![String::from(".")]),
..Default::default()
}),
text_document_sync: Some(TextDocumentSyncCapability::Options(
TextDocumentSyncOptions {
open_close: Some(true),
Expand Down
Loading

0 comments on commit 3ff9c45

Please sign in to comment.