Skip to content

Commit 4a0a07f

Browse files
committed
bind source for class
1 parent b154dde commit 4a0a07f

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

script/core/jump-source.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ local guide = require 'parser.guide'
33
---@param results table
44
return function (results)
55
for _, result in ipairs(results) do
6-
if result.target.type == 'doc.field.name' then
6+
if result.target.type == 'doc.field.name'
7+
or result.target.type == 'doc.class.name' then
78
local doc = result.target.parent.source
89
if doc then
910
result.uri = doc.source

script/parser/luadoc.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,10 @@ local function bindCommentsAndFields(binded)
17871787
if class then
17881788
class.bindSource = nil
17891789
end
1790+
if source then
1791+
doc.source = source
1792+
source.bindSource = doc
1793+
end
17901794
class = doc
17911795
bindCommentsToDoc(doc, comments)
17921796
comments = {}

script/provider/build-meta.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ local function buildText(root, class)
105105
lines[#lines+1] = ('---@field %s %s'):format(field.name, field.typeName)
106106
end
107107

108+
lines[#lines+1] = ('---@source %s'):format(class.location:gsub('#', ':'))
108109
local name = mergeString(root, class.namespace, class.name)
109110
lines[#lines+1] = ('%s = {}'):format(name)
110111
lines[#lines+1] = ''

test/tclient/tests/jump-source.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ XX = 1
3131
3232
---@source file:///lib.c:30:20
3333
YY = 1
34+
35+
---@source file:///lib.c
36+
---@class BBB
37+
---@source file:///lib.c
38+
BBB = {}
3439
]]
3540
}
3641
})
@@ -48,6 +53,8 @@ print(a.x)
4853
print(a.ff)
4954
print(XX)
5055
print(YY)
56+
---@type BBB
57+
print(BBB)
5158
]]
5259
}
5360
})
@@ -111,4 +118,34 @@ print(YY)
111118
}
112119
}
113120
}))
121+
122+
local locations = client:awaitRequest('textDocument/definition', {
123+
textDocument = { uri = furi.encode('main.lua') },
124+
position = { line = 7, character = 10 },
125+
})
126+
127+
assert(util.equal(locations, {
128+
{
129+
uri = 'file:///lib.c',
130+
range = {
131+
start = { line = 0, character = 0 },
132+
['end'] = { line = 0, character = 0 },
133+
}
134+
}
135+
}))
136+
137+
local locations = client:awaitRequest('textDocument/definition', {
138+
textDocument = { uri = furi.encode('main.lua') },
139+
position = { line = 8, character = 7 },
140+
})
141+
142+
assert(util.equal(locations, {
143+
{
144+
uri = 'file:///lib.c',
145+
range = {
146+
start = { line = 0, character = 0 },
147+
['end'] = { line = 0, character = 0 },
148+
}
149+
}
150+
}))
114151
end)

0 commit comments

Comments
 (0)