@@ -198,7 +198,19 @@ pub type Context = HashMap<String, ContextValue>;
198198 * diagnostics: a vec the hook can fill to add diagnostics
199199 * file_symbol: if provided, can be used to add dependencies
200200 */
201- type GetSymbolHook = fn ( session : & mut SessionInfo , eval : & EvaluationSymbol , context : & mut Option < Context > , diagnostics : & mut Vec < Diagnostic > , scope : Option < Rc < RefCell < Symbol > > > ) -> Option < EvaluationSymbolPtr > ;
201+ type GetSymbolHookCallable = fn ( session : & mut SessionInfo , eval : & EvaluationSymbol , context : & mut Option < Context > , diagnostics : & mut Vec < Diagnostic > , scope : Option < Rc < RefCell < Symbol > > > ) -> Option < EvaluationSymbolPtr > ;
202+
203+ #[ derive( Debug , Clone ) ]
204+ pub struct GetSymbolHook {
205+ pub callable : GetSymbolHookCallable ,
206+ pub name : String
207+ }
208+
209+ impl PartialEq for GetSymbolHook {
210+ fn eq ( & self , other : & Self ) -> bool {
211+ self . name == other. name
212+ }
213+ }
202214
203215
204216#[ derive( Debug , Clone ) ]
@@ -1194,7 +1206,7 @@ impl Evaluation {
11941206 let get_item = get_item. borrow ( ) ;
11951207 if get_item. evaluations ( ) . is_some ( ) && get_item. evaluations ( ) . unwrap ( ) . len ( ) == 1 {
11961208 let get_item_eval = & get_item. evaluations ( ) . unwrap ( ) [ 0 ] ;
1197- if let Some ( hook) = get_item_eval. symbol . get_symbol_hook {
1209+ if let Some ( hook) = get_item_eval. symbol . get_symbol_hook . as_ref ( ) {
11981210 let parent_file_or_func = parent. clone ( ) . borrow ( ) . parent_file_or_function ( ) . as_ref ( ) . unwrap ( ) . upgrade ( ) . unwrap ( ) ;
11991211 let is_in_validation = match parent_file_or_func. borrow ( ) . typ ( ) . clone ( ) {
12001212 SymType :: FILE | SymType :: PACKAGE ( _) | SymType :: FUNCTION => {
@@ -1206,7 +1218,7 @@ impl Evaluation {
12061218 let old_range = context. as_mut ( ) . unwrap ( ) . remove ( & S ! ( "range" ) ) ;
12071219 context. as_mut ( ) . unwrap ( ) . insert ( S ! ( "range" ) , ContextValue :: RANGE ( sub. slice . range ( ) ) ) ;
12081220 context. as_mut ( ) . unwrap ( ) . insert ( S ! ( "is_in_validation" ) , ContextValue :: BOOLEAN ( is_in_validation) ) ;
1209- let hook_result = hook ( session, & get_item_eval. symbol , context, & mut diagnostics, Some ( parent. clone ( ) ) ) ;
1221+ let hook_result = ( hook. callable ) ( session, & get_item_eval. symbol , context, & mut diagnostics, Some ( parent. clone ( ) ) ) ;
12101222 if let Some ( hook_result) = hook_result {
12111223 match hook_result {
12121224 EvaluationSymbolPtr :: WEAK ( ref weak) => {
@@ -1347,8 +1359,7 @@ impl Evaluation {
13471359 } ,
13481360 ArgumentType :: KWARG => {
13491361 kwarg_index = index as i32 ;
1350- } ,
1351- _ => { }
1362+ }
13521363 }
13531364 }
13541365 if !function. is_static {
@@ -1456,7 +1467,7 @@ impl Evaluation {
14561467 diagnostics
14571468 }
14581469
1459- fn process_argument_diagnostics ( session : & SessionInfo , expr_call : & ExprCall , diagnostics : Vec < Vec < Diagnostic > > , eval_count : usize ) -> Vec < Diagnostic > {
1470+ fn process_argument_diagnostics ( session : & SessionInfo , expr_call : & ExprCall , diagnostics : Vec < Vec < Diagnostic > > , _eval_count : usize ) -> Vec < Diagnostic > {
14601471 let mut filtered_diagnostics = vec ! [ ] ;
14611472 //iter through diagnostics and check that each evaluation has the same amount of diagnostics with code OLS01007 or OLS01008 or OLS01010
14621473 let all_same_issues = diagnostics. iter ( ) . fold_while ( None , |acc, diags| {
@@ -1789,8 +1800,8 @@ impl EvaluationSymbol {
17891800 /* Execute Hook, then return the effective EvaluationSymbolPtr */
17901801 pub fn get_symbol ( & self , session : & mut SessionInfo , context : & mut Option < Context > , diagnostics : & mut Vec < Diagnostic > , file_symbol : Option < Rc < RefCell < Symbol > > > ) -> EvaluationSymbolPtr {
17911802 let mut custom_eval = None ;
1792- if let Some ( hook) = self . get_symbol_hook {
1793- custom_eval = hook ( session, self , context, diagnostics, file_symbol) ;
1803+ if let Some ( hook) = self . get_symbol_hook . as_ref ( ) {
1804+ custom_eval = ( hook. callable ) ( session, self , context, diagnostics, file_symbol) ;
17941805 }
17951806 custom_eval. as_ref ( ) . unwrap_or ( & self . sym ) . clone ( )
17961807 }
0 commit comments