@@ -1234,6 +1234,18 @@ impl Symbol {
1234
1234
}
1235
1235
}
1236
1236
1237
+ /// Return all symbols before the given position that are visible in the body of this symbol.
1238
+ pub fn get_all_visible_symbols ( & self , name_prefix : & String , position : u32 ) -> HashMap < OYarn , Vec < Rc < RefCell < Symbol > > > > {
1239
+ match self {
1240
+ Symbol :: Class ( c) => c. get_all_visible_symbols ( name_prefix, position) ,
1241
+ Symbol :: File ( f) => f. get_all_visible_symbols ( name_prefix, position) ,
1242
+ Symbol :: Package ( PackageSymbol :: Module ( m) ) => m. get_all_visible_symbols ( name_prefix, position) ,
1243
+ Symbol :: Package ( PackageSymbol :: PythonPackage ( p) ) => p. get_all_visible_symbols ( name_prefix, position) ,
1244
+ Symbol :: Function ( f) => f. get_all_visible_symbols ( name_prefix, position) ,
1245
+ _ => HashMap :: new ( ) ,
1246
+ }
1247
+ }
1248
+
1237
1249
/**
1238
1250
* Return a symbol that can be called from outside of the body of the symbol
1239
1251
*/
@@ -2100,17 +2112,18 @@ impl Symbol {
2100
2112
/*
2101
2113
Return all the symbols that are available at a given position or in a scope for a given start name
2102
2114
*/
2103
- pub fn get_all_inferred_names ( on_symbol : & Rc < RefCell < Symbol > > , name : & String , position : Option < u32 > ) -> HashMap < OYarn , Vec < Rc < RefCell < Symbol > > > > {
2115
+ pub fn get_all_inferred_names ( on_symbol : & Rc < RefCell < Symbol > > , name : & String , position : u32 ) -> HashMap < OYarn , Vec < Rc < RefCell < Symbol > > > > {
2104
2116
fn helper (
2105
- on_symbol : & Rc < RefCell < Symbol > > , name : & String , position : Option < u32 > , acc : & mut HashMap < OYarn , Vec < Rc < RefCell < Symbol > > > >
2117
+ on_symbol : & Rc < RefCell < Symbol > > , name : & String , position : u32 , acc : & mut HashMap < OYarn , Vec < Rc < RefCell < Symbol > > > >
2106
2118
) {
2107
2119
// Add symbols from files and functions
2108
2120
if matches ! ( on_symbol. borrow( ) . typ( ) , SymType :: FILE | SymType :: FUNCTION ) {
2109
- on_symbol. borrow ( ) . all_symbols ( ) . filter ( |sym|
2110
- sym. borrow ( ) . name ( ) . starts_with ( name) && ( position. is_none ( ) || !sym. borrow ( ) . has_range ( ) || position. unwrap ( ) > sym. borrow ( ) . range ( ) . end ( ) . to_u32 ( ) )
2111
- ) . for_each ( | sym| {
2112
- acc. entry ( sym. borrow ( ) . name ( ) . clone ( ) ) . or_default ( ) . push ( sym. clone ( ) ) ;
2113
- } ) ;
2121
+ let symbols_map = on_symbol. borrow ( ) . get_all_visible_symbols ( name, position) ;
2122
+ for ( sym_name, sym_vec) in symbols_map {
2123
+ acc. entry ( sym_name)
2124
+ . or_default ( )
2125
+ . extend ( sym_vec) ;
2126
+ }
2114
2127
}
2115
2128
// Traverse upwards if we are under a class or a function
2116
2129
if matches ! ( on_symbol. borrow( ) . typ( ) , SymType :: CLASS | SymType :: FUNCTION ) {
0 commit comments