Skip to content

Commit 82d716c

Browse files
committed
resolve #1224 show comments for doc.field
1 parent ac3235f commit 82d716c

File tree

6 files changed

+136
-12
lines changed

6 files changed

+136
-12
lines changed

script/core/hover/description.lua

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ local function getBindComment(source)
125125
return table.concat(lines, '\n')
126126
end
127127

128-
local function lookUpDocComments(source, docGroup)
128+
local function lookUpDocComments(source)
129+
local docGroup = source.bindDocs
130+
if not docGroup then
131+
return
132+
end
129133
if source.type == 'setlocal'
130134
or source.type == 'getlocal' then
131135
source = source.node
@@ -282,6 +286,9 @@ end
282286

283287
local function getFunctionComment(source)
284288
local docGroup = source.bindDocs
289+
if not docGroup then
290+
return
291+
end
285292

286293
local hasReturnComment = false
287294
for _, doc in ipairs(source.bindDocs) do
@@ -329,23 +336,28 @@ local function getFunctionComment(source)
329336
elseif doc.type == 'doc.overload' then
330337
md:splitLine()
331338
end
332-
::CONTINUE::
333339
end
334340

335341
local enums = getBindEnums(source, docGroup)
336342
md:add('lua', enums)
337-
return md
343+
344+
local comment = md:string()
345+
if comment == '' then
346+
return nil
347+
end
348+
return comment
338349
end
339350

340351
local function tryDocComment(source)
341-
if not source.bindDocs then
342-
return
343-
end
344-
if source.type ~= 'function' then
345-
local comment = lookUpDocComments(source, source.bindDocs)
346-
return comment
352+
if source.type == 'function' then
353+
local comment = getFunctionComment(source)
354+
if comment then
355+
return comment
356+
end
357+
source = source.parent
347358
end
348-
return getFunctionComment(source)
359+
local comment = lookUpDocComments(source)
360+
return comment
349361
end
350362

351363
local function tryDocOverloadToComment(source)

script/provider/markdown.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ function mt:string(nl)
9494
if lines[#lines] ~= '' then
9595
lines[#lines+1] = ''
9696
end
97+
elseif last == '---' then
98+
if lines[#lines] ~= '' then
99+
lines[#lines+1] = ''
100+
end
97101
end
98102
end
99103
lines[#lines+1] = obj.text

script/vm/def.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,15 @@ local nodeSwitch;nodeSwitch = util.switch()
102102
if lastKey then
103103
return
104104
end
105-
local tbl = source.parent
105+
local key = guide.getKeyName(source)
106+
if type(key) ~= 'string' then
107+
return
108+
end
106109
local uri = guide.getUri(source)
107-
searchFieldSwitch(tbl.type, uri, tbl, guide.getKeyName(source), pushResult)
110+
local parentNode = vm.compileNode(source.node)
111+
for pn in parentNode:eachObject() do
112+
searchFieldSwitch(pn.type, uri, pn, key, pushResult)
113+
end
108114
end)
109115
: case 'doc.see.field'
110116
: call(function (source, lastKey, pushResult)

test/completion/common.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,7 @@ zz<??>
20122012
```
20132013
20142014
---
2015+
20152016
abc]],
20162017
}
20172018
}

test/crossfile/hover.lua

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ TEST {
7777
```
7878
7979
---
80+
8081
* [a.lua](file:///a.lua) (搜索路径: `?.lua`)]],
8182
}
8283

@@ -109,6 +110,7 @@ TEST {
109110
```
110111
111112
---
113+
112114
* [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `Folder\?.lua`)]],
113115
}
114116

@@ -127,6 +129,7 @@ TEST {
127129
```
128130
129131
---
132+
130133
* [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `?.lua`)]],
131134
}
132135

@@ -145,6 +148,7 @@ TEST {
145148
```
146149
147150
---
151+
148152
* [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `?.lua`)]],
149153
}
150154
else
@@ -163,6 +167,7 @@ TEST {
163167
```
164168
165169
---
170+
166171
* [Folder/a.lua](file:///Folder/a.lua) (搜索路径: `Folder/?.lua`)]],
167172
}
168173
end
@@ -329,6 +334,7 @@ function f(x: number)
329334
```
330335
331336
---
337+
332338
abc]]
333339
}
334340

@@ -350,6 +356,7 @@ TEST {
350356
```
351357
352358
---
359+
353360
abc]]
354361
}
355362

@@ -488,6 +495,7 @@ function f(<?x?>) end
488495
```
489496
490497
---
498+
491499
this is comment]]
492500
}
493501

@@ -557,6 +565,7 @@ function f(arg1: integer, arg2: integer)
557565
```
558566
559567
---
568+
560569
comment1
561570
562571
@*param* `arg2` — comment2
@@ -666,6 +675,7 @@ function f()
666675
```
667676
668677
---
678+
669679
comment1
670680
comment2]]}
671681

@@ -710,6 +720,7 @@ local x: A
710720
```
711721
712722
---
723+
713724
AAA]]}
714725

715726
TEST {{ path = 'a.lua', content = '', }, {
@@ -730,6 +741,7 @@ local x: A {
730741
```
731742
732743
---
744+
733745
AAA]]}
734746

735747
TEST {{ path = 'a.lua', content = '', }, {
@@ -749,9 +761,11 @@ local x: A
749761
```
750762
751763
---
764+
752765
BBB
753766
754767
---
768+
755769
AAA]]}
756770

757771
TEST {{ path = 'a.lua', content = '', }, {
@@ -770,9 +784,11 @@ hover = [[
770784
```
771785
772786
---
787+
773788
AAA
774789
775790
---
791+
776792
BBB]]}
777793

778794
TEST {{ path = 'a.lua', content = '', }, {
@@ -791,9 +807,11 @@ hover = [[
791807
```
792808
793809
---
810+
794811
BBB
795812
796813
---
814+
797815
AAA]]}
798816

799817
TEST {{ path = 'a.lua', content = '', }, {
@@ -829,6 +847,7 @@ local food: unknown
829847
```
830848
831849
---
850+
832851
I'm a multiline comment
833852
]]}
834853

@@ -937,6 +956,7 @@ function bthci.rawhci(hcibytes: any, callback: any)
937956
```
938957
939958
---
959+
940960
Sends a raw HCI command to the BlueTooth controller.]]}
941961

942962
TEST {{ path = 'a.lua', content = '', }, {
@@ -1021,6 +1041,7 @@ function fn()
10211041
```
10221042
10231043
---
1044+
10241045
line1
10251046
10261047
line2]]}
@@ -1156,6 +1177,7 @@ TEST {
11561177
```
11571178
11581179
---
1180+
11591181
The color of your awesome apple!]]
11601182
}
11611183

@@ -1235,6 +1257,7 @@ local n: integer
12351257
```
12361258
12371259
---
1260+
12381261
comments]]
12391262
}
12401263

@@ -1253,6 +1276,7 @@ local n: integer
12531276
```
12541277
12551278
---
1279+
12561280
comments]]
12571281
}
12581282

@@ -1271,6 +1295,7 @@ local n: integer
12711295
```
12721296
12731297
---
1298+
12741299
comments]]
12751300
}
12761301

@@ -1289,6 +1314,7 @@ local n: integer
12891314
```
12901315
12911316
---
1317+
12921318
comments]]
12931319
}
12941320

@@ -1307,6 +1333,7 @@ local n: integer
13071333
```
13081334
13091335
---
1336+
13101337
comments]]
13111338
}
13121339

@@ -1324,6 +1351,7 @@ local n: unknown
13241351
```
13251352
13261353
---
1354+
13271355
[here](file:///x.lua)]]
13281356
}
13291357

@@ -1341,6 +1369,7 @@ local n: unknown
13411369
```
13421370
13431371
---
1372+
13441373
[here](file:///d%3A/x.lua)]]
13451374
}
13461375

@@ -1358,6 +1387,7 @@ local n: unknown
13581387
```
13591388
13601389
---
1390+
13611391
[here](command:xxxxx)]]
13621392
}
13631393

@@ -1380,5 +1410,64 @@ TEST {
13801410
```
13811411
13821412
---
1413+
1414+
comments]]
1415+
}
1416+
1417+
TEST {
1418+
{
1419+
path = 'a.lua',
1420+
content = [[
1421+
-- comments
1422+
<?A?> = function () end
1423+
]]
1424+
},
1425+
hover = [[
1426+
```lua
1427+
function A()
1428+
```
1429+
1430+
---
1431+
1432+
comments]]
1433+
}
1434+
1435+
TEST {
1436+
{
1437+
path = 'a.lua',
1438+
content = [[
1439+
local t = {
1440+
-- comments
1441+
<?A?> = function () end
1442+
}
1443+
]]
1444+
},
1445+
hover = [[
1446+
```lua
1447+
function A()
1448+
```
1449+
1450+
---
1451+
1452+
comments]]
1453+
}
1454+
1455+
TEST {
1456+
{
1457+
path = 'a.lua',
1458+
content = [[
1459+
-- comments
1460+
---@return number
1461+
<?A?> = function () end
1462+
]]
1463+
},
1464+
hover = [[
1465+
```lua
1466+
function A()
1467+
-> number
1468+
```
1469+
1470+
---
1471+
13831472
comments]]
13841473
}

0 commit comments

Comments
 (0)