Skip to content

Commit

Permalink
Manually fix the rest of clippy warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreLachanceGit committed Jul 7, 2023
1 parent c42dea3 commit f26323a
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 207 deletions.
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};
2 changes: 1 addition & 1 deletion 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 Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/features/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ pub fn get_tokens(ast_query: &Arc<Mutex<impl AstQuery>>) -> SemanticTokensResult
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 Down
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
228 changes: 99 additions & 129 deletions src/metadata/ast/translator.rs

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions src/metadata/ast/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,13 @@ impl Ast {
indent.to_string() + "| "
};

let mut i = 0;
for child in node_id.children(&self.arena) {
for (i, child) in node_id.children(&self.arena).enumerate() {
self._get_debug_tree(
child,
&indent,
i == node_id.children(&self.arena).collect::<Vec<_>>().len() - 1,
result,
);
i += 1;
}
}
}
79 changes: 30 additions & 49 deletions src/metadata/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ impl SymbolTableActions for SymbolTable {
}
}
}
for index_name in 1..(names.len() - 1) {
let test = names[index_name];
let fields = symbol.contains_fields(test.to_string());

for name in names.iter().take(names.len() - 1).skip(1) {
let fields = symbol.contains_fields(name.to_string());
if let Some(field) = fields {
if let Some(x) = field.type_.get_name() {
if x == Type::Name {
Expand Down Expand Up @@ -394,50 +394,34 @@ impl Symbols {
}

pub fn find_mut(&mut self, name: &str) -> Option<&mut Symbol> {
for symbol in &mut self.types {
if symbol.name == name {
return Some(symbol);
}
if let Some(s) = self.types.iter_mut().find(|symbol| symbol.name == name) {
return Some(s);
}
for symbol in &mut self.constants {
if symbol.name == name {
return Some(symbol);
}
if let Some(s) = self.constants.iter_mut().find(|symbol| symbol.name == name) {
return Some(s);
}
for symbol in &mut self.variables {
if symbol.name == name {
return Some(symbol);
}
if let Some(s) = self.variables.iter_mut().find(|symbol| symbol.name == name) {
return Some(s);
}
for symbol in &mut self.functions {
if symbol.name == name {
return Some(symbol);
}
if let Some(s) = self.functions.iter_mut().find(|symbol| symbol.name == name) {
return Some(s);
}

None
}

pub fn get_mut(&mut self, id: usize) -> Option<&mut Symbol> {
for symbol in &mut self.types {
if symbol.id == id {
return Some(symbol);
}
if let Some(s) = self.types.iter_mut().find(|symbol| symbol.id == id) {
return Some(s);
}
for symbol in &mut self.constants {
if symbol.id == id {
return Some(symbol);
}
if let Some(s) = self.constants.iter_mut().find(|symbol| symbol.id == id) {
return Some(s);
}
for symbol in &mut self.variables {
if symbol.id == id {
return Some(symbol);
}
if let Some(s) = self.variables.iter_mut().find(|symbol| symbol.id == id) {
return Some(s);
}
for symbol in &mut self.functions {
if symbol.id == id {
return Some(symbol);
}
if let Some(s) = self.functions.iter_mut().find(|symbol| symbol.id == id) {
return Some(s);
}

None
Expand Down Expand Up @@ -558,16 +542,14 @@ impl ScopeSymbolTable {
type2: NodeKind,
) -> Vec<Field> {
let mut fields: Vec<Field> = vec![];
let fields_node: VisitNode =
match child_visit_node.get_child_of_kind(type1) {
Some(x) => x,
None => {
return fields;
}
};

let fields_node: VisitNode;
match child_visit_node.get_child_of_kind(type1) {
Some(x) => {
fields_node = x;
}
None => {
return fields;
}
}
for field_visit in fields_node.get_children() {
let param_node = field_visit.get();
if param_node.kind == type2 {
Expand Down Expand Up @@ -636,12 +618,11 @@ impl ScopeSymbolTable {
TypeDecType::Package => {}
}

let fields_symbol: Option<Vec<Field>>;
if fields.is_empty() {
fields_symbol = None;
let fields_symbol: Option<Vec<Field>> = if fields.is_empty() {
None
} else {
fields_symbol = Some(fields);
}
Some(fields)
};

table.symbols.types.push(Symbol::new(
name,
Expand Down
30 changes: 14 additions & 16 deletions src/plugin_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,21 @@ impl PluginManager {
}
};

for path in paths {
if let Ok(dir_entry) = path {
info!("Loading plugin: {}", dir_entry.path().display());
let file_content = fs::read(dir_entry.path()).unwrap();
let functions = (*FUNCTIONS).clone();
for dir_entry in paths.flatten() {
info!("Loading plugin: {}", dir_entry.path().display());
let file_content = fs::read(dir_entry.path()).unwrap();
let functions = (*FUNCTIONS).clone();

match Plugin::create(file_content, functions, true) {
Ok(plugin) => {
self.plugins.push(plugin);
}
Err(err) => {
error!(
"Failed loading plugin: {} Error: {}",
dir_entry.path().display(),
err
);
}
match Plugin::create(file_content, functions, true) {
Ok(plugin) => {
self.plugins.push(plugin);
}
Err(err) => {
error!(
"Failed loading plugin: {} Error: {}",
dir_entry.path().display(),
err
);
}
}
}
Expand Down

0 comments on commit f26323a

Please sign in to comment.