Skip to content

Commit ac3235f

Browse files
committed
fix hover
1 parent 59b2b8e commit ac3235f

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

script/core/hover/description.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,16 @@ local function getBindEnums(source, docGroup)
268268
return table.concat(chunks, '\n\n')
269269
end
270270

271-
local function tryDocFieldUpComment(source)
271+
local function tryDocFieldComment(source)
272272
if source.type ~= 'doc.field' then
273273
return
274274
end
275-
if not source.bindGroup then
276-
return
275+
if source.comment then
276+
return normalizeComment(source.comment.text, guide.getUri(source))
277+
end
278+
if source.bindGroup then
279+
return getBindComment(source)
277280
end
278-
local comment = getBindComment(source)
279-
return comment
280281
end
281282

282283
local function getFunctionComment(source)
@@ -394,7 +395,7 @@ return function (source)
394395
source = source.parent
395396
end
396397
return tryDocOverloadToComment(source)
397-
or tryDocFieldUpComment(source)
398+
or tryDocFieldComment(source)
398399
or tyrDocParamComment(source)
399400
or tryDocComment(source)
400401
or tryDocClassComment(source)

script/core/hover/table.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ return function (source)
178178
return nil
179179
end
180180

181-
for view in vm.getInfer(source):eachView(uri) do
182-
if view == 'string'
183-
or (view ~= 'unknown' and view ~= 'any' and vm.isSubType(uri, view, 'string')) then
181+
local node = vm.compileNode(source)
182+
for n in node:eachObject() do
183+
if n.type == 'global' and n.cate == 'type' then
184+
if n.name == 'string'
185+
or (n.name ~= 'unknown' and n.name ~= 'any' and vm.isSubType(uri, n.name, 'string')) then
186+
return nil
187+
end
188+
elseif n.type == 'doc.type.string'
189+
or n.type == 'string' then
184190
return nil
185191
end
186192
end

test/crossfile/hover.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,3 +1360,25 @@ local n: unknown
13601360
---
13611361
[here](command:xxxxx)]]
13621362
}
1363+
1364+
TEST {
1365+
{
1366+
path = 'a.lua',
1367+
content = [[
1368+
---@class A
1369+
---@field x number # comments
1370+
1371+
---@type A
1372+
local t
1373+
1374+
print(t.<?x?>)
1375+
]]
1376+
},
1377+
hover = [[
1378+
```lua
1379+
(field) A.x: number
1380+
```
1381+
1382+
---
1383+
comments]]
1384+
}

test/hover/init.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,3 +2112,11 @@ print(<?bool?>)
21122112
[[
21132113
local bool: boolean = true|false
21142114
]]
2115+
2116+
TEST [[
2117+
---@type 'a'
2118+
local <?s?>
2119+
]]
2120+
[[
2121+
local s: 'a'
2122+
]]

0 commit comments

Comments
 (0)