summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-29 15:47:31 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-29 15:47:31 +0800
commit2a795db6935b37980ba7410fa7fbe0e0fd0a562a (patch)
treef33a55a6b2fbe4c73c062c7f84067655750fa4b2 /script/core
parent7397df30ab802b6f6e3b75c6094d1c1711604937 (diff)
downloadlua-language-server-2a795db6935b37980ba7410fa7fbe0e0fd0a562a.zip
fix #1395
Diffstat (limited to 'script/core')
-rw-r--r--script/core/completion/completion.lua14
-rw-r--r--script/core/look-backward.lua14
2 files changed, 19 insertions, 9 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 09d276a6..71f38645 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua
index eeee6017..8d3e3439 100644
--- a/script/core/look-backward.lua
+++ b/script/core/look-backward.lua
@@ -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