|
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.definition import pylsp_definitions
|
6 | 8 | from pylsp.workspace import Document
|
@@ -57,3 +59,36 @@ def test_assignment(config, workspace):
|
57 | 59 |
|
58 | 60 | doc = Document(DOC_URI, workspace, DOC)
|
59 | 61 | assert [{'uri': DOC_URI, 'range': def_range}] == pylsp_definitions(config, doc, cursor_pos)
|
| 62 | + |
| 63 | + |
| 64 | +def test_document_path_definitions(config, workspace_other_root_path, tmpdir): |
| 65 | + # Create a dummy module out of the workspace's root_path and try to get |
| 66 | + # a definition on it in another file placed next to it. |
| 67 | + module_content = ''' |
| 68 | +def foo(): |
| 69 | + pass |
| 70 | +''' |
| 71 | + |
| 72 | + p = tmpdir.join("mymodule.py") |
| 73 | + p.write(module_content) |
| 74 | + |
| 75 | + # Content of doc to test definition |
| 76 | + doc_content = """from mymodule import foo""" |
| 77 | + doc_path = str(tmpdir) + os.path.sep + 'myfile.py' |
| 78 | + doc_uri = uris.from_fs_path(doc_path) |
| 79 | + doc = Document(doc_uri, workspace_other_root_path, doc_content) |
| 80 | + |
| 81 | + # The range where is defined in mymodule.py |
| 82 | + def_range = { |
| 83 | + 'start': {'line': 1, 'character': 4}, |
| 84 | + 'end': {'line': 1, 'character': 7} |
| 85 | + } |
| 86 | + |
| 87 | + # The position where foo is called in myfile.py |
| 88 | + cursor_pos = {'line': 0, 'character': 24} |
| 89 | + |
| 90 | + # The uri for mymodule.py |
| 91 | + module_path = str(p) |
| 92 | + module_uri = uris.from_fs_path(module_path) |
| 93 | + |
| 94 | + assert [{'uri': module_uri, 'range': def_range}] == pylsp_definitions(config, doc, cursor_pos) |
0 commit comments