Skip to content

Commit f7cdfee

Browse files
committed
Alias markdown hover does not repeat description
1 parent 8d12152 commit f7cdfee

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

script/core/hover/description.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ local function lookUpDocComments(source)
212212
return table.concat(lines, '\n')
213213
end
214214

215-
local function tryDocClassComment(source)
215+
local function tryDocClassComment(source, types)
216+
types = types or {['doc.class'] = true}
217+
216218
for _, def in ipairs(vm.getDefs(source)) do
217-
if def.type == 'doc.class'
218-
or def.type == 'doc.alias'
219-
or def.type == 'doc.enum' then
219+
if types[def.type] then
220220
local comment = getBindComment(def)
221221
if comment then
222222
return comment
@@ -238,7 +238,9 @@ local function buildEnumChunk(docType, name, uri)
238238
end
239239
local enums = {}
240240
local types = {}
241-
local lines = {}
241+
local lines = {('#### %s:'):format(name)}
242+
local commentTypes = {['doc.enum'] = true, ['doc.alias'] = true}
243+
242244
for _, tp in ipairs(vm.getDefs(docType)) do
243245
types[#types+1] = vm.getInfer(tp):view(guide.getUri(docType))
244246
if tp.type == 'doc.type.string'
@@ -247,20 +249,22 @@ local function buildEnumChunk(docType, name, uri)
247249
or tp.type == 'doc.type.code' then
248250
enums[#enums+1] = tp
249251
end
250-
local comment = tryDocClassComment(tp)
252+
253+
local comment = tryDocClassComment(tp, commentTypes)
251254
if comment then
252255
for line in util.eachLine(comment) do
253256
lines[#lines+1] = line
254257
end
255258
end
256259
end
260+
257261
if #enums == 0 then
258262
return nil
259263
end
260-
if #lines > 0 and lines[#lines] ~= "" then
264+
if #lines > 1 then
261265
lines[#lines+1] = ""
262266
end
263-
lines[#lines+1] = ('#### %s:'):format(name)
267+
264268
for _, enum in ipairs(enums) do
265269
local suffix = (enum.default and ' (default)')
266270
or (enum.additional and ' (additional)')

test/crossfile/hover.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,7 @@ TEST {
15121512
{
15131513
path = 'a.lua',
15141514
content = [[
1515+
---Description comment
15151516
---@alias A
15161517
---| 1 # comment1
15171518
---| 2 # comment2
@@ -1528,6 +1529,8 @@ local x: 1|2
15281529
---
15291530
15301531
#### A:
1532+
Description comment
1533+
15311534
- `1` — comment1
15321535
- `2` — comment2]]
15331536
}

0 commit comments

Comments
 (0)