Skip to content

Commit 299e75f

Browse files
committed
Pass use_document_path to jedi_script when getting hovers
1 parent 4b42a24 commit 299e75f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: pylsp/plugins/hover.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@hookimpl
1212
def pylsp_hover(document, position):
1313
code_position = _utils.position_to_jedi_linecolumn(document, position)
14-
definitions = document.jedi_script().infer(**code_position)
14+
definitions = document.jedi_script(use_document_path=True).infer(**code_position)
1515
word = document.word_at_position(position)
1616

1717
# Find first exact matching definition

Diff for: test/plugins/test_hover.py

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright 2017-2020 Palantir Technologies, Inc.
22
# Copyright 2021- Python Language Server Contributors.
33

4+
import os
5+
46
from pylsp import uris
57
from pylsp.plugins.hover import pylsp_hover
68
from pylsp.workspace import Document
@@ -72,3 +74,28 @@ def test_hover(workspace):
7274
} == pylsp_hover(doc, hov_position)
7375

7476
assert {'contents': ''} == pylsp_hover(doc, no_hov_position)
77+
78+
79+
def test_document_path_hover(workspace_other_root_path, tmpdir):
80+
# Create a dummy module out of the workspace's root_path and try to get
81+
# a definition on it in another file placed next to it.
82+
module_content = '''
83+
def foo():
84+
"""A docstring for foo."""
85+
pass
86+
'''
87+
88+
p = tmpdir.join("mymodule.py")
89+
p.write(module_content)
90+
91+
# Content of doc to test definition
92+
doc_content = """from mymodule import foo
93+
foo"""
94+
doc_path = str(tmpdir) + os.path.sep + 'myfile.py'
95+
doc_uri = uris.from_fs_path(doc_path)
96+
doc = Document(doc_uri, workspace_other_root_path, doc_content)
97+
98+
cursor_pos = {'line': 1, 'character': 3}
99+
contents = pylsp_hover(doc, cursor_pos)['contents']
100+
101+
assert 'A docstring for foo.' == contents[1]

0 commit comments

Comments
 (0)