From de513d0a4bcf85684b0f0e23fa298c45d18b01c6 Mon Sep 17 00:00:00 2001 From: 0xSwapFeeder Date: Mon, 9 Oct 2023 17:02:06 -0400 Subject: [PATCH] fix(solidity/lint/core): fixed lint and compile issues --- libs/ast-extractor/src/extract.rs | 1 - libs/ast-extractor/src/retriever.rs | 2 +- libs/ast-extractor/src/retriever/expr_call.rs | 2 +- libs/ast-extractor/src/retriever/finder.rs | 289 ++++++++++++------ .../src/retriever/finder/find_node.rs | 46 +-- libs/ast-extractor/src/retriever/stmts.rs | 4 +- libs/lsp-server-wrapper/src/client.rs | 92 +++--- libs/lsp-server-wrapper/src/jsonrpc.rs | 2 +- libs/lsp-server-wrapper/src/jsonrpc/error.rs | 6 +- libs/lsp-server-wrapper/src/lib.rs | 28 +- libs/lsp-server-wrapper/src/server.rs | 62 ++-- libs/lsp-server-wrapper/src/service.rs | 181 +++++------ libs/lsp-server-wrapper/src/service/state.rs | 2 +- .../rules/best_practises/explicit_types.rs | 12 +- .../src/rules/best_practises/reason_string.rs | 4 +- .../src/rules/naming/foundry_func_name.rs | 26 +- .../src/rules/naming/func_visibility.rs | 4 +- .../solidhunter-lib/src/rules/naming/mod.rs | 8 +- .../naming/private_vars_leading_underscore.rs | 59 ++-- .../src/rules/order/ordering.rs | 76 ++--- .../core/solidhunter-lib/tests/linter.rs | 2 +- 21 files changed, 542 insertions(+), 366 deletions(-) diff --git a/libs/ast-extractor/src/extract.rs b/libs/ast-extractor/src/extract.rs index e51cd39a..0b88575d 100644 --- a/libs/ast-extractor/src/extract.rs +++ b/libs/ast-extractor/src/extract.rs @@ -13,7 +13,6 @@ pub fn extract_ast_from_content(content: &str) -> Result { - ($pos.line == $start.line && $pos.char >= $start.column && $start.line != $end.line) || - ($pos.line == $end.line && $pos.char <= $end.column && $start.line != $end.line) || - ($pos.line == $start.line && $pos.line == $end.line && $pos.char >= $start.column && $pos.char <= $end.column) || - ($pos.line > $start.line && $pos.line < $end.line) + ($pos.line == $start.line && $pos.char >= $start.column && $start.line != $end.line) + || ($pos.line == $end.line && $pos.char <= $end.column && $start.line != $end.line) + || ($pos.line == $start.line + && $pos.line == $end.line + && $pos.char >= $start.column + && $pos.char <= $end.column) + || ($pos.line > $start.line && $pos.line < $end.line) }; } @@ -29,16 +30,10 @@ pub struct Position { impl Position { pub fn new(line: usize, char: usize) -> Self { - Self { - line, - char, - } + Self { line, char } } - } - - struct FinderVisitor { current_contract: Option, current_function: Option, @@ -54,9 +49,7 @@ struct FinderVisitor { to_find: Position, } - impl FinderVisitor { - pub fn new(pos: Position) -> Self { Self { current_contract: None, @@ -76,10 +69,17 @@ impl FinderVisitor { fn check_inheritance_matching(&mut self, contract: &ItemContract) -> bool { if let Some(inheritance) = &contract.inheritance { - if is_in_range!(inheritance.span().start(), inheritance.span().end(), self.to_find) { + if is_in_range!( + inheritance.span().start(), + inheritance.span().end(), + self.to_find + ) { for inherit in &inheritance.inheritance { if is_in_range!(inherit.span().start(), inherit.span().end(), self.to_find) { - self.found = Some(FoundNode::ContractDefInheritance(contract.clone(), inherit.clone())); + self.found = Some(FoundNode::ContractDefInheritance( + contract.clone(), + inherit.clone(), + )); return true; } } @@ -106,11 +106,18 @@ impl<'ast> Visit<'ast> for FinderVisitor { } } - fn visit_expr_call(&mut self, call: &'ast ExprCall) { if is_in_range!(call.span().start(), call.span().end(), self.to_find) { - if !is_in_range!(call.args.span().start(), call.args.span().end(), self.to_find) { - self.found = Some(FoundNode::IdentUsageCall(self.current_contract.clone(), self.current_function.clone(), call.clone())); + if !is_in_range!( + call.args.span().start(), + call.args.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::IdentUsageCall( + self.current_contract.clone(), + self.current_function.clone(), + call.clone(), + )); } visit::visit_expr_call(self, call); } @@ -120,14 +127,23 @@ impl<'ast> Visit<'ast> for FinderVisitor { // Therefore we can not goto or list_ref any variable used in a new expr fn visit_expr_new(&mut self, new: &'ast ExprNew) { if is_in_range!(new.ty.span().start(), new.ty.span().end(), self.to_find) { - self.found = Some(FoundNode::ContractInstantiation(self.current_contract.clone().unwrap(), self.current_function.clone(), new.clone())); + self.found = Some(FoundNode::ContractInstantiation( + self.current_contract.clone().unwrap(), + self.current_function.clone(), + new.clone(), + )); } } fn visit_type(&mut self, ty: &'ast Type) { println!("type: {:?}", ty); if is_in_range!(ty.span().start(), ty.span().end(), self.to_find) { - self.found = Some(FoundNode::TypeUsage(self.current_contract.clone(), self.current_function.clone(), self.current_expr.clone(), ty.clone())); + self.found = Some(FoundNode::TypeUsage( + self.current_contract.clone(), + self.current_function.clone(), + self.current_expr.clone(), + ty.clone(), + )); visit::visit_type(self, ty); } } @@ -138,16 +154,24 @@ impl<'ast> Visit<'ast> for FinderVisitor { let _s = var.name.span().start(); let _e = var.name.span().end(); if is_in_range!(var.name.span().start(), var.name.span().end(), self.to_find) { - self.found = Some(FoundNode::VariableDefName(self.current_contract.clone(), self.current_function.clone(), var.clone(), var.name.clone())); - return; + self.found = Some(FoundNode::VariableDefName( + self.current_contract.clone(), + self.current_function.clone(), + var.clone(), + var.name.clone(), + )); + return; } visit_variable_declaration(self, var); } - } fn visit_stmt_var_decl(&mut self, stmt_var_decl: &'ast StmtVarDecl) { - if is_in_range!(stmt_var_decl.span().start(), stmt_var_decl.span().end(), self.to_find) { + if is_in_range!( + stmt_var_decl.span().start(), + stmt_var_decl.span().end(), + self.to_find + ) { visit::visit_stmt_var_decl(self, stmt_var_decl); } } @@ -157,9 +181,16 @@ impl<'ast> Visit<'ast> for FinderVisitor { self.current_property = Some(var.clone()); if is_in_range!(var.name.span().start(), var.name.span().end(), self.to_find) { if self.current_contract.is_none() { - self.found = Some(FoundNode::ConstantVariableDefName(var.clone(), var.name.clone())) + self.found = Some(FoundNode::ConstantVariableDefName( + var.clone(), + var.name.clone(), + )) } else { - self.found = Some(FoundNode::PropertyDefName(self.current_contract.clone().unwrap(),var.clone(), var.name.clone())); + self.found = Some(FoundNode::PropertyDefName( + self.current_contract.clone().unwrap(), + var.clone(), + var.name.clone(), + )); } return; } @@ -175,7 +206,11 @@ impl<'ast> Visit<'ast> for FinderVisitor { self.found = Some(FoundNode::ContractDefName(contract.clone())); } self.check_inheritance_matching(contract); - if is_in_range!(contract.brace_token.span().start(), contract.brace_token.span().end(), self.to_find) { + if is_in_range!( + contract.brace_token.span().start(), + contract.brace_token.span().end(), + self.to_find + ) { visit::visit_item_contract(self, contract); } self.current_contract = None; @@ -183,13 +218,30 @@ impl<'ast> Visit<'ast> for FinderVisitor { fn visit_item_enum(&mut self, enumm: &'ast ItemEnum) { self.current_enum = Some(enumm.clone()); - if is_in_range!(enumm.name.span().start(), enumm.name.span().end(), self.to_find) { - self.found = Some(FoundNode::EnumDefName(self.current_contract.clone(),enumm.clone(), enumm.name.clone())); + if is_in_range!( + enumm.name.span().start(), + enumm.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::EnumDefName( + self.current_contract.clone(), + enumm.clone(), + enumm.name.clone(), + )); return; } for variant in &enumm.variants { - if is_in_range!(variant.ident.span().start(), variant.ident.span().end(), self.to_find) { - self.found = Some(FoundNode::EnumDefValue(self.current_contract.clone(), enumm.clone(), variant.clone(), variant.ident.clone())); + if is_in_range!( + variant.ident.span().start(), + variant.ident.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::EnumDefValue( + self.current_contract.clone(), + enumm.clone(), + variant.clone(), + variant.ident.clone(), + )); return; } } @@ -199,30 +251,61 @@ impl<'ast> Visit<'ast> for FinderVisitor { fn visit_item_error(&mut self, error: &'ast ItemError) { self.current_error = Some(error.clone()); - if is_in_range!(error.name.span().start(), error.name.span().end(), self.to_find) { - self.found = Some(FoundNode::ErrorDefName(self.current_contract.clone(), error.clone(), error.name.clone())); + if is_in_range!( + error.name.span().start(), + error.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::ErrorDefName( + self.current_contract.clone(), + error.clone(), + error.name.clone(), + )); return; } for param in &error.parameters { - if is_in_range!(param.name.span().start(), param.name.span().end(), self.to_find) { - self.found = Some(FoundNode::ErrorDefParameter(self.current_contract.clone(), error.clone(), param.clone())); + if is_in_range!( + param.name.span().start(), + param.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::ErrorDefParameter( + self.current_contract.clone(), + error.clone(), + param.clone(), + )); return; } } visit::visit_item_error(self, error); self.current_error = None; - } fn visit_item_event(&mut self, event: &'ast ItemEvent) { self.current_event = Some(event.clone()); - if is_in_range!(event.name.span().start(), event.name.span().end(), self.to_find) { - self.found = Some(FoundNode::EventDefName(self.current_contract.clone().unwrap(), event.clone(), event.name.clone())); + if is_in_range!( + event.name.span().start(), + event.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::EventDefName( + self.current_contract.clone().unwrap(), + event.clone(), + event.name.clone(), + )); return; } for param in &event.parameters { - if is_in_range!(param.name.span().start(), param.name.span().end(), self.to_find) { - self.found = Some(FoundNode::EventDefParameter(self.current_contract.clone().unwrap(), event.clone(), param.clone())); + if is_in_range!( + param.name.span().start(), + param.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::EventDefParameter( + self.current_contract.clone().unwrap(), + event.clone(), + param.clone(), + )); return; } } @@ -232,15 +315,35 @@ impl<'ast> Visit<'ast> for FinderVisitor { fn visit_item_function(&mut self, function: &'ast ItemFunction) { self.current_function = Some(function.clone()); - if is_in_range!(function.name.span().start(), function.name.span().end(), self.to_find) { - self.found = Some(FoundNode::FunctionDefName(self.current_contract.clone().unwrap(), function.clone())); + if is_in_range!( + function.name.span().start(), + function.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::FunctionDefName( + self.current_contract.clone().unwrap(), + function.clone(), + )); return; } - if is_in_range!(function.arguments.span().start(), function.arguments.span().end(), self.to_find) { + if is_in_range!( + function.arguments.span().start(), + function.arguments.span().end(), + self.to_find + ) { for param in &function.arguments { - if is_in_range!(param.name.span().start(), param.name.span().end(), self.to_find) { - self.found = Some(FoundNode::FunctionDefParameterName(self.current_contract.clone().unwrap(), function.clone(), param.clone(), param.name.clone())); + if is_in_range!( + param.name.span().start(), + param.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::FunctionDefParameterName( + self.current_contract.clone().unwrap(), + function.clone(), + param.clone(), + param.name.clone(), + )); break; } } @@ -261,20 +364,44 @@ impl<'ast> Visit<'ast> for FinderVisitor { return; } if is_in_range!(ident.span().start(), ident.span().end(), self.to_find) { - self.found = Some(FoundNode::IdentUsageName(self.current_contract.clone(), self.current_function.clone(), self.current_expr.clone(), ident.clone())); + self.found = Some(FoundNode::IdentUsageName( + self.current_contract.clone(), + self.current_function.clone(), + self.current_expr.clone(), + ident.clone(), + )); } } fn visit_item_struct(&mut self, strukt: &'ast ItemStruct) { self.current_struct = Some(strukt.clone()); - if is_in_range!(strukt.name.span().start(), strukt.name.span().end(), self.to_find) { - self.found = Some(FoundNode::StructDefName(self.current_contract.clone(), strukt.name.clone())); + if is_in_range!( + strukt.name.span().start(), + strukt.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::StructDefName( + self.current_contract.clone(), + strukt.name.clone(), + )); return; } - if is_in_range!(strukt.brace_token.span().start(), strukt.brace_token.span().end(), self.to_find) { + if is_in_range!( + strukt.brace_token.span().start(), + strukt.brace_token.span().end(), + self.to_find + ) { for field in &strukt.fields { - if is_in_range!(field.name.span().start(), field.name.span().end(), self.to_find) { - self.found = Some(FoundNode::StructDefPropertyName( self.current_contract.clone(), field.clone(), field.name.clone())); + if is_in_range!( + field.name.span().start(), + field.name.span().end(), + self.to_find + ) { + self.found = Some(FoundNode::StructDefPropertyName( + self.current_contract.clone(), + field.clone(), + field.name.clone(), + )); return; } } @@ -282,27 +409,23 @@ impl<'ast> Visit<'ast> for FinderVisitor { } self.current_struct = None; } - } - pub fn retrieve_node_from_position(ast: &File, pos: Position) -> Option { let mut visitor = FinderVisitor::new(pos); visitor.visit_file(ast); visitor.found } - #[cfg(test)] mod tests { + use proc_macro2::TokenStream; use std::fs; use std::path::PathBuf; - use proc_macro2::TokenStream; use super::*; use std::str::FromStr; - #[test] fn test_retrieve_contract_def_name() { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -371,7 +494,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(15, 22)); - + if let Some(FoundNode::ContractInstantiation(_contract, _func, expr)) = res { if let Type::Custom(sol_path) = &expr.ty { assert_eq!(sol_path.to_string(), "One"); @@ -505,7 +628,6 @@ mod tests { } } - #[test] fn test_retrieve_type_string() { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -518,7 +640,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(4, 10)); - if let Some(FoundNode::TypeUsage(_,_,_,Type::String(_))) = res { + if let Some(FoundNode::TypeUsage(_, _, _, Type::String(_))) = res { } else { panic!() } @@ -559,7 +681,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(13, 12)); - if let Some(FoundNode::TypeUsage(_,_,_expr, Type::Custom(ident))) = res { + if let Some(FoundNode::TypeUsage(_, _, _expr, Type::Custom(ident))) = res { assert_eq!(ident.to_string(), "another_one"); } else { panic!() @@ -578,8 +700,8 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(7, 42)); - - if let Some(FoundNode::TypeUsage(_,_,_expr, Type::Uint(_,_))) = res { + + if let Some(FoundNode::TypeUsage(_, _, _expr, Type::Uint(_, _))) = res { } else { panic!() } @@ -637,7 +759,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(8, 18)); - + if let Some(FoundNode::StructDefPropertyName(contract, _var, Some(ident))) = res { assert!(contract.is_some()); assert_eq!(ident.to_string(), "storedData1"); @@ -658,7 +780,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(2, 17)); - + if let Some(FoundNode::StructDefPropertyName(contract, _var, Some(ident))) = res { assert!(contract.is_none()); assert_eq!(ident.to_string(), "storedData1"); @@ -679,7 +801,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(12, 14)); - + if let Some(FoundNode::EnumDefName(contract, _ennum, ident)) = res { assert!(contract.is_some()); assert_eq!(ident.to_string(), "another_one"); @@ -700,7 +822,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(14, 12)); - + if let Some(FoundNode::EnumDefValue(contract, _ennum, _variant, ident)) = res { assert!(contract.is_some()); assert_eq!(ident.to_string(), "Tuesday"); @@ -721,7 +843,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(1, 8)); - + if let Some(FoundNode::EnumDefName(contract, _ennum, ident)) = res { assert!(contract.is_none()); assert_eq!(ident.to_string(), "one"); @@ -742,7 +864,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(3, 8)); - + if let Some(FoundNode::EnumDefValue(contract, _ennum, _variant, ident)) = res { assert!(contract.is_none()); assert_eq!(ident.to_string(), "Tuesday"); @@ -763,7 +885,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(1, 8)); - + if let Some(FoundNode::ErrorDefName(contract, _err, ident)) = res { assert!(contract.is_none()); assert_eq!(ident.to_string(), "one"); @@ -784,7 +906,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(4, 16)); - + if let Some(FoundNode::ErrorDefName(contract, _err, ident)) = res { assert!(contract.is_some()); assert_eq!(ident.to_string(), "another_one"); @@ -805,7 +927,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(4, 33)); - + if let Some(FoundNode::ErrorDefParameter(contract, _err, ident)) = res { assert!(contract.is_some()); if let Some(name) = &ident.name { @@ -830,13 +952,12 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(1, 21)); - + if let Some(FoundNode::ErrorDefParameter(contract, _err, ident)) = res { assert!(contract.is_none()); if let Some(name) = &ident.name { assert_eq!(name.to_string(), "val1"); - } - else { + } else { panic!() } } else { @@ -856,8 +977,8 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(4, 16)); - - if let Some(FoundNode::EventDefName(_contract, _err, ident) ) = res { + + if let Some(FoundNode::EventDefName(_contract, _err, ident)) = res { assert_eq!(ident.to_string(), "another_one"); } else { panic!() @@ -888,7 +1009,6 @@ mod tests { } } - #[test] fn test_retrieve_prop_usage_on_assign() { let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -901,7 +1021,7 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(5, 14)); - + if let Some(FoundNode::IdentUsageName(_contract, _func, _expr, ident)) = res { assert_eq!(ident.to_string(), "storedData"); } else { @@ -921,8 +1041,8 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(9, 22)); - - if let Some(FoundNode::IdentUsageName(_contract, _func, _expr, ident) ) = res { + + if let Some(FoundNode::IdentUsageName(_contract, _func, _expr, ident)) = res { assert_eq!(ident.to_string(), "storedData"); } else { panic!() @@ -941,12 +1061,11 @@ mod tests { let tokens = TokenStream::from_str(source.as_str()).unwrap(); let ast = parse2(tokens).unwrap(); let res = retrieve_node_from_position(&ast, Position::new(5, 22)); - + if let Some(FoundNode::IdentUsageName(_contract, _func, _expr, ident)) = res { assert_eq!(ident.to_string(), "x"); } else { panic!() } } - } diff --git a/libs/ast-extractor/src/retriever/finder/find_node.rs b/libs/ast-extractor/src/retriever/finder/find_node.rs index 83878f1e..9a137c41 100644 --- a/libs/ast-extractor/src/retriever/finder/find_node.rs +++ b/libs/ast-extractor/src/retriever/finder/find_node.rs @@ -1,11 +1,12 @@ - /** * find_node.rs * Enum for all possible ast types that can be found * author: 0xMemoryGrinder */ - -use syn_solidity::{ExprNew, ItemContract, ItemEnum, ItemFunction, VariableDeclaration, ExprCall, SolIdent, VariableDefinition, Type, Expr, Variant, ItemEvent, ItemError, Modifier, EventParameter}; +use syn_solidity::{ + EventParameter, Expr, ExprCall, ExprNew, ItemContract, ItemEnum, ItemError, ItemEvent, + ItemFunction, Modifier, SolIdent, Type, VariableDeclaration, VariableDefinition, Variant, +}; #[derive(Debug)] pub enum FoundNode { @@ -14,21 +15,39 @@ pub enum FoundNode { ContractDefInheritance(ItemContract, Modifier), ContractInstantiation(ItemContract, Option, ExprNew), - // Functions FunctionDefName(ItemContract, ItemFunction), - FunctionDefParameterName(ItemContract, ItemFunction, VariableDeclaration, Option), + FunctionDefParameterName( + ItemContract, + ItemFunction, + VariableDeclaration, + Option, + ), // Properties/Variables/Constants PropertyDefName(ItemContract, VariableDefinition, SolIdent), ConstantVariableDefName(VariableDefinition, SolIdent), - VariableDefName(Option, Option, VariableDeclaration, Option), + VariableDefName( + Option, + Option, + VariableDeclaration, + Option, + ), // Types and Identifiers - TypeUsage(Option, Option, Option, Type), + TypeUsage( + Option, + Option, + Option, + Type, + ), IdentUsageCall(Option, Option, ExprCall), - IdentUsageName(Option, Option, Option, SolIdent), - + IdentUsageName( + Option, + Option, + Option, + SolIdent, + ), // Structs StructDefName(Option, SolIdent), @@ -42,13 +61,9 @@ pub enum FoundNode { ErrorDefName(Option, ItemError, SolIdent), ErrorDefParameter(Option, ItemError, VariableDeclaration), - - // Events EventDefName(ItemContract, ItemEvent, SolIdent), EventDefParameter(ItemContract, ItemEvent, EventParameter), - - // Contracts //ContractScope(ItemContract, Option, SolPath), @@ -65,15 +80,12 @@ pub enum FoundNode { //StructUsageName(ItemContract, Option, Expr, Type), //StructUsageProperty(ItemContract, Option, Expr, SolIdent, Type), - // Errors //ErrorUsageName(ItemContract, Option, ExprCall, SolIdent), - // Events //EventUsageName(ItemContract, Option, Expr, SolIdent), - //TODO type cast // TODO super ast node -} \ No newline at end of file +} diff --git a/libs/ast-extractor/src/retriever/stmts.rs b/libs/ast-extractor/src/retriever/stmts.rs index b4310a53..508e4a9a 100644 --- a/libs/ast-extractor/src/retriever/stmts.rs +++ b/libs/ast-extractor/src/retriever/stmts.rs @@ -11,9 +11,7 @@ struct SmtsVisitor { impl SmtsVisitor { pub fn new() -> Self { - Self { - stmts: Vec::new(), - } + Self { stmts: Vec::new() } } } diff --git a/libs/lsp-server-wrapper/src/client.rs b/libs/lsp-server-wrapper/src/client.rs index 4450f384..a593f9ef 100644 --- a/libs/lsp-server-wrapper/src/client.rs +++ b/libs/lsp-server-wrapper/src/client.rs @@ -1,19 +1,19 @@ -use std::cell::RefCell; +use crate::jsonrpc::{self}; +use lsp_server::{Message, RequestId}; use lsp_types::notification::*; use lsp_types::request::*; use lsp_types::*; -use crate::jsonrpc::{self,}; -use std::fmt::Display; -use std::rc::Weak; -use lsp_server::{Message, RequestId}; use serde::Serialize; use serde_json::Value; +use std::cell::RefCell; +use std::fmt::Display; +use std::rc::Weak; use tracing::error; use crate::server::LspServer; #[derive(Clone)] - pub(crate) struct ClientInner { +pub(crate) struct ClientInner { server: Option>, id: RefCell, } @@ -60,10 +60,7 @@ impl Client { /// immediately return `Err` with JSON-RPC error code `-32002` ([read more]). /// /// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize - pub fn register_capability( - &self, - registrations: Vec, - ) -> jsonrpc::Result<()> { + pub fn register_capability(&self, registrations: Vec) -> jsonrpc::Result<()> { self.send_request::(RegistrationParams { registrations }) } @@ -311,12 +308,7 @@ impl Client { /// # Initialization /// /// This notification will only be sent if the server is initialized. - pub fn publish_diagnostics( - &self, - uri: Url, - diags: Vec, - version: Option, - ) { + pub fn publish_diagnostics(&self, uri: Url, diags: Vec, version: Option) { self.send_notification::(PublishDiagnosticsParams::new( uri, diags, version, )); @@ -345,10 +337,7 @@ impl Client { /// # Compatibility /// /// This request was introduced in specification version 3.6.0. - pub fn configuration( - &self, - items: Vec, - ) -> jsonrpc::Result> { + pub fn configuration(&self, items: Vec) -> jsonrpc::Result> { self.send_request::(ConfigurationParams { items }) } @@ -388,10 +377,7 @@ impl Client { /// immediately return `Err` with JSON-RPC error code `-32002` ([read more]). /// /// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize - pub fn apply_edit( - &self, - edit: WorkspaceEdit, - ) -> jsonrpc::Result { + pub fn apply_edit(&self, edit: WorkspaceEdit) -> jsonrpc::Result { self.send_request::(ApplyWorkspaceEditParams { edit, label: None }) } @@ -401,31 +387,37 @@ impl Client { /// /// This notification will only be sent if the server is initialized. pub fn send_notification(&self, params: N::Params) - where - N: lsp_types::notification::Notification, + where + N: lsp_types::notification::Notification, { let server_opt = self.inner.server.clone().unwrap().upgrade(); if server_opt.is_none() { eprintln!("Cannot send request, server is not initialized"); return; } - server_opt.unwrap().send(Message::Notification( - lsp_server::Notification::new(N::METHOD.to_string(), params), - )); + server_opt + .unwrap() + .send(Message::Notification(lsp_server::Notification::new( + N::METHOD.to_string(), + params, + ))); } fn send_notification_unchecked(&self, params: N::Params) - where - N: lsp_types::notification::Notification, + where + N: lsp_types::notification::Notification, { let server_opt = self.inner.server.clone().unwrap().upgrade(); if server_opt.is_none() { eprintln!("Cannot send request, server is not initialized"); return; } - server_opt.unwrap().send(Message::Notification( - lsp_server::Notification::new(N::METHOD.to_string(), params), - )); + server_opt + .unwrap() + .send(Message::Notification(lsp_server::Notification::new( + N::METHOD.to_string(), + params, + ))); } /// Sends a custom request to the client. @@ -437,32 +429,41 @@ impl Client { /// /// [read more]: https://microsoft.github.io/language-server-protocol/specification#initialize pub fn send_request(&self, params: R::Params) -> jsonrpc::Result - where - R: lsp_types::request::Request, + where + R: lsp_types::request::Request, { let server_opt = self.inner.server.clone().unwrap().upgrade(); if server_opt.is_none() { eprintln!("Cannot send request, server is not initialized"); return Err(jsonrpc::not_initialized_error()); } - server_opt.as_ref().unwrap().send(Message::Request( - lsp_server::Request::new(RequestId::from(self.next_request_id().to_string()), R::METHOD.to_string(), params), - )); + server_opt + .as_ref() + .unwrap() + .send(Message::Request(lsp_server::Request::new( + RequestId::from(self.next_request_id().to_string()), + R::METHOD.to_string(), + params, + ))); Err(jsonrpc::not_initialized_error()) } fn send_request_unchecked(&self, params: R::Params) -> jsonrpc::Result - where - R: lsp_types::request::Request, + where + R: lsp_types::request::Request, { let server_opt = self.inner.server.clone().unwrap().upgrade(); if server_opt.is_none() { eprintln!("Cannot send request, server is not initialized"); return Err(jsonrpc::not_initialized_error()); } - server_opt.unwrap().send(Message::Request( - lsp_server::Request::new(RequestId::from(self.next_request_id().to_string()), R::METHOD.to_string(), params), - )); + server_opt + .unwrap() + .send(Message::Request(lsp_server::Request::new( + RequestId::from(self.next_request_id().to_string()), + R::METHOD.to_string(), + params, + ))); Err(jsonrpc::not_initialized_error()) } } @@ -477,5 +478,4 @@ impl Client { } id } - -} \ No newline at end of file +} diff --git a/libs/lsp-server-wrapper/src/jsonrpc.rs b/libs/lsp-server-wrapper/src/jsonrpc.rs index a00465f3..664d6868 100644 --- a/libs/lsp-server-wrapper/src/jsonrpc.rs +++ b/libs/lsp-server-wrapper/src/jsonrpc.rs @@ -1,4 +1,4 @@ mod error; pub(crate) use self::error::not_initialized_error; -pub use self::error::{Error, ErrorCode, Result}; \ No newline at end of file +pub use self::error::{Error, ErrorCode, Result}; diff --git a/libs/lsp-server-wrapper/src/jsonrpc/error.rs b/libs/lsp-server-wrapper/src/jsonrpc/error.rs index 80e6eb25..4ce7358e 100644 --- a/libs/lsp-server-wrapper/src/jsonrpc/error.rs +++ b/libs/lsp-server-wrapper/src/jsonrpc/error.rs @@ -139,8 +139,8 @@ impl Error { /// Creates a new "invalid params" error (`-32602`). pub fn invalid_params(message: M) -> Self - where - M: Into>, + where + M: Into>, { Error { code: ErrorCode::InvalidParams, @@ -214,4 +214,4 @@ mod tests { let deserialized: ErrorCode = serde_json::from_str("-12345").unwrap(); assert_eq!(deserialized, ErrorCode::ServerError(-12345)); } -} \ No newline at end of file +} diff --git a/libs/lsp-server-wrapper/src/lib.rs b/libs/lsp-server-wrapper/src/lib.rs index 6d7f3682..493d6b5d 100644 --- a/libs/lsp-server-wrapper/src/lib.rs +++ b/libs/lsp-server-wrapper/src/lib.rs @@ -1,17 +1,17 @@ -mod server; mod client; mod jsonrpc; +mod server; mod service; +pub use crate::jsonrpc::{Error, Result}; +pub use client::Client; pub use lsp_types; -use lsp_types::*; use lsp_types::request::{ GotoDeclarationParams, GotoDeclarationResponse, GotoImplementationParams, GotoImplementationResponse, GotoTypeDefinitionParams, GotoTypeDefinitionResponse, }; -pub use crate::jsonrpc::{Error, Result}; +use lsp_types::*; use serde_json::Value; -pub use client::Client; pub use server::LspStdioServer; pub use service::LspService; @@ -497,10 +497,7 @@ pub trait LanguageServer { /// /// This request was introduced in specification version 3.15.0. - fn selection_range( - &self, - params: SelectionRangeParams, - ) -> Result>> { + fn selection_range(&self, params: SelectionRangeParams) -> Result>> { let _ = params; eprintln!("Got a textDocument/selectionRange request, but it is not implemented"); Err(Error::method_not_found()) @@ -570,7 +567,9 @@ pub trait LanguageServer { params: SemanticTokensDeltaParams, ) -> Result> { let _ = params; - eprintln!("Got a textDocument/semanticTokens/full/delta request, but it is not implemented"); + eprintln!( + "Got a textDocument/semanticTokens/full/delta request, but it is not implemented" + ); Err(Error::method_not_found()) } @@ -1038,10 +1037,7 @@ pub trait LanguageServer { /// Servers can only use this new model if clients advertise support for it via the /// `workspace.symbol.resolve_support` capability. - fn symbol( - &self, - params: WorkspaceSymbolParams, - ) -> Result>> { + fn symbol(&self, params: WorkspaceSymbolParams) -> Result>> { let _ = params; eprintln!("Got a workspace/symbol request, but it is not implemented"); Err(Error::method_not_found()) @@ -1090,7 +1086,9 @@ pub trait LanguageServer { fn did_change_workspace_folders(&self, params: DidChangeWorkspaceFoldersParams) { let _ = params; - eprintln!("Got a workspace/didChangeWorkspaceFolders notification, but it is not implemented"); + eprintln!( + "Got a workspace/didChangeWorkspaceFolders notification, but it is not implemented" + ); } /// The [`workspace/willCreateFiles`] request is sent from the client to the server before @@ -1214,4 +1212,4 @@ pub trait LanguageServer { // TODO: Add `work_done_progress_cancel()` here (since 3.15.0) when supported by `tower-lsp`. // https://github.com/ebkalderon/tower-lsp/issues/176 -} \ No newline at end of file +} diff --git a/libs/lsp-server-wrapper/src/server.rs b/libs/lsp-server-wrapper/src/server.rs index 3e7dcdc4..1a7b118b 100644 --- a/libs/lsp-server-wrapper/src/server.rs +++ b/libs/lsp-server-wrapper/src/server.rs @@ -3,9 +3,9 @@ use std::error::Error; use std::rc::{Rc, Weak}; -use lsp_server::{Connection, IoThreads, Message, Response}; -use crate::{Client, LanguageServer}; use crate::service::LspService; +use crate::{Client, LanguageServer}; +use lsp_server::{Connection, IoThreads, Message, Response}; pub(crate) trait LspServer { fn send(&self, msg: Message); @@ -15,7 +15,7 @@ struct InnerLspStdioServer { connection: Connection, io_threads: IoThreads, client: Rc>, - self_ref: Weak + self_ref: Weak, } pub struct LspStdioServer { @@ -31,14 +31,15 @@ impl<'a> LspStdioServer { connection, io_threads, client, - self_ref: me.clone() - } + self_ref: me.clone(), + }, }) } - - - fn run_initialization(&self, service: &LspService) -> Result<(), Box> { + fn run_initialization( + &self, + service: &LspService, + ) -> Result<(), Box> { let (initialize_id, initialize_params) = self.inner.connection.initialize_start()?; let res = service.call_request("initialize", initialize_params)?; let res = match res { @@ -49,29 +50,39 @@ impl<'a> LspStdioServer { let resp = Response::new_ok(initialize_id, res); self.inner.connection.sender.send(resp.into()).unwrap(); match &self.inner.connection.receiver.recv() { - Ok(Message::Notification(n)) => { - service.call_notification(&n.method, n.params.clone()).map_err(|e| { + Ok(Message::Notification(n)) => service + .call_notification(&n.method, n.params.clone()) + .map_err(|e| { eprintln!("Error: {}", e); e - }) - } + }), Ok(msg) => { - return Err(format!(r#"expected initialized notification, got: {msg:?}"#).to_owned().into()); + return Err( + format!(r#"expected initialized notification, got: {msg:?}"#) + .to_owned() + .into(), + ); } Err(e) => { - return Err(format!("expected initialized notification, got error: {e}",).to_owned().into()) + return Err( + format!("expected initialized notification, got error: {e}",) + .to_owned() + .into(), + ) } }?; Ok(()) - } pub fn serve(this: Rc, init: F) -> Result<(), Box> - where - F: FnOnce(Rc>) -> S + 'a, + where + F: FnOnce(Rc>) -> S + 'a, { - this.inner.client.borrow_mut().set_server(this.inner.self_ref.clone()); + this.inner + .client + .borrow_mut() + .set_server(this.inner.self_ref.clone()); let client = this.inner.client.clone(); let service = LspService::new(client, init); this.run_initialization(&service)?; @@ -90,7 +101,7 @@ impl<'a> LspStdioServer { Ok(is_shutdown) => is_shutdown, Err(e) => { eprintln!("Handle shutdown Error: {}", e); - continue + continue; } }; let result = service.call_request(&req.method, req.params); @@ -98,10 +109,14 @@ impl<'a> LspStdioServer { Ok(result) => result, Err(e) => { eprintln!("Call request Error: {}", e); - continue + continue; } }; - let resp = Response { id, result, error: None }; + let resp = Response { + id, + result, + error: None, + }; if is_shutdown { eprintln!("Shutting down"); return Ok(()); @@ -134,10 +149,5 @@ impl LspServer for LspStdioServer { let _ = self.inner.connection.sender.send(msg).map_err(|e| { eprintln!("Error: {}", e); }); - } } - - - - diff --git a/libs/lsp-server-wrapper/src/service.rs b/libs/lsp-server-wrapper/src/service.rs index 4e300403..10bb8b62 100644 --- a/libs/lsp-server-wrapper/src/service.rs +++ b/libs/lsp-server-wrapper/src/service.rs @@ -1,16 +1,16 @@ mod state; +pub(crate) use self::state::{ServerState, State}; +pub use crate::client::Client; +use crate::{jsonrpc, LanguageServer}; +use lsp_types::request::*; +use lsp_types::*; use std::cell::RefCell; use std::error::Error; use std::rc::Rc; use std::sync::Arc; -use lsp_types::*; -use lsp_types::request::*; -pub use crate::client::Client; -use crate::{jsonrpc, LanguageServer}; -pub(crate) use self::state::{ServerState, State}; - pub(super) struct InnerService { +pub(super) struct InnerService { backend: Arc, //pub(super) client: Arc>, } @@ -22,8 +22,8 @@ pub struct LspService { impl LspService { pub fn new(client: Rc>, init: F) -> Self - where - F: FnOnce(Rc>) -> S, + where + F: FnOnce(Rc>) -> S, { let backend = init(client); LspService { @@ -34,284 +34,295 @@ impl LspService { } } - pub fn call_request(&self, method: &str, params: serde_json::Value) -> Result, Box> { + pub fn call_request( + &self, + method: &str, + params: serde_json::Value, + ) -> Result, Box> { let ret = match method { "initialize" => { self.state.set(State::Initializing); let params: InitializeParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.initialize(params)?) - }, + } "shutdown" => { self.state.set(State::ShutDown); serde_json::to_value(self.inner.backend.shutdown()?) - }, + } "textDocument/willSaveWaitUntil" => { let params: WillSaveTextDocumentParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.will_save_wait_until(params)?) - }, + } "textDocument/declaration" => { let params: GotoDeclarationParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.goto_declaration(params)?) - }, + } "textDocument/definition" => { let params: GotoDefinitionParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.goto_definition(params)?) - }, + } "textDocument/typeDefinition" => { let params: GotoTypeDefinitionParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.goto_type_definition(params)?) - }, + } "textDocument/implementation" => { let params: GotoImplementationParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.goto_implementation(params)?) - }, + } "textDocument/references" => { let params: ReferenceParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.references(params)?) - }, + } "textDocument/prepareCallHierarchy" => { let params: CallHierarchyPrepareParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.prepare_call_hierarchy(params)?) - }, + } "textDocument/incomingCalls" => { - let params: CallHierarchyIncomingCallsParams = serde_json::from_value(params).unwrap(); + let params: CallHierarchyIncomingCallsParams = + serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.incoming_calls(params)?) - }, + } "textDocument/outgoingCalls" => { - let params: CallHierarchyOutgoingCallsParams = serde_json::from_value(params).unwrap(); + let params: CallHierarchyOutgoingCallsParams = + serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.outgoing_calls(params)?) - }, + } "textDocument/prepareTypeHierarchy" => { let params: TypeHierarchyPrepareParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.prepare_type_hierarchy(params)?) - }, + } "textDocument/supertypes" => { let params: TypeHierarchySupertypesParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.supertypes(params)?) - }, + } "textDocument/subtypes" => { let params: TypeHierarchySubtypesParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.subtypes(params)?) - }, + } "textDocument/documentHighlight" => { let params: DocumentHighlightParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.document_highlight(params)?) - }, + } "textDocument/documentLink" => { let params: DocumentLinkParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.document_link(params)?) - }, + } "documentLink/resolve" => { let params: DocumentLink = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.document_link_resolve(params)?) - }, + } "textDocument/hover" => { let params: HoverParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.hover(params)?) - }, + } "textDocument/codeLens" => { let params: CodeLensParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.code_lens(params)?) - }, + } "codeLens/resolve" => { let params: CodeLens = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.code_lens_resolve(params)?) - }, + } "textDocument/foldingRange" => { let params: FoldingRangeParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.folding_range(params)?) - }, + } "textDocument/selectionRange" => { let params: SelectionRangeParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.selection_range(params)?) - }, + } "textDocument/documentSymbol" => { let params: DocumentSymbolParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.document_symbol(params)?) - }, + } "textDocument/sementicTokens/full" => { let params: SemanticTokensParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.semantic_tokens_full(params)?) - }, + } "textDocument/sementicTokens/full/delta" => { let params: SemanticTokensDeltaParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.semantic_tokens_full_delta(params)?) - }, + } "textDocument/sementicTokens/range" => { let params: SemanticTokensRangeParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.semantic_tokens_range(params)?) - }, + } "textDocument/inlineValue" => { let params: InlineValueParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.inline_value(params)?) - }, + } "textDocument/inlayHint" => { let params: InlayHintParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.inlay_hint(params)?) - }, + } "inlayHint/resolve" => { let params: InlayHint = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.inlay_hint_resolve(params)?) - }, + } "textDocument/moniker" => { let params: MonikerParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.moniker(params)?) - }, + } "textDocument/completion" => { let params: CompletionParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.completion(params)?) - }, + } "completionItem/resolve" => { let params: CompletionItem = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.completion_resolve(params)?) - }, + } "textDocument/diagnostic" => { let params: DocumentDiagnosticParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.diagnostic(params)?) - }, + } "workspace/diagnostic" => { let params: WorkspaceDiagnosticParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.workspace_diagnostic(params)?) - }, + } "textDocument/signatureHelp" => { let params: SignatureHelpParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.signature_help(params)?) - }, + } "textDocument/codeAction" => { let params: CodeActionParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.code_action(params)?) - }, + } "codeAction/resolve" => { let params: CodeAction = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.code_action_resolve(params)?) - }, + } "textDocument/documentColor" => { let params: DocumentColorParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.document_color(params)?) - }, + } "textDocument/colorPresentation" => { let params: ColorPresentationParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.color_presentation(params)?) - }, + } "textDocument/formatting" => { let params: DocumentFormattingParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.formatting(params)?) - }, + } "textDocument/rangeFormatting" => { let params: DocumentRangeFormattingParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.range_formatting(params)?) - }, + } "textDocument/onTypeFormatting" => { - let params: DocumentOnTypeFormattingParams = serde_json::from_value(params).unwrap(); + let params: DocumentOnTypeFormattingParams = + serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.on_type_formatting(params)?) - }, + } "textDocument/rename" => { let params: RenameParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.rename(params)?) - }, + } "textDocument/prepareRename" => { let params: TextDocumentPositionParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.prepare_rename(params)?) - }, + } "textDocument/linkedEditingRange" => { let params: LinkedEditingRangeParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.linked_editing_range(params)?) - }, + } "workspace/symbol" => { let params: WorkspaceSymbolParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.symbol(params)?) - }, + } "workspaceSymbol/resolve" => { let params: WorkspaceSymbol = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.symbol_resolve(params)?) - }, + } "workspace/willCreateFiles" => { let params: CreateFilesParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.will_create_files(params)?) - }, + } "workspace/willRenameFiles" => { let params: RenameFilesParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.will_rename_files(params)?) - }, + } "workspace/willDeleteFiles" => { let params: DeleteFilesParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.will_delete_files(params)?) - }, + } "workspace/executeCommand" => { let params: ExecuteCommandParams = serde_json::from_value(params).unwrap(); serde_json::to_value(self.inner.backend.execute_command(params)?) - }, + } "exit" => { self.state.set(State::Exited); return Ok(None); - }, + } _ => { return Err(Box::new(jsonrpc::Error::method_not_found()).into()); } - }.map_err( - |e| { - eprintln!("Error: {}", e); - Box::new(e) - } - )?; + } + .map_err(|e| { + eprintln!("Error: {}", e); + Box::new(e) + })?; Ok(Some(ret)) } - pub fn call_notification(&self, method: &str, params: serde_json::Value) -> Result<(), Box> { + pub fn call_notification( + &self, + method: &str, + params: serde_json::Value, + ) -> Result<(), Box> { match method { "initialized" => { self.state.set(State::Initialized); let params: InitializedParams = serde_json::from_value(params).unwrap(); self.inner.backend.initialized(params); - }, + } "textDocument/didOpen" => { let params: DidOpenTextDocumentParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_open(params); - }, + } "textDocument/didChange" => { let params: DidChangeTextDocumentParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_change(params); - }, + } "textDocument/willSave" => { let params: WillSaveTextDocumentParams = serde_json::from_value(params).unwrap(); self.inner.backend.will_save(params); - }, + } "textDocument/didSave" => { let params: DidSaveTextDocumentParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_save(params); - }, + } "textDocument/didClose" => { let params: DidCloseTextDocumentParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_close(params); - }, + } "workspace/didChangeConfiguration" => { let params: DidChangeConfigurationParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_change_configuration(params); - }, + } "workspace/didChangeWorkspaceFolders" => { - let params: DidChangeWorkspaceFoldersParams = serde_json::from_value(params).unwrap(); + let params: DidChangeWorkspaceFoldersParams = + serde_json::from_value(params).unwrap(); self.inner.backend.did_change_workspace_folders(params); - }, + } "workspace/didCreateFiles" => { let params: CreateFilesParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_create_files(params) - }, + } "workspace/didRenameFiles" => { let params: RenameFilesParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_rename_files(params) - }, + } "workspace/didDeleteFiles" => { let params: DeleteFilesParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_delete_files(params) - }, + } "workspace/didChangeWatchedFiles" => { let params: DidChangeWatchedFilesParams = serde_json::from_value(params).unwrap(); self.inner.backend.did_change_watched_files(params) - }, + } _ => { return Err("Method not found".to_owned().into()); } } Ok(()) } -} \ No newline at end of file +} diff --git a/libs/lsp-server-wrapper/src/service/state.rs b/libs/lsp-server-wrapper/src/service/state.rs index c4ede1f7..e404e8d5 100644 --- a/libs/lsp-server-wrapper/src/service/state.rs +++ b/libs/lsp-server-wrapper/src/service/state.rs @@ -47,4 +47,4 @@ impl Debug for ServerState { fn fmt(&self, f: &mut Formatter) -> fmt::Result { self.get().fmt(f) } -} \ No newline at end of file +} diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/explicit_types.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/explicit_types.rs index 521e4f3c..4831ffdb 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/explicit_types.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/explicit_types.rs @@ -101,16 +101,14 @@ impl RuleType for ExplicitTypes { impl ExplicitTypes { pub(crate) fn create(data: RuleEntry) -> Box { - let mut value; - if !data.data.is_empty(){ - value = match &data.data[0] { + let value = if !data.data.is_empty() { + match &data.data[0] { Value::String(val) => val.as_str(), _ => DEFAULT_RULE, } - } - else { - value = DEFAULT_RULE; - } + } else { + DEFAULT_RULE + }; let rule = ExplicitTypes { rule: value.to_string(), data, diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/reason_string.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/reason_string.rs index bd4bd485..0277f480 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/reason_string.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/best_practises/reason_string.rs @@ -70,10 +70,10 @@ impl RuleType for ReasonString { false } }) { - if let Expr::Lit(ast_extractor::Lit::Str(lit_str)) = expr_string { + if let Expr::Lit(Lit::Str(lit_str)) = expr_string { let actual_string = lit_str.values[0].token().to_string(); - if actual_string.len() > self.max_length as usize { + if actual_string.len() > self.max_length { let location = ( lit_str.values[0].span().start(), lit_str.values[0].span().end(), diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/foundry_func_name.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/foundry_func_name.rs index dab6458b..24905d4a 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/foundry_func_name.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/foundry_func_name.rs @@ -1,4 +1,5 @@ use ast_extractor::Spanned; +use serde_json::Value; use crate::linter::SolidFile; use crate::rules::types::*; @@ -46,22 +47,29 @@ impl RuleType for FoundryFuncName { return vec![]; } let mut res = Vec::new(); - let re = regex::Regex::new(r"^test(Fork)?(Fuzz)?(Fail)?(_)?(Revert(If_|When_){1})?\w{1,}$").unwrap(); + let re = regex::Regex::new(r"^test(Fork)?(Fuzz)?(Fail)?(_)?(Revert(If_|When_){1})?\w{1,}$") + .unwrap(); let contracts = ast_extractor::retriever::retrieve_contract_nodes(&file.data); for contract in contracts { for function in ast_extractor::retriever::retrieve_functions_nodes(&contract) { - let visibility = function.attributes.iter().find(|attr| matches!(attr, ast_extractor::FunctionAttribute::Visibility(_))); + let visibility = function + .attributes + .iter() + .find(|attr| matches!(attr, ast_extractor::FunctionAttribute::Visibility(_))); let visibility = match visibility { Some(ast_extractor::FunctionAttribute::Visibility(visibility)) => visibility, _ => continue, }; - if !matches!(visibility, ast_extractor::Visibility::Public(_)) && !matches!(visibility, ast_extractor::Visibility::External(_)) { + if !matches!(visibility, ast_extractor::Visibility::Public(_)) + && !matches!(visibility, ast_extractor::Visibility::External(_)) + { continue; } if let Some(name) = function.name { - if !re.is_match(&name.as_string()) && !self.excluded.contains(&name.as_string()) { + if !re.is_match(&name.as_string()) && !self.excluded.contains(&name.as_string()) + { let span = name.span(); res.push(self.create_diag((span.start(), span.end()), file)); } @@ -74,7 +82,15 @@ impl RuleType for FoundryFuncName { impl FoundryFuncName { pub(crate) fn create(data: RuleEntry) -> Box { - let rule = FoundryFuncName { excluded: data.data.clone(), data }; + let mut excluded: Vec = Vec::new(); + data.data.iter().for_each(|value| { + if let Value::String(val) = value { + excluded.push(val.to_string()); + } else { + eprintln!("Invalid value for rule foundry-func-name: {:?}", value); + } + }); + let rule = FoundryFuncName { excluded, data }; Box::new(rule) } diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/func_visibility.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/func_visibility.rs index 60691461..25ee9491 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/func_visibility.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/func_visibility.rs @@ -93,8 +93,8 @@ impl FuncVisibility { id: RULE_ID.to_string(), severity: Severity::WARNING, data: vec![serde_json::json!({ - "strict": DEFAULT_IGNORE_CONSTRUCTORS, - }),], + "strict": DEFAULT_IGNORE_CONSTRUCTORS, + })], } } } diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/mod.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/mod.rs index ea7ce3c9..fbe1f0e1 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/mod.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/mod.rs @@ -1,32 +1,32 @@ use crate::rules::naming::const_name_snakecase::ConstNameSnakeCase; use crate::rules::naming::contract_name_pascalcase::ContractNamePascalCase; use crate::rules::naming::event_name_camelcase::EventNameCamelCase; +use crate::rules::naming::foundry_func_name::FoundryFuncName; use crate::rules::naming::func_name_camelcase::FuncNameCamelCase; use crate::rules::naming::func_param_name_camelcase::FuncParamNameCamelcase; use crate::rules::naming::func_visibility::FuncVisibility; use crate::rules::naming::modifier_name_mixedcase::ModifierNameMixedcase; use crate::rules::naming::named_parameters_mapping::NamedParametersMapping; +use crate::rules::naming::private_vars_leading_underscore::PrivateVarsLeadingUnderscore; use crate::rules::naming::use_forbidden_name::UseForbiddenName; use crate::rules::naming::var_name_mixedcase::VarNameMixedCase; -use crate::rules::naming::foundry_func_name::FoundryFuncName; use crate::rules::types::{RuleEntry, RulesMap}; use crate::rules::RuleBuilder; use std::collections::HashMap; -use crate::rules::naming::private_vars_leading_underscore::PrivateVarsLeadingUnderscore; #[macro_use] pub(crate) mod func_param_name_camelcase; pub(crate) mod const_name_snakecase; pub(crate) mod contract_name_pascalcase; pub(crate) mod event_name_camelcase; +pub(crate) mod foundry_func_name; pub(crate) mod func_name_camelcase; pub(crate) mod func_visibility; pub(crate) mod modifier_name_mixedcase; pub(crate) mod named_parameters_mapping; +pub(crate) mod private_vars_leading_underscore; pub(crate) mod use_forbidden_name; pub(crate) mod var_name_mixedcase; -pub(crate) mod foundry_func_name; -pub(crate) mod private_vars_leading_underscore; // List all rules diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/private_vars_leading_underscore.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/private_vars_leading_underscore.rs index 3e775247..5e61a67b 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/private_vars_leading_underscore.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/naming/private_vars_leading_underscore.rs @@ -1,5 +1,5 @@ -use ast_extractor::{Item, Spanned}; use ast_extractor::Visibility::{Internal, Private}; +use ast_extractor::{Item, Spanned}; use crate::linter::SolidFile; use crate::rules::types::*; @@ -61,7 +61,11 @@ impl RuleType for PrivateVarsLeadingUnderscore { if !leading_underscore { let span = name.span(); - res.push(self.create_diag((span.start(), span.end()), file, MESSAGE_PRIVATE.to_string())); + res.push(self.create_diag( + (span.start(), span.end()), + file, + MESSAGE_PRIVATE.to_string(), + )); } } } @@ -73,7 +77,11 @@ impl RuleType for PrivateVarsLeadingUnderscore { if !leading_underscore { let span = name.span(); - res.push(self.create_diag((span.start(), span.end()), file, MESSAGE_PRIVATE.to_string())); + res.push(self.create_diag( + (span.start(), span.end()), + file, + MESSAGE_PRIVATE.to_string(), + )); } } } @@ -81,11 +89,7 @@ impl RuleType for PrivateVarsLeadingUnderscore { } let is_private = match function.attributes.visibility() { - Some(val) => match val { - Private(_) => true, - Internal(_) => true, - _ => false, - }, + Some(val) => matches!(val, Private(_) | Internal(_)), None => true, }; @@ -94,12 +98,19 @@ impl RuleType for PrivateVarsLeadingUnderscore { if !leading_underscore && is_private { let span = name.span(); - res.push(self.create_diag((span.start(), span.end()), file, MESSAGE_PRIVATE.to_string())); + res.push(self.create_diag( + (span.start(), span.end()), + file, + MESSAGE_PRIVATE.to_string(), + )); } - if leading_underscore && !is_private { let span = name.span(); - res.push(self.create_diag((span.start(), span.end()), file, MESSAGE_PUBLIC.to_string())); + res.push(self.create_diag( + (span.start(), span.end()), + file, + MESSAGE_PUBLIC.to_string(), + )); } } } @@ -107,11 +118,7 @@ impl RuleType for PrivateVarsLeadingUnderscore { for node_var in contract.body.iter() { if let Item::Variable(var) = node_var { let is_private = match var.attributes.visibility() { - Some(val) => match val { - Private(_) => true, - Internal(_) => true, - _ => false, - }, + Some(val) => matches!(val, Private(_) | Internal(_)), None => true, }; @@ -119,11 +126,19 @@ impl RuleType for PrivateVarsLeadingUnderscore { if !leading_underscore && is_private { let span = var.name.span(); - res.push(self.create_diag((span.start(), span.end()), file, MESSAGE_PRIVATE.to_string())); + res.push(self.create_diag( + (span.start(), span.end()), + file, + MESSAGE_PRIVATE.to_string(), + )); } if leading_underscore && !is_private { let span = var.name.span(); - res.push(self.create_diag((span.start(), span.end()), file, MESSAGE_PRIVATE.to_string())); + res.push(self.create_diag( + (span.start(), span.end()), + file, + MESSAGE_PUBLIC.to_string(), + )); } } } @@ -157,11 +172,9 @@ impl PrivateVarsLeadingUnderscore { RuleEntry { id: RULE_ID.to_string(), severity: Severity::WARNING, - data: vec![ - serde_json::json!({ - "strict": DEFAULT_STRICT, - }), - ], + data: vec![serde_json::json!({ + "strict": DEFAULT_STRICT, + })], } } } diff --git a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/order/ordering.rs b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/order/ordering.rs index c4a67c95..4517e381 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/src/rules/order/ordering.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/src/rules/order/ordering.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use ast_extractor::{Spanned, Visit, visit, FunctionKind, Visibility}; +use ast_extractor::{visit, FunctionKind, Spanned, Visibility, Visit}; use crate::linter::SolidFile; use crate::rules::types::*; @@ -27,11 +27,7 @@ impl OrderingVisitor { (FileItemType::Import, vec![None, Some(FileItemType::Pragma)]), ( FileItemType::Enum, - vec![ - None, - Some(FileItemType::Pragma), - Some(FileItemType::Import), - ], + vec![None, Some(FileItemType::Pragma), Some(FileItemType::Import)], ), ( FileItemType::Struct, @@ -75,9 +71,10 @@ impl OrderingVisitor { Some(FileItemType::ContractLibrary), ], ), - ].iter() - .cloned() - .collect(); + ] + .iter() + .cloned() + .collect(); let authorized_contract_items: HashMap>> = [ (ContractItemType::Udt, vec![None]), @@ -87,7 +84,11 @@ impl OrderingVisitor { ), ( ContractItemType::Enum, - vec![None, Some(ContractItemType::Udt), Some(ContractItemType::Struct)], + vec![ + None, + Some(ContractItemType::Udt), + Some(ContractItemType::Struct), + ], ), ( ContractItemType::Property, @@ -224,9 +225,10 @@ impl OrderingVisitor { Some(ContractItemType::InternalFunction), ], ), - ].iter() - .cloned() - .collect(); + ] + .iter() + .cloned() + .collect(); OrderingVisitor { file, data, @@ -268,7 +270,7 @@ impl OrderingVisitor { fn is_authorized_file_item(&self, item: FileItemType) -> bool { if let Some(authorized_items) = self.authorized_file_items.get(&item) { - let res = authorized_items.contains(&self.file_current_item); + let res = authorized_items.contains(&self.file_current_item); return res; } true @@ -320,9 +322,12 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } fn visit_item_contract(&mut self, contract_def: &'ast ast_extractor::ItemContract) { - if contract_def.is_interface() && !self.is_authorized_file_item(FileItemType::ContractInterface) || - contract_def.is_library() && !self.is_authorized_file_item(FileItemType::ContractLibrary) || - !self.is_authorized_file_item(FileItemType::Contract) { + if contract_def.is_interface() + && !self.is_authorized_file_item(FileItemType::ContractInterface) + || contract_def.is_library() + && !self.is_authorized_file_item(FileItemType::ContractLibrary) + || !self.is_authorized_file_item(FileItemType::Contract) + { let location = (contract_def.span().start(), contract_def.span().end()); self.reports.push(self.create_diag(&self.file, location)); } else { @@ -334,7 +339,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { self.inside_contract = false; } - fn visit_item_udt(&mut self,udt: &'ast ast_extractor::ItemUdt) { + fn visit_item_udt(&mut self, udt: &'ast ast_extractor::ItemUdt) { if !self.is_authorized_contract_item(ContractItemType::Udt) { let location = (udt.span().start(), udt.span().end()); self.reports.push(self.create_diag(&self.file, location)); @@ -343,7 +348,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } } - fn visit_variable_definition(&mut self,var: &'ast ast_extractor::VariableDefinition) { + fn visit_variable_definition(&mut self, var: &'ast ast_extractor::VariableDefinition) { if !self.is_authorized_contract_item(ContractItemType::Property) { let location = (var.span().start(), var.span().end()); self.reports.push(self.create_diag(&self.file, location)); @@ -352,7 +357,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } } - fn visit_item_event(&mut self,event: &'ast ast_extractor::ItemEvent) { + fn visit_item_event(&mut self, event: &'ast ast_extractor::ItemEvent) { if !self.is_authorized_contract_item(ContractItemType::Event) { let location = (event.span().start(), event.span().end()); self.reports.push(self.create_diag(&self.file, location)); @@ -361,8 +366,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } } - fn visit_item_function(&mut self,function: &'ast ast_extractor::ItemFunction) { - + fn visit_item_function(&mut self, function: &'ast ast_extractor::ItemFunction) { match function.kind { FunctionKind::Modifier(_) => { if !self.is_authorized_contract_item(ContractItemType::Modifier) { @@ -371,7 +375,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::Modifier); } - }, + } FunctionKind::Constructor(_) => { if !self.is_authorized_contract_item(ContractItemType::Constructor) { let location = (function.span().start(), function.span().end()); @@ -379,7 +383,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::Constructor); } - }, + } FunctionKind::Receive(_) => { if !self.is_authorized_contract_item(ContractItemType::Receive) { let location = (function.span().start(), function.span().end()); @@ -387,17 +391,20 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::Receive); } - }, + } FunctionKind::Fallback(_) => { if !self.is_authorized_contract_item(ContractItemType::FallBack) { let location = (function.span().start(), function.span().end()); self.reports.push(self.create_diag(&self.file, location)); } else { self.contract_current_item = Some(ContractItemType::FallBack); - } - }, + } + } FunctionKind::Function(_) => { - let visibility = function.attributes.iter().find(|attr| matches!(attr, ast_extractor::FunctionAttribute::Visibility(_))); + let visibility = function + .attributes + .iter() + .find(|attr| matches!(attr, ast_extractor::FunctionAttribute::Visibility(_))); let visibility = match visibility { Some(ast_extractor::FunctionAttribute::Visibility(visibility)) => visibility, _ => return, @@ -411,7 +418,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::ExternalFunction); } - }, + } Visibility::Public(_) => { if !self.is_authorized_contract_item(ContractItemType::PublicFunction) { let location = (function.span().start(), function.span().end()); @@ -419,7 +426,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::PublicFunction); } - }, + } Visibility::Internal(_) => { if !self.is_authorized_contract_item(ContractItemType::InternalFunction) { let location = (function.span().start(), function.span().end()); @@ -427,7 +434,7 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::InternalFunction); } - }, + } Visibility::Private(_) => { if !self.is_authorized_contract_item(ContractItemType::PrivateFunction) { let location = (function.span().start(), function.span().end()); @@ -435,14 +442,11 @@ impl<'ast> Visit<'ast> for OrderingVisitor { } else { self.contract_current_item = Some(ContractItemType::PrivateFunction); } - }, + } } - } } } - - } #[derive(Debug, Clone)] @@ -450,7 +454,6 @@ pub struct Ordering { data: RuleEntry, } - impl RuleType for Ordering { fn diagnose(&self, file: &SolidFile, _files: &[SolidFile]) -> Vec { let mut visitor = OrderingVisitor::new(file.clone(), self.data.clone()); @@ -501,4 +504,3 @@ enum ContractItemType { InternalFunction, PrivateFunction, } - diff --git a/toolchains/solidity/linter/core/solidhunter-lib/tests/linter.rs b/toolchains/solidity/linter/core/solidhunter-lib/tests/linter.rs index 5ee98f90..9eef7543 100644 --- a/toolchains/solidity/linter/core/solidhunter-lib/tests/linter.rs +++ b/toolchains/solidity/linter/core/solidhunter-lib/tests/linter.rs @@ -168,5 +168,5 @@ test_directories! { NotRelyOnTime, NamedParametersMapping, Ordering, - FoundryFunctionName + PrivateVarsLeadingUnderscore }