forked from microsoft/monitors4codegen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_sync_multilspy_python.py
103 lines (95 loc) · 4.06 KB
/
test_sync_multilspy_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
This file contains tests for running the Python Language Server: jedi-language-server
"""
from monitors4codegen.multilspy import SyncLanguageServer
from monitors4codegen.multilspy.multilspy_config import Language
from tests.test_utils import create_test_context
from pathlib import PurePath
def test_multilspy_python_black() -> None:
"""
Test the working of multilspy with python repository - black
"""
code_language = Language.PYTHON
params = {
"code_language": code_language,
"repo_url": "https://github.com/psf/black/",
"repo_commit": "f3b50e466969f9142393ec32a4b2a383ffbe5f23"
}
with create_test_context(params) as context:
lsp = SyncLanguageServer.create(context.config, context.logger, context.source_directory)
# All the communication with the language server must be performed inside the context manager
# The server process is started when the context manager is entered and is terminated when the context manager is exited.
with lsp.start_server():
result = lsp.request_definition(str(PurePath("src/black/mode.py")), 163, 4)
assert isinstance(result, list)
assert len(result) == 1
item = result[0]
assert item["relativePath"] == str(PurePath("src/black/mode.py"))
assert item["range"] == {
"start": {"line": 163, "character": 4},
"end": {"line": 163, "character": 20},
}
result = lsp.request_references(str(PurePath("src/black/mode.py")), 163, 4)
assert isinstance(result, list)
assert len(result) == 8
for item in result:
del item["uri"]
del item["absolutePath"]
assert result == [
{
"relativePath": str(PurePath("src/black/__init__.py")),
"range": {
"start": {"line": 71, "character": 4},
"end": {"line": 71, "character": 20},
},
},
{
"relativePath": str(PurePath("src/black/__init__.py")),
"range": {
"start": {"line": 1105, "character": 11},
"end": {"line": 1105, "character": 27},
},
},
{
"relativePath": str(PurePath("src/black/__init__.py")),
"range": {
"start": {"line": 1113, "character": 11},
"end": {"line": 1113, "character": 27},
},
},
{
"relativePath": str(PurePath("src/black/mode.py")),
"range": {
"start": {"line": 163, "character": 4},
"end": {"line": 163, "character": 20},
},
},
{
"relativePath": str(PurePath("src/black/parsing.py")),
"range": {
"start": {"line": 7, "character": 68},
"end": {"line": 7, "character": 84},
},
},
{
"relativePath": str(PurePath("src/black/parsing.py")),
"range": {
"start": {"line": 37, "character": 11},
"end": {"line": 37, "character": 27},
},
},
{
"relativePath": str(PurePath("src/black/parsing.py")),
"range": {
"start": {"line": 39, "character": 14},
"end": {"line": 39, "character": 30},
},
},
{
"relativePath": str(PurePath("src/black/parsing.py")),
"range": {
"start": {"line": 44, "character": 11},
"end": {"line": 44, "character": 27},
},
},
]