diff options
author | actboy168 <actboy168@gmail.com> | 2020-12-03 14:15:41 +0800 |
---|---|---|
committer | actboy168 <actboy168@gmail.com> | 2020-12-03 14:15:41 +0800 |
commit | d481a5a6a103a057830d62a5d4afa04f0cab3a1e (patch) | |
tree | 19476dc413a58e49e55b9c3fe36d5f8ada299957 | |
parent | c08d501b7bdea16d87998d3ef28c2b708515cd10 (diff) | |
download | lua-language-server-d481a5a6a103a057830d62a5d4afa04f0cab3a1e.zip |
增加若干测试
-rw-r--r-- | script/core/hover/description.lua | 21 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 111 |
2 files changed, 108 insertions, 24 deletions
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index 7be50947..74896709 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -210,22 +210,25 @@ local function getFunctionComment(source) ) end elseif doc.type == 'doc.return' then - if has_return_comment and doc.comment then + if has_return_comment then local name = {} for _, rtn in ipairs(doc.returns) do if rtn.name then name[#name+1] = rtn.name[1] end end - if #name == 0 then - comments[#comments+1] = ('@*return* — %s'):format( - doc.comment.text - ) + if doc.comment then + if #name == 0 then + comments[#comments+1] = ('@*return* — %s'):format(doc.comment.text) + else + comments[#comments+1] = ('@*return* `%s` — %s'):format(table.concat(name, ','), doc.comment.text) + end else - comments[#comments+1] = ('@*return* `%s` — %s'):format( - table.concat(name, ','), - doc.comment.text - ) + if #name == 0 then + comments[#comments+1] = '@*return*' + else + comments[#comments+1] = ('@*return* `%s`'):format(table.concat(name, ',')) + end end end end diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 3715ba9c..9fc0842e 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -485,23 +485,104 @@ function f(x: string, y: table) } } -TEST { - { - path = 'a.lua', - content = '', - }, - { - path = 'b.lua', - content = [[ +TEST {{ path = 'a.lua', content = '', }, { + path = 'b.lua', + content = [[ ---Comment ---@param x string ---@return string # this is comment function f(<?x?>) end ]] - }, - hover = { - label = [[local x: string]], - name = 'x', - description = nil, - } -} +}, +hover = { + label = [[local x: string]], + name = 'x', + description = nil, +}} + + +TEST {{ path = 'a.lua', content = '', }, { + path = 'b.lua', + content = [[ + ---comment1 + ---@param arg1 integer + ---@param arg2 integer comment2 + ---@return boolean + ---comment3 + function <?f?>(arg1, arg2) end + ]] +}, +hover = { + label = [[ +function f(arg1: integer, arg2: integer) + -> boolean]], + name = 'f', + description = [[ +--- + +comment1 + +@*param* `arg2` — comment2 + +comment3]] +}} + + +TEST {{ path = 'a.lua', content = '', }, { + path = 'b.lua', + content = [[ + ---@return boolean, string #comment + function <?f?>() end + ]] +}, +hover = { + label = [[ +function f() + -> boolean + 2. string]], + name = 'f', + description = [[ +--- + +@*return* — comment]] +}} + +TEST {{ path = 'a.lua', content = '', }, { + path = 'b.lua', + content = [[ + ---@return boolean + ---@return string #comment + function <?f?>() end + ]] +}, +hover = { + label = [[ +function f() + -> boolean + 2. string]], + name = 'f', + description = [[ +--- + +@*return* + +@*return* — comment]] +}} + + +TEST {{ path = 'a.lua', content = '', }, { + path = 'b.lua', + content = [[ + ---@return boolean + ---@return string + function <?f?>() end + ]] +}, +hover = { + label = [[ +function f() + -> boolean + 2. string]], + name = 'f', + description = nil +}} |