-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_cquery.py
51 lines (37 loc) · 1.23 KB
/
test_cquery.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
#
# Run with: python3 test_cquery.py --log "/path/to/cquery"
#
import ls_interact as ls
import sys
import json
import os
def interact(json_rpc):
paths = [os.getcwd() + '/cpp-test/src/first.cpp']
for p in paths:
json_rpc.notify(ls.DidOpenTextDocument(p))
print('Press enter when you think indexing is finished...')
sys.stdin.readline()
r = json_rpc.request(ls.GotoDefinition(paths[0], 7, 3))
r = json_rpc.wait_for(r)
assert len(r) == 1
assert r[0]['uri'].endswith('/first.h')
r = json_rpc.request(ls.GotoDefinition(paths[0], 12, 3))
r = json_rpc.wait_for(r)
assert len(r) == 1
assert r[0]['uri'].endswith('/second.cpp')
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.cpp')
def main():
if not os.path.exists('./cpp-test/build/compile_commands.json'):
print('Could not find compile_commands.json, please run make in ./cpp-test/build.')
return
ls.run(interact, {
'initializationOptions': {
'cacheDirectory': '/tmp/cquery-cache'
},
'rootUri': 'file://' + os.getcwd() + '/cpp-test/build',
})
if __name__ == '__main__':
main()