forked from microsoft/monitors4codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sync_multilspy_rust.py
67 lines (58 loc) · 2.51 KB
/
test_sync_multilspy_rust.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
"""
This file contains tests for running the Rust Language Server: rust-analyzer
"""
import unittest
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_rust_carbonyl() -> None:
"""
Test the working of multilspy with rust repository - carbonyl
"""
code_language = Language.RUST
params = {
"code_language": code_language,
"repo_url": "https://github.com/fathyb/carbonyl/",
"repo_commit": "ab80a276b1bd1c2c8dcefc8f248415dfc61dc2bf"
}
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/browser/bridge.rs")), 132, 18)
assert isinstance(result, list)
assert len(result) == 1
item = result[0]
assert item["relativePath"] == str(PurePath("src/input/tty.rs"))
assert item["range"] == {
"start": {"line": 43, "character": 11},
"end": {"line": 43, "character": 19},
}
result = lsp.request_references(str(PurePath("src/input/tty.rs")), 43, 15)
assert isinstance(result, list)
assert len(result) == 2
for item in result:
del item["uri"]
del item["absolutePath"]
case = unittest.TestCase()
case.assertCountEqual(
result,
[
{
"relativePath": str(PurePath("src/browser/bridge.rs")),
"range": {
"start": {"line": 132, "character": 13},
"end": {"line": 132, "character": 21},
},
},
{
"relativePath": str(PurePath("src/input/tty.rs")),
"range": {
"start": {"line": 16, "character": 13},
"end": {"line": 16, "character": 21},
},
},
],
)