Skip to content

Commit 2a795db

Browse files
committed
fix #1395
1 parent 7397df3 commit 2a795db

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# changelog
22

3+
## 3.5.2
4+
* `FIX` [#1395](https://github.com/sumneko/lua-language-server/issues/1395)
5+
36
## 3.5.1
47
`2022-7-26`
58
* `NEW` supports [color](https://github.com/sumneko/lua-language-server/pull/1379)

script/core/completion/completion.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ end
15971597

15981598
local function getComment(state, position)
15991599
local offset = guide.positionToOffset(state, position)
1600-
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset)
1600+
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset, true)
16011601
if not symbolOffset then
16021602
return
16031603
end
@@ -1610,9 +1610,9 @@ local function getComment(state, position)
16101610
return nil
16111611
end
16121612

1613-
local function getluaDoc(state, position)
1613+
local function getLuaDoc(state, position)
16141614
local offset = guide.positionToOffset(state, position)
1615-
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset)
1615+
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset, true)
16161616
if not symbolOffset then
16171617
return
16181618
end
@@ -2063,8 +2063,8 @@ local function tryluaDocOfFunction(doc, results)
20632063
}
20642064
end
20652065

2066-
local function tryluaDoc(state, position, results)
2067-
local doc = getluaDoc(state, position)
2066+
local function tryLuaDoc(state, position, results)
2067+
local doc = getLuaDoc(state, position)
20682068
if not doc then
20692069
return
20702070
end
@@ -2103,7 +2103,7 @@ local function tryComment(state, position, results)
21032103
return
21042104
end
21052105
local word = lookBackward.findWord(state.lua, guide.positionToOffset(state, position))
2106-
local doc = getluaDoc(state, position)
2106+
local doc = getLuaDoc(state, position)
21072107
if not word then
21082108
local comment = getComment(state, position)
21092109
if not comment then
@@ -2142,7 +2142,7 @@ local function tryCompletions(state, position, triggerCharacter, results)
21422142
return
21432143
end
21442144
if getComment(state, position) then
2145-
tryluaDoc(state, position, results)
2145+
tryLuaDoc(state, position, results)
21462146
tryComment(state, position, results)
21472147
return
21482148
end

script/core/look-backward.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ function m.findTargetSymbol(text, offset, symbol)
8181
return nil
8282
end
8383

84-
function m.findAnyOffset(text, offset)
84+
---@param text string
85+
---@param offset integer
86+
---@param inline? boolean # 必须在同一行中(排除换行符)
87+
function m.findAnyOffset(text, offset, inline)
8588
for i = offset, 1, -1 do
86-
if not m.isSpace(text:sub(i, i)) then
89+
local c = text:sub(i, i)
90+
if inline then
91+
if c == '\r'
92+
or c == '\n' then
93+
return nil
94+
end
95+
end
96+
if not m.isSpace(c) then
8797
return i
8898
end
8999
end

test/completion/common.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,3 +3697,19 @@ f(<??>)
36973697
kind = define.CompletionItemKind.EnumMember,
36983698
},
36993699
}
3700+
3701+
TEST [[
3702+
--
3703+
<??>
3704+
]]
3705+
(function (results)
3706+
assert(#results > 2)
3707+
end)
3708+
3709+
TEST [[
3710+
--xxx
3711+
<??>
3712+
]]
3713+
(function (results)
3714+
assert(#results > 2)
3715+
end)

0 commit comments

Comments
 (0)