Skip to content

Commit

Permalink
Pass document path to jedi_names when a file is not placed in a module (
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 authored Nov 4, 2020
1 parent 1425f75 commit cf59b8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion pyls/plugins/symbols.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright 2017 Palantir Technologies, Inc.
import logging
import os

from pyls import hookimpl
from pyls.lsp import SymbolKind

Expand All @@ -15,7 +17,13 @@ def pyls_document_symbols(config, document):
symbols_settings = config.plugin_settings('jedi_symbols')
all_scopes = symbols_settings.get('all_scopes', True)
add_import_symbols = symbols_settings.get('include_import_symbols', True)
definitions = document.jedi_names(all_scopes=all_scopes)

use_document_path = False
document_dir = os.path.normpath(os.path.dirname(document.path))
if not os.path.isfile(os.path.join(document_dir, '__init__.py')):
use_document_path = True

definitions = document.jedi_names(use_document_path, all_scopes=all_scopes)
module_name = document.dot_path
symbols = []
exclude = set({})
Expand Down
6 changes: 3 additions & 3 deletions pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def word_at_position(self, position):
return m_start[0] + m_end[-1]

@lock
def jedi_names(self, all_scopes=False, definitions=True, references=False):
script = self.jedi_script()
def jedi_names(self, use_document_path, all_scopes=False, definitions=True, references=False):
script = self.jedi_script(use_document_path=use_document_path)
return script.get_names(all_scopes=all_scopes, definitions=definitions,
references=references)

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

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

kwargs = {
'code': self.source,
Expand Down

0 comments on commit cf59b8f

Please sign in to comment.