Skip to content

Commit b862736

Browse files
committed
don't treat half string in comment as string
fix #2013
1 parent 5b6542e commit b862736

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
## 3.6.18
44
* `FIX` [#1943]
55
* `FIX` [#1996]
6+
* `FIX` [#2013]
67

78
[#1943]: https://github.com./LuaLS/lua-language-server/issues/1943
89
[#1996]: https://github.com./LuaLS/lua-language-server/issues/1996
10+
[#2013]: https://github.com./LuaLS/lua-language-server/issues/2013
911

1012
## 3.6.17
1113
`2023-3-9`

script/parser/luadoc.lua

+6-5
Original file line numberDiff line numberDiff line change
@@ -1501,21 +1501,22 @@ end
15011501
local function trimTailComment(text)
15021502
local comment = text
15031503
if text:sub(1, 1) == '@' then
1504-
comment = text:sub(2)
1504+
comment = util.trim(text:sub(2))
15051505
end
15061506
if text:sub(1, 1) == '#' then
1507-
comment = text:sub(2)
1507+
comment = util.trim(text:sub(2))
15081508
end
15091509
if text:sub(1, 2) == '--' then
1510-
comment = text:sub(3)
1510+
comment = util.trim(text:sub(3))
15111511
end
1512-
if comment:find '^%s*[\'"[]' then
1512+
if comment:find '^%s*[\'"[]'
1513+
and comment:find '[\'"%]]%s*$' then
15131514
local state = compile(comment:gsub('^%s+', ''), 'String')
15141515
if state and state.ast then
15151516
comment = state.ast[1]
15161517
end
15171518
end
1518-
return comment
1519+
return util.trim(comment)
15191520
end
15201521

15211522
local function buildLuaDoc(comment)

test/crossfile/hover.lua

+30-9
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ function f(x: string, y: table)
575575
576576
@*param* `x` — this is comment
577577
578-
@*param* `y` — comment 1
578+
@*param* `y` — comment 1
579579
580580
@*return* `name` — comment 2
581581
@@ -746,7 +746,7 @@ function f(a: boolean)
746746
747747
---
748748
749-
@*param* `a` — xxx
749+
@*param* `a` — xxx
750750
751751
```lua
752752
a:
@@ -1308,7 +1308,7 @@ local n: integer
13081308
13091309
---
13101310
1311-
comments]]
1311+
comments]]
13121312
}
13131313

13141314
TEST {
@@ -1365,7 +1365,7 @@ local n: integer
13651365
13661366
---
13671367
1368-
comments]]
1368+
comments]]
13691369
}
13701370

13711371
TEST {
@@ -1384,7 +1384,7 @@ local n: integer
13841384
13851385
---
13861386
1387-
comments]]
1387+
comments]]
13881388
}
13891389

13901390
TEST {
@@ -1461,7 +1461,7 @@ TEST {
14611461
14621462
---
14631463
1464-
comments]]
1464+
comments]]
14651465
}
14661466

14671467
TEST {
@@ -1708,7 +1708,7 @@ local x: unknown
17081708
17091709
---
17101710
1711-
See: [A](file:///a.lua#1#10) comment1]]
1711+
See: [A](file:///a.lua#1#10) comment1]]
17121712
}
17131713

17141714
TEST { {path = 'a.lua', content = [[
@@ -1728,8 +1728,8 @@ local x: unknown
17281728
---
17291729
17301730
See:
1731-
* [A](file:///a.lua#1#10) comment1
1732-
* [TTT](file:///a.lua#3#0) comment2]]
1731+
* [A](file:///a.lua#1#10) comment1
1732+
* [TTT](file:///a.lua#3#0) comment2]]
17331733
}
17341734

17351735
TEST { {path = 'a.lua', content = [[
@@ -1755,3 +1755,24 @@ comment2
17551755
function f()
17561756
```]]
17571757
}
1758+
1759+
TEST { {path = 'a.lua', content = [[
1760+
---"hello world" this is ok
1761+
---@param bar any "lorem ipsum" this is ignored
1762+
---@param baz any # "dolor sit" this is ignored
1763+
local function <?foo?>(bar, baz)
1764+
end
1765+
]]},
1766+
hover = [[
1767+
```lua
1768+
function foo(bar: any, baz: any)
1769+
```
1770+
1771+
---
1772+
1773+
"hello world" this is ok
1774+
1775+
@*param* `bar` — "lorem ipsum" this is ignored
1776+
1777+
@*param* `baz` — "dolor sit" this is ignored]]
1778+
}

0 commit comments

Comments
 (0)