-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_clangd_multi_project.py
65 lines (52 loc) · 1.73 KB
/
test_clangd_multi_project.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
#
# 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
root = os.getcwd() + '/multi-project/'
def interact(json_rpc):
paths = [root + 'source/bar/bar.cpp',
root + 'source/libfoo/foo.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 Multiply() in bar.cpp
r = json_rpc.request(ls.GotoDefinition(paths[0], 6, 21))
r = json_rpc.wait_for(r)
# check that the definition in foo.cpp is found
assert len(r) >= 1
assert r[0]['uri'].endswith('/foo.cpp')
# find references to Multiple() in foo.cpp
r = json_rpc.request(ls.FindReferences(paths[1], 1, 6))
r = json_rpc.wait_for(r)
# check that the call site in bar.cpp is found
found = False
for ref in r:
if ref['uri'].endswith('/bar.cpp'):
found = True
break
assert found
def main():
ret = os.system('cd multi-project && ./setup.sh')
if ret != 0:
return ret
ls.run(interact, cmdline_args='--background-index', initialize_params={
'rootUri': 'file://' + root + 'source',
'initializationOptions': {
'compilationDatabaseMap': [
{
'sourceDir': root + 'source/libfoo',
'dbPath': root + 'build/libfoo'
},
{
'sourceDir': root + 'source/bar',
'dbPath': root + 'build/bar'
}
]
}
})
if __name__ == '__main__':
main()