8
8
9
9
@hookimpl
10
10
def pyls_document_symbols (config , document ):
11
- # all_scopes = config.plugin_settings('jedi_symbols').get('all_scopes', True)
11
+ if not config .capabilities .get ("documentSymbol" , {}).get ("hierarchicalDocumentSymbolSupport" , False ):
12
+ return pyls_document_symbols_legacy (config , document )
13
+ # returns DocumentSymbol[]
14
+ hide_imports = config .plugin_settings ('jedi_symbols' ).get ('hide_imports' , False )
12
15
definitions = document .jedi_names (all_scopes = False )
13
16
def transform (d ):
14
- include_d = _include_def (d )
17
+ include_d = _include_def (d , hide_imports )
15
18
if include_d is None :
16
19
return None
17
20
children = [dt for dt in (transform (d1 ) for d1 in d .defined_names ()) if dt ] if include_d else None
@@ -28,17 +31,33 @@ def transform(d):
28
31
}
29
32
return [dt for dt in (transform (d ) for d in definitions ) if dt ]
30
33
31
- def _include_def (definition ):
34
+ def pyls_document_symbols_legacy (config , document ):
35
+ # returns SymbolInformation[]
36
+ all_scopes = config .plugin_settings ('jedi_symbols' ).get ('all_scopes' , True )
37
+ hide_imports = config .plugin_settings ('jedi_symbols' ).get ('hide_imports' , False )
38
+ definitions = document .jedi_names (all_scopes = all_scopes )
39
+ return [{
40
+ 'name' : d .name ,
41
+ 'containerName' : _container (d ),
42
+ 'location' : {
43
+ 'uri' : document .uri ,
44
+ 'range' : _range (d ),
45
+ },
46
+ 'kind' : _kind (d ),
47
+ } for d in definitions if _include_def (d , hide_imports ) is not None ]
48
+
49
+ def _include_def (definition , hide_imports = True ):
32
50
# True: include def and sub-defs
33
51
# False: include def but do not include sub-defs
34
52
# None: Do not include def or sub-defs
35
53
if (# Unused vars should also be skipped
36
54
definition .name != '_' and
37
- not definition ._name .is_import () and
38
55
definition .is_definition () and
39
56
not definition .in_builtin_module () and
40
57
_kind (definition ) is not None
41
58
):
59
+ if definition ._name .is_import ():
60
+ return None if hide_imports else False
42
61
# for `statement`, we do not enumerate its child nodes. It tends to cause Error.
43
62
return definition .type not in ("statement" ,)
44
63
return None
0 commit comments