|
1 | 1 | # Copyright 2017-2020 Palantir Technologies, Inc.
|
2 | 2 | # Copyright 2021- Python Language Server Contributors.
|
3 | 3 |
|
| 4 | +import os |
| 5 | + |
4 | 6 | from pylsp import uris
|
5 | 7 | from pylsp.plugins.hover import pylsp_hover
|
6 | 8 | from pylsp.workspace import Document
|
@@ -72,3 +74,28 @@ def test_hover(workspace):
|
72 | 74 | } == pylsp_hover(doc, hov_position)
|
73 | 75 |
|
74 | 76 | 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