diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-03-22 16:15:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-03-22 16:15:16 +0800 |
commit | b8627365c0abe5a9d40c91f81b2aef7ea869faad (patch) | |
tree | d1634ad66931919067a9609fb645d99f576bb7ad | |
parent | 5b6542e8ff276a195c502cc2479b53685429eb2e (diff) | |
download | lua-language-server-b8627365c0abe5a9d40c91f81b2aef7ea869faad.zip |
don't treat half string in comment as string
fix #2013
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 11 | ||||
-rw-r--r-- | 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 <?foo?>(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]] +} |