diff options
-rw-r--r-- | script/core/hover/description.lua | 32 | ||||
-rw-r--r-- | script/provider/markdown.lua | 4 | ||||
-rw-r--r-- | script/vm/def.lua | 10 | ||||
-rw-r--r-- | test/completion/common.lua | 1 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 89 | ||||
-rw-r--r-- | test/definition/luadoc.lua | 12 |
6 files changed, 136 insertions, 12 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 5f5c50f6..32a0a798 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -125,7 +125,11 @@ local function getBindComment(source) return table.concat(lines, '\n') end -local function lookUpDocComments(source, docGroup) +local function lookUpDocComments(source) + local docGroup = source.bindDocs + if not docGroup then + return + end if source.type == 'setlocal' or source.type == 'getlocal' then source = source.node @@ -282,6 +286,9 @@ end local function getFunctionComment(source) local docGroup = source.bindDocs + if not docGroup then + return + end local hasReturnComment = false for _, doc in ipairs(source.bindDocs) do @@ -329,23 +336,28 @@ local function getFunctionComment(source) elseif doc.type == 'doc.overload' then md:splitLine() end - ::CONTINUE:: end local enums = getBindEnums(source, docGroup) md:add('lua', enums) - return md + + local comment = md:string() + if comment == '' then + return nil + end + return comment end local function tryDocComment(source) - if not source.bindDocs then - return - end - if source.type ~= 'function' then - local comment = lookUpDocComments(source, source.bindDocs) - return comment + if source.type == 'function' then + local comment = getFunctionComment(source) + if comment then + return comment + end + source = source.parent end - return getFunctionComment(source) + local comment = lookUpDocComments(source) + return comment end local function tryDocOverloadToComment(source) diff --git a/script/provider/markdown.lua b/script/provider/markdown.lua index f2f7f777..50716073 100644 --- a/script/provider/markdown.lua +++ b/script/provider/markdown.lua @@ -94,6 +94,10 @@ function mt:string(nl) if lines[#lines] ~= '' then lines[#lines+1] = '' end + elseif last == '---' then + if lines[#lines] ~= '' then + lines[#lines+1] = '' + end end end lines[#lines+1] = obj.text diff --git a/script/vm/def.lua b/script/vm/def.lua index a7af29b2..f557f221 100644 --- a/script/vm/def.lua +++ b/script/vm/def.lua @@ -102,9 +102,15 @@ local nodeSwitch;nodeSwitch = util.switch() if lastKey then return end - local tbl = source.parent + local key = guide.getKeyName(source) + if type(key) ~= 'string' then + return + end local uri = guide.getUri(source) - searchFieldSwitch(tbl.type, uri, tbl, guide.getKeyName(source), pushResult) + local parentNode = vm.compileNode(source.node) + for pn in parentNode:eachObject() do + searchFieldSwitch(pn.type, uri, pn, key, pushResult) + end end) : case 'doc.see.field' : call(function (source, lastKey, pushResult) diff --git a/test/completion/common.lua b/test/completion/common.lua index 81368e6e..98901a98 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -2012,6 +2012,7 @@ zz<??> ``` --- + abc]], } } diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 84276a27..f412183c 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -77,6 +77,7 @@ TEST { ``` --- + * [a.lua](file:///a.lua) (搜索路径: `?.lua`)]], } @@ -109,6 +110,7 @@ TEST { ``` --- + * [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `Folder\?.lua`)]], } @@ -127,6 +129,7 @@ TEST { ``` --- + * [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `?.lua`)]], } @@ -145,6 +148,7 @@ TEST { ``` --- + * [Folder\a.lua](file:///Folder/a.lua) (搜索路径: `?.lua`)]], } else @@ -163,6 +167,7 @@ TEST { ``` --- + * [Folder/a.lua](file:///Folder/a.lua) (搜索路径: `Folder/?.lua`)]], } end @@ -329,6 +334,7 @@ function f(x: number) ``` --- + abc]] } @@ -350,6 +356,7 @@ TEST { ``` --- + abc]] } @@ -488,6 +495,7 @@ function f(<?x?>) end ``` --- + this is comment]] } @@ -557,6 +565,7 @@ function f(arg1: integer, arg2: integer) ``` --- + comment1 @*param* `arg2` — comment2 @@ -666,6 +675,7 @@ function f() ``` --- + comment1 comment2]]} @@ -710,6 +720,7 @@ local x: A ``` --- + AAA]]} TEST {{ path = 'a.lua', content = '', }, { @@ -730,6 +741,7 @@ local x: A { ``` --- + AAA]]} TEST {{ path = 'a.lua', content = '', }, { @@ -749,9 +761,11 @@ local x: A ``` --- + BBB --- + AAA]]} TEST {{ path = 'a.lua', content = '', }, { @@ -770,9 +784,11 @@ hover = [[ ``` --- + AAA --- + BBB]]} TEST {{ path = 'a.lua', content = '', }, { @@ -791,9 +807,11 @@ hover = [[ ``` --- + BBB --- + AAA]]} TEST {{ path = 'a.lua', content = '', }, { @@ -829,6 +847,7 @@ local food: unknown ``` --- + I'm a multiline comment ]]} @@ -937,6 +956,7 @@ function bthci.rawhci(hcibytes: any, callback: any) ``` --- + Sends a raw HCI command to the BlueTooth controller.]]} TEST {{ path = 'a.lua', content = '', }, { @@ -1021,6 +1041,7 @@ function fn() ``` --- + line1 line2]]} @@ -1156,6 +1177,7 @@ TEST { ``` --- + The color of your awesome apple!]] } @@ -1235,6 +1257,7 @@ local n: integer ``` --- + comments]] } @@ -1253,6 +1276,7 @@ local n: integer ``` --- + comments]] } @@ -1271,6 +1295,7 @@ local n: integer ``` --- + comments]] } @@ -1289,6 +1314,7 @@ local n: integer ``` --- + comments]] } @@ -1307,6 +1333,7 @@ local n: integer ``` --- + comments]] } @@ -1324,6 +1351,7 @@ local n: unknown ``` --- + [here](file:///x.lua)]] } @@ -1341,6 +1369,7 @@ local n: unknown ``` --- + [here](file:///d%3A/x.lua)]] } @@ -1358,6 +1387,7 @@ local n: unknown ``` --- + [here](command:xxxxx)]] } @@ -1380,5 +1410,64 @@ TEST { ``` --- + + comments]] +} + +TEST { + { + path = 'a.lua', + content = [[ + -- comments + <?A?> = function () end + ]] + }, + hover = [[ +```lua +function A() +``` + +--- + + comments]] +} + +TEST { + { + path = 'a.lua', + content = [[ + local t = { + -- comments + <?A?> = function () end + } + ]] + }, + hover = [[ +```lua +function A() +``` + +--- + + comments]] +} + +TEST { + { + path = 'a.lua', + content = [[ + -- comments + ---@return number + <?A?> = function () end + ]] + }, + hover = [[ +```lua +function A() + -> number +``` + +--- + comments]] } diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua index b07396fa..2d927016 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -907,3 +907,15 @@ local function f() ---@cast <?x?> integer end ]] + +TEST [[ +---@class A +---@field <!x!> number + +---@param a A +local function f(a) end + +f { + <!<?x?>!> = 1, +} +]] |