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
104
105
106
107
108
109
110
111
112
113
114
|
local lclient = require 'lclient'
local util = require 'utility'
local ws = require 'workspace'
local files = require 'files'
local furi = require 'file-uri'
local fs = require 'bee.filesystem'
---@async
lclient():start(function (client)
client:registerFakers()
client:initialize()
ws.awaitReady()
client:notify('textDocument/didOpen', {
textDocument = {
uri = furi.encode('1.lua'),
languageId = 'lua',
version = 0,
text = [[
---@class AAA
---@source file:///xxx.lua:50
---@field x number
local mt = {}
---@source file:///yyy.lua:30
function mt:ff() end
---@source file:///lib.c
XX = 1
---@source file:///lib.c:30:20
YY = 1
]]
}
})
client:notify('textDocument/didOpen', {
textDocument = {
uri = furi.encode('main.lua'),
languageId = 'lua',
version = 0,
text = [[
---@type AAA
local a
print(a.x)
print(a.ff)
print(XX)
print(YY)
]]
}
})
local locations = client:awaitRequest('textDocument/definition', {
textDocument = { uri = furi.encode('main.lua') },
position = { line = 3, character = 9 },
})
assert(util.equal(locations, {
{
uri = 'file:///xxx.lua',
range = {
start = { line = 49, character = 0 },
['end'] = { line = 49, character = 0 },
}
}
}))
local locations = client:awaitRequest('textDocument/definition', {
textDocument = { uri = furi.encode('main.lua') },
position = { line = 4, character = 9 },
})
assert(util.equal(locations, {
{
uri = 'file:///yyy.lua',
range = {
start = { line = 29, character = 0 },
['end'] = { line = 29, character = 0 },
}
}
}))
local locations = client:awaitRequest('textDocument/definition', {
textDocument = { uri = furi.encode('main.lua') },
position = { line = 5, character = 7 },
})
assert(util.equal(locations, {
{
uri = 'file:///lib.c',
range = {
start = { line = 0, character = 0 },
['end'] = { line = 0, character = 0 },
}
}
}))
local locations = client:awaitRequest('textDocument/definition', {
textDocument = { uri = furi.encode('main.lua') },
position = { line = 6, character = 7 },
})
assert(util.equal(locations, {
{
uri = 'file:///lib.c',
range = {
start = { line = 29, character = 20 },
['end'] = { line = 29, character = 20 },
}
}
}))
end)
|