@@ -17,7 +17,7 @@ pub struct AstUtils {}
1717
1818impl AstUtils {
1919
20- pub fn get_symbols ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , file_info : & Rc < RefCell < FileInfo > > , offset : u32 ) -> ( AnalyzeAstResult , Option < TextRange > , Option < ExprCall > ) {
20+ pub fn get_expr ( file_info : & Rc < RefCell < FileInfo > > , offset : u32 ) -> ( Option < ExprOrIdent > , Option < ExprCall > ) {
2121 let mut expr: Option < ExprOrIdent > = None ;
2222 let mut call_expr: Option < ExprCall > = None ;
2323 let file_info_ast = file_info. borrow ( ) . file_info_ast . clone ( ) ;
@@ -28,10 +28,13 @@ impl AstUtils {
2828 break ;
2929 }
3030 }
31- let Some ( expr) = expr else {
31+ if expr. is_none ( ) {
3232 warn ! ( "expr not found" ) ;
33- return ( AnalyzeAstResult :: default ( ) , None , None ) ;
34- } ;
33+ }
34+ ( expr, call_expr)
35+ }
36+
37+ pub fn get_symbols ( session : & mut SessionInfo , file_symbol : & Rc < RefCell < Symbol > > , offset : u32 , expr : & ExprOrIdent ) -> ( AnalyzeAstResult , Option < TextRange > ) {
3538 let parent_symbol = Symbol :: get_scope_symbol ( file_symbol. clone ( ) , offset, matches ! ( expr, ExprOrIdent :: Parameter ( _) ) ) ;
3639 AstUtils :: build_scope ( session, & parent_symbol) ;
3740 let from_module;
@@ -45,7 +48,7 @@ impl AstUtils {
4548 ( S ! ( "range" ) , ContextValue :: RANGE ( expr. range ( ) ) )
4649 ] ) ) ;
4750 let analyse_ast_result: AnalyzeAstResult = Evaluation :: analyze_ast ( session, & expr, parent_symbol. clone ( ) , & expr. range ( ) . end ( ) , & mut context, false , & mut vec ! [ ] ) ;
48- ( analyse_ast_result, Some ( expr. range ( ) ) , call_expr )
51+ ( analyse_ast_result, Some ( expr. range ( ) ) )
4952
5053 }
5154
@@ -80,7 +83,7 @@ impl AstUtils {
8083
8184pub struct ExprFinderVisitor < ' a > {
8285 offset : TextSize ,
83- expr : Option < ExprOrIdent < ' a > > ,
86+ expr : Option < ExprOrIdent > ,
8487 last_call_expr : Option < & ' a ExprCall > ,
8588}
8689
@@ -91,7 +94,7 @@ impl<'a> ExprFinderVisitor<'a> {
9194 expr: the expr being searched for
9295 last_call_expr: The last call expr preceding the expr we are searching for
9396 */
94- pub fn find_expr_at ( stmt : & ' a Stmt , offset : u32 ) -> ( Option < ExprOrIdent < ' a > > , Option < ExprCall > ) {
97+ pub fn find_expr_at ( stmt : & ' a Stmt , offset : u32 ) -> ( Option < ExprOrIdent > , Option < ExprCall > ) {
9598 let mut visitor = Self {
9699 offset : TextSize :: new ( offset) ,
97100 expr : None ,
@@ -114,7 +117,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
114117 }
115118 walk_expr ( self , expr) ;
116119 if self . expr . is_none ( ) {
117- self . expr = Some ( ExprOrIdent :: Expr ( expr) ) ;
120+ self . expr = Some ( ExprOrIdent :: Expr ( expr. clone ( ) ) ) ;
118121 }
119122 } else {
120123 walk_expr ( self , expr) ;
@@ -125,10 +128,10 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
125128 walk_alias ( self , alias) ;
126129 if self . expr . is_none ( ) {
127130 if alias. name . range ( ) . contains ( self . offset ) {
128- self . expr = Some ( ExprOrIdent :: Ident ( & alias. name ) ) ;
131+ self . expr = Some ( ExprOrIdent :: Ident ( alias. name . clone ( ) ) ) ;
129132 } else if let Some ( ref asname) = alias. asname {
130133 if asname. range ( ) . contains ( self . offset ) {
131- self . expr = Some ( ExprOrIdent :: Ident ( asname) )
134+ self . expr = Some ( ExprOrIdent :: Ident ( asname. clone ( ) ) )
132135 }
133136 }
134137 }
@@ -140,7 +143,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
140143 let ExceptHandler :: ExceptHandler ( ref handler) = * except_handler;
141144 if let Some ( ref ident) = handler. name {
142145 if ident. clone ( ) . range ( ) . contains ( self . offset ) {
143- self . expr = Some ( ExprOrIdent :: Ident ( ident) ) ;
146+ self . expr = Some ( ExprOrIdent :: Ident ( ident. clone ( ) ) ) ;
144147 }
145148 }
146149 } else {
@@ -151,7 +154,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
151154 fn visit_parameter ( & mut self , parameter : & ' a Parameter ) {
152155 walk_parameter ( self , parameter) ;
153156 if self . expr . is_none ( ) && parameter. name . range ( ) . contains ( self . offset ) {
154- self . expr = Some ( ExprOrIdent :: Parameter ( parameter) ) ;
157+ self . expr = Some ( ExprOrIdent :: Parameter ( parameter. clone ( ) ) ) ;
155158 }
156159 }
157160
@@ -161,7 +164,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
161164 if self . expr . is_none ( ) {
162165 if let Some ( ref ident) = keyword. arg {
163166 if ident. range ( ) . contains ( self . offset ) {
164- self . expr = Some ( ExprOrIdent :: Ident ( ident) ) ;
167+ self . expr = Some ( ExprOrIdent :: Ident ( ident. clone ( ) ) ) ;
165168 }
166169 }
167170 } else {
@@ -173,7 +176,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
173176 walk_pattern_keyword ( self , pattern_keyword) ;
174177
175178 if self . expr . is_none ( ) && pattern_keyword. clone ( ) . attr . range ( ) . contains ( self . offset ) {
176- self . expr = Some ( ExprOrIdent :: Ident ( & pattern_keyword. attr ) ) ;
179+ self . expr = Some ( ExprOrIdent :: Ident ( pattern_keyword. attr . clone ( ) ) ) ;
177180 } else {
178181 walk_pattern_keyword ( self , pattern_keyword) ;
179182 }
@@ -190,7 +193,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
190193 } ;
191194
192195 if ident. is_some ( ) && ident. unwrap ( ) . range ( ) . contains ( self . offset ) {
193- self . expr = Some ( ExprOrIdent :: Ident ( ident. unwrap ( ) ) ) ;
196+ self . expr = Some ( ExprOrIdent :: Ident ( ident. unwrap ( ) . clone ( ) ) ) ;
194197 }
195198
196199 }
@@ -212,7 +215,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
212215
213216 if let Some ( ident) = ident {
214217 if ident. range ( ) . contains ( self . offset ) {
215- self . expr = Some ( ExprOrIdent :: Ident ( ident) ) ;
218+ self . expr = Some ( ExprOrIdent :: Ident ( ident. clone ( ) ) ) ;
216219 }
217220 }
218221 }
@@ -233,7 +236,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
233236
234237 for ident in idents {
235238 if ident. range ( ) . contains ( self . offset ) {
236- self . expr = Some ( ExprOrIdent :: Ident ( ident) ) ;
239+ self . expr = Some ( ExprOrIdent :: Ident ( ident. clone ( ) ) ) ;
237240 break ;
238241 }
239242 }
0 commit comments