Skip to content

Commit

Permalink
fix #1395
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jul 29, 2022
1 parent 7397df3 commit 2a795db
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# changelog

## 3.5.2
* `FIX` [#1395](https://github.com/sumneko/lua-language-server/issues/1395)

## 3.5.1
`2022-7-26`
* `NEW` supports [color](https://github.com/sumneko/lua-language-server/pull/1379)
Expand Down
14 changes: 7 additions & 7 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ end

local function getComment(state, position)
local offset = guide.positionToOffset(state, position)
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset)
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset, true)
if not symbolOffset then
return
end
Expand All @@ -1610,9 +1610,9 @@ local function getComment(state, position)
return nil
end

local function getluaDoc(state, position)
local function getLuaDoc(state, position)
local offset = guide.positionToOffset(state, position)
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset)
local symbolOffset = lookBackward.findAnyOffset(state.lua, offset, true)
if not symbolOffset then
return
end
Expand Down Expand Up @@ -2063,8 +2063,8 @@ local function tryluaDocOfFunction(doc, results)
}
end

local function tryluaDoc(state, position, results)
local doc = getluaDoc(state, position)
local function tryLuaDoc(state, position, results)
local doc = getLuaDoc(state, position)
if not doc then
return
end
Expand Down Expand Up @@ -2103,7 +2103,7 @@ local function tryComment(state, position, results)
return
end
local word = lookBackward.findWord(state.lua, guide.positionToOffset(state, position))
local doc = getluaDoc(state, position)
local doc = getLuaDoc(state, position)
if not word then
local comment = getComment(state, position)
if not comment then
Expand Down Expand Up @@ -2142,7 +2142,7 @@ local function tryCompletions(state, position, triggerCharacter, results)
return
end
if getComment(state, position) then
tryluaDoc(state, position, results)
tryLuaDoc(state, position, results)
tryComment(state, position, results)
return
end
Expand Down
14 changes: 12 additions & 2 deletions script/core/look-backward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ function m.findTargetSymbol(text, offset, symbol)
return nil
end

function m.findAnyOffset(text, offset)
---@param text string
---@param offset integer
---@param inline? boolean # 必须在同一行中(排除换行符)
function m.findAnyOffset(text, offset, inline)
for i = offset, 1, -1 do
if not m.isSpace(text:sub(i, i)) then
local c = text:sub(i, i)
if inline then
if c == '\r'
or c == '\n' then
return nil
end
end
if not m.isSpace(c) then
return i
end
end
Expand Down
16 changes: 16 additions & 0 deletions test/completion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3697,3 +3697,19 @@ f(<??>)
kind = define.CompletionItemKind.EnumMember,
},
}

TEST [[
--
<??>
]]
(function (results)
assert(#results > 2)
end)

TEST [[
--xxx
<??>
]]
(function (results)
assert(#results > 2)
end)

0 comments on commit 2a795db

Please sign in to comment.