@@ -19,26 +19,29 @@ pub struct AstUtils {}
1919
2020impl AstUtils {
2121
22- pub fn get_expr < ' a > ( file_info_ast : & ' a FileInfoAst , offset : u32 ) -> ( Option < ExprOrIdent < ' a > > , Option < ExprCall > ) {
22+
23+ pub fn get_symbols < ' a > ( session : & mut SessionInfo , file_info_ast : & ' a FileInfoAst , file_symbol : & Rc < RefCell < Symbol > > , offset : u32 ) -> ( AnalyzeAstResult , Option < TextRange > , Option < ExprOrIdent < ' a > > , Option < ExprCall > ) {
2324 let mut expr: Option < ExprOrIdent < ' a > > = None ;
2425 let mut call_expr: Option < ExprCall > = None ;
2526 for stmt in file_info_ast. get_stmts ( ) . unwrap ( ) . iter ( ) {
2627 //we have to handle imports differently as symbols are not visible in file.
27- if let Some ( test_import ) = Self :: get_symbol_in_import ( session, file_symbol, offset, stmt) {
28- return test_import ;
28+ if let Some ( ( result , range ) ) = Self :: get_symbol_in_import ( session, file_symbol, offset, stmt) {
29+ return ( result , range , None , None ) ;
2930 }
3031 ( expr, call_expr) = ExprFinderVisitor :: find_expr_at ( stmt, offset) ;
3132 if expr. is_some ( ) {
3233 break ;
3334 }
3435 }
35- if expr . is_none ( ) {
36+ let Some ( expr ) = expr else {
3637 warn ! ( "expr not found" ) ;
37- }
38- ( expr, call_expr)
38+ return ( AnalyzeAstResult :: default ( ) , None , None , None ) ;
39+ } ;
40+ let ( result, range) = Self :: get_symbol_from_expr ( session, file_symbol, & expr, offset) ;
41+ ( result, range, Some ( expr) , call_expr)
3942 }
4043
41- pub fn get_symbols ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , offset : u32 , expr : & ExprOrIdent ) -> ( AnalyzeAstResult , Option < TextRange > ) {
44+ pub fn get_symbol_from_expr < ' a > ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , expr : & ExprOrIdent < ' a > , offset : u32 ) -> ( AnalyzeAstResult , Option < TextRange > ) {
4245 let parent_symbol = Symbol :: get_scope_symbol ( file_symbol. clone ( ) , offset, matches ! ( expr, ExprOrIdent :: Parameter ( _) ) ) ;
4346 AstUtils :: build_scope ( session, & parent_symbol) ;
4447 let from_module;
@@ -53,7 +56,6 @@ impl AstUtils {
5356 ] ) ) ;
5457 let analyse_ast_result: AnalyzeAstResult = Evaluation :: analyze_ast ( session, & expr, parent_symbol. clone ( ) , & expr. range ( ) . end ( ) , & mut context, false , & mut vec ! [ ] ) ;
5558 ( analyse_ast_result, Some ( expr. range ( ) ) )
56-
5759 }
5860
5961 pub fn flatten_expr ( expr : & Expr ) -> String {
@@ -82,9 +84,9 @@ impl AstUtils {
8284 }
8385 }
8486
85- fn get_symbol_in_import ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , offset : u32 , stmt : & Stmt ) -> Option < ( AnalyzeAstResult , Option < TextRange > , Option < ExprCall > ) > {
87+ fn get_symbol_in_import ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , offset : u32 , stmt : & Stmt ) -> Option < ( AnalyzeAstResult , Option < TextRange > ) > {
8688 match stmt {
87- //for all imports, the idea will be to check if we are on the last name of the import (then it has benn imported already and we can fallback on it),
89+ //for all imports, the idea will be to check if we are on the last name of the import (then it has been imported already and we can fallback on it),
8890 //or then take the full tree to the offset symbol and resolve_import on it as it was in a 'from' clause.
8991 Stmt :: Import ( stmt) => {
9092 for alias in stmt. names . iter ( ) {
@@ -116,7 +118,7 @@ impl AstUtils {
116118 evaluations : vec ! [ Evaluation :: eval_from_symbol( & Rc :: downgrade( & symbol) , None ) ] ,
117119 diagnostics : vec ! [ ] ,
118120 } ;
119- return Some ( ( result, Some ( range) , None ) ) ;
121+ return Some ( ( result, Some ( range) ) ) ;
120122 }
121123 } else {
122124 let res = resolve_import_stmt ( session, file_symbol, None , & [
@@ -134,7 +136,7 @@ impl AstUtils {
134136 ) . collect ( ) ,
135137 diagnostics : vec ! [ ] ,
136138 } ;
137- return Some ( ( result, Some ( range) , None ) ) ;
139+ return Some ( ( result, Some ( range) ) ) ;
138140 }
139141 }
140142 return None ;
@@ -165,7 +167,7 @@ impl AstUtils {
165167 evaluations : vec ! [ Evaluation :: eval_from_symbol( & Rc :: downgrade( & symbol) , None ) ] ,
166168 diagnostics : vec ! [ ] ,
167169 } ;
168- return Some ( ( result, Some ( range) , None ) ) ;
170+ return Some ( ( result, Some ( range) ) ) ;
169171 }
170172 }
171173 } ,
0 commit comments