Skip to content

Commit

Permalink
Pass use_document_path to jedi_script when getting hovers
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jul 28, 2021
1 parent 4b42a24 commit 299e75f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylsp/plugins/hover.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@hookimpl
def pylsp_hover(document, position):
code_position = _utils.position_to_jedi_linecolumn(document, position)
definitions = document.jedi_script().infer(**code_position)
definitions = document.jedi_script(use_document_path=True).infer(**code_position)
word = document.word_at_position(position)

# Find first exact matching definition
Expand Down
27 changes: 27 additions & 0 deletions test/plugins/test_hover.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

import os

from pylsp import uris
from pylsp.plugins.hover import pylsp_hover
from pylsp.workspace import Document
Expand Down Expand Up @@ -72,3 +74,28 @@ def test_hover(workspace):
} == pylsp_hover(doc, hov_position)

assert {'contents': ''} == pylsp_hover(doc, no_hov_position)


def test_document_path_hover(workspace_other_root_path, tmpdir):
# Create a dummy module out of the workspace's root_path and try to get
# a definition on it in another file placed next to it.
module_content = '''
def foo():
"""A docstring for foo."""
pass
'''

p = tmpdir.join("mymodule.py")
p.write(module_content)

# Content of doc to test definition
doc_content = """from mymodule import foo
foo"""
doc_path = str(tmpdir) + os.path.sep + 'myfile.py'
doc_uri = uris.from_fs_path(doc_path)
doc = Document(doc_uri, workspace_other_root_path, doc_content)

cursor_pos = {'line': 1, 'character': 3}
contents = pylsp_hover(doc, cursor_pos)['contents']

assert 'A docstring for foo.' == contents[1]

0 comments on commit 299e75f

Please sign in to comment.