From b8627365c0abe5a9d40c91f81b2aef7ea869faad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Mar 2023 16:15:16 +0800 Subject: don't treat half string in comment as string fix #2013 --- changelog.md | 2 ++ script/parser/luadoc.lua | 11 ++++++----- test/crossfile/hover.lua | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/changelog.md b/changelog.md index 8b1537c8..59a3ca68 100644 --- a/changelog.md +++ b/changelog.md @@ -3,9 +3,11 @@ ## 3.6.18 * `FIX` [#1943] * `FIX` [#1996] +* `FIX` [#2013] [#1943]: https://github.com/LuaLS/lua-language-server/issues/1943 [#1996]: https://github.com/LuaLS/lua-language-server/issues/1996 +[#2013]: https://github.com/LuaLS/lua-language-server/issues/2013 ## 3.6.17 `2023-3-9` diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 545f9d95..2f5a8ad3 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1501,21 +1501,22 @@ end local function trimTailComment(text) local comment = text if text:sub(1, 1) == '@' then - comment = text:sub(2) + comment = util.trim(text:sub(2)) end if text:sub(1, 1) == '#' then - comment = text:sub(2) + comment = util.trim(text:sub(2)) end if text:sub(1, 2) == '--' then - comment = text:sub(3) + comment = util.trim(text:sub(3)) end - if comment:find '^%s*[\'"[]' then + if comment:find '^%s*[\'"[]' + and comment:find '[\'"%]]%s*$' then local state = compile(comment:gsub('^%s+', ''), 'String') if state and state.ast then comment = state.ast[1] end end - return comment + return util.trim(comment) end local function buildLuaDoc(comment) diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 3cd560ff..7763d643 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -575,7 +575,7 @@ function f(x: string, y: table) @*param* `x` — this is comment -@*param* `y` — comment 1 +@*param* `y` — comment 1 @*return* `name` — comment 2 @@ -746,7 +746,7 @@ function f(a: boolean) --- -@*param* `a` — xxx +@*param* `a` — xxx ```lua a: @@ -1308,7 +1308,7 @@ local n: integer --- - comments]] +comments]] } TEST { @@ -1365,7 +1365,7 @@ local n: integer --- - comments]] +comments]] } TEST { @@ -1384,7 +1384,7 @@ local n: integer --- - comments]] +comments]] } TEST { @@ -1461,7 +1461,7 @@ TEST { --- - comments]] +comments]] } TEST { @@ -1708,7 +1708,7 @@ local x: unknown --- -See: [A](file:///a.lua#1#10) comment1]] +See: [A](file:///a.lua#1#10) comment1]] } TEST { {path = 'a.lua', content = [[ @@ -1728,8 +1728,8 @@ local x: unknown --- See: - * [A](file:///a.lua#1#10) comment1 - * [TTT](file:///a.lua#3#0) comment2]] + * [A](file:///a.lua#1#10) comment1 + * [TTT](file:///a.lua#3#0) comment2]] } TEST { {path = 'a.lua', content = [[ @@ -1755,3 +1755,24 @@ comment2 function f() ```]] } + +TEST { {path = 'a.lua', content = [[ +---"hello world" this is ok +---@param bar any "lorem ipsum" this is ignored +---@param baz any # "dolor sit" this is ignored +local function (bar, baz) +end +]]}, +hover = [[ +```lua +function foo(bar: any, baz: any) +``` + +--- + +"hello world" this is ok + +@*param* `bar` — "lorem ipsum" this is ignored + +@*param* `baz` — "dolor sit" this is ignored]] +} -- cgit v1.2.3