@@ -38,8 +38,9 @@ def pylsp_document_symbols(config, document):
38
38
39
39
# Skip imported symbols comparing module names.
40
40
sym_full_name = d .full_name
41
- document_dot_path = document .dot_path
42
41
if sym_full_name is not None :
42
+ document_dot_path = document .dot_path
43
+
43
44
# We assume a symbol is imported from another module to start
44
45
# with.
45
46
imported_symbol = True
@@ -48,6 +49,8 @@ def pylsp_document_symbols(config, document):
48
49
# we need to discard it to do module comparisons below.
49
50
if '.' in sym_full_name :
50
51
sym_module_name = sym_full_name .rpartition ('.' )[0 ]
52
+ else :
53
+ sym_module_name = sym_full_name
51
54
52
55
# This is necessary to display symbols in init files (the checks
53
56
# below fail without it).
@@ -56,9 +59,9 @@ def pylsp_document_symbols(config, document):
56
59
57
60
# document_dot_path is the module where the symbol is imported,
58
61
# whereas sym_module_name is the one where it was declared.
59
- if sym_module_name . startswith ( document_dot_path ) :
60
- # If sym_module_name starts with the same string as document_dot_path,
61
- # we can safely assume it was declared in the document.
62
+ if document_dot_path in sym_module_name :
63
+ # If document_dot_path is in sym_module_name, we can safely assume
64
+ # that the symbol was declared in the document.
62
65
imported_symbol = False
63
66
elif sym_module_name .split ('.' )[0 ] in document_dot_path .split ('.' ):
64
67
# If the first module in sym_module_name is one of the modules in
@@ -74,10 +77,19 @@ def pylsp_document_symbols(config, document):
74
77
# When there's no __init__.py next to a file or in one of its
75
78
# parents, the checks above fail. However, Jedi has a nice way
76
79
# to tell if the symbol was declared in the same file: if
77
- # full_name starts by __main__.
80
+ # sym_module_name starts by __main__.
78
81
if imported_symbol :
79
82
if not sym_module_name .startswith ('__main__' ):
80
83
continue
84
+ else :
85
+ # We need to skip symbols if their definition doesn't have `full_name` info, they
86
+ # are detected as a definition, but their description (e.g. `class Foo`) doesn't
87
+ # match the code where they're detected by Jedi. This happens for relative imports.
88
+ if _include_def (d ):
89
+ if d .description not in d .get_line_code ():
90
+ continue
91
+ else :
92
+ continue
81
93
82
94
try :
83
95
docismodule = os .path .samefile (document .path , d .module_path )
0 commit comments