-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_clangd.py
55 lines (41 loc) · 1.43 KB
/
test_clangd.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
#
# Run with: python3 test_clangd.py --log --log-pretty "/path/to/clangd --compile-commands-dir ${PWD}/cpp-test/build-1"
#
import ls_interact as ls
from common import JsonRpc
import os
def interact(json_rpc):
paths = [os.getcwd() + '/cpp-test/src/first.cpp']
for p in paths:
json_rpc.notify(ls.DidOpenTextDocument(p))
for p in paths:
json_rpc.wait_for(JsonRpc.JsonRpcPendingMethod(
'textDocument/publishDiagnostics'))
# ctrl-click on bob()
r = json_rpc.request(ls.GotoDefinition(paths[0], 13, 3))
r = json_rpc.wait_for(r)
assert len(r) == 1
assert r[0]['uri'].endswith('/first.h')
# ctrl-click on bar()
r = json_rpc.request(ls.GotoDefinition(paths[0], 18, 3))
r = json_rpc.wait_for(r)
assert len(r) == 1
# This doesn't work currently, since there's no cross-cu index. Instead,
# it goes to the declaration.
# assert r[0]['uri'].endswith('/second.cpp')
assert r[0]['uri'].endswith('/second.h')
# ctrl-click on foo()
r = json_rpc.request(ls.GotoDefinition(paths[0], 19, 3))
r = json_rpc.wait_for(r)
assert len(r) == 1
assert r[0]['uri'].endswith('/first.cpp')
def main():
for build in (1, 2):
ret = os.system('make -C cpp-test/build-{}'.format(build))
if ret != 0:
return ret
ls.run(interact, {
'rootUri': 'file://' + os.getcwd() + '/cpp-test/src',
})
if __name__ == '__main__':
main()