Skip to content

Commit cf59b8f

Browse files
authored
Pass document path to jedi_names when a file is not placed in a module (#882)
1 parent 1425f75 commit cf59b8f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pyls/plugins/symbols.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Copyright 2017 Palantir Technologies, Inc.
22
import logging
3+
import os
4+
35
from pyls import hookimpl
46
from pyls.lsp import SymbolKind
57

@@ -15,7 +17,13 @@ def pyls_document_symbols(config, document):
1517
symbols_settings = config.plugin_settings('jedi_symbols')
1618
all_scopes = symbols_settings.get('all_scopes', True)
1719
add_import_symbols = symbols_settings.get('include_import_symbols', True)
18-
definitions = document.jedi_names(all_scopes=all_scopes)
20+
21+
use_document_path = False
22+
document_dir = os.path.normpath(os.path.dirname(document.path))
23+
if not os.path.isfile(os.path.join(document_dir, '__init__.py')):
24+
use_document_path = True
25+
26+
definitions = document.jedi_names(use_document_path, all_scopes=all_scopes)
1927
module_name = document.dot_path
2028
symbols = []
2129
exclude = set({})

pyls/workspace.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def word_at_position(self, position):
234234
return m_start[0] + m_end[-1]
235235

236236
@lock
237-
def jedi_names(self, all_scopes=False, definitions=True, references=False):
238-
script = self.jedi_script()
237+
def jedi_names(self, use_document_path, all_scopes=False, definitions=True, references=False):
238+
script = self.jedi_script(use_document_path=use_document_path)
239239
return script.get_names(all_scopes=all_scopes, definitions=definitions,
240240
references=references)
241241

@@ -263,7 +263,7 @@ def jedi_script(self, position=None, use_document_path=False):
263263

264264
# Extend sys_path with document's path if requested
265265
if use_document_path:
266-
sys_path += [os.path.dirname(self.path)]
266+
sys_path += [os.path.normpath(os.path.dirname(self.path))]
267267

268268
kwargs = {
269269
'code': self.source,

0 commit comments

Comments
 (0)