Skip to content

Pass document path to jedi_names when a file is not placed in a module #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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