summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-17 21:07:55 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-17 21:07:55 +0800
commit84148fbedef3f3ae04552dcf3218e05027c17625 (patch)
tree8c5c9f7b693c0d99282349f686660f55a01ad5ca /script/core
parentdb328eeed2ab7b67a179bb14edfdd0ad03c63bb1 (diff)
downloadlua-language-server-84148fbedef3f3ae04552dcf3218e05027c17625.zip
update
Diffstat (limited to 'script/core')
-rw-r--r--script/core/completion.lua27
-rw-r--r--script/core/keyword.lua8
-rw-r--r--script/core/look-backward.lua2
-rw-r--r--script/core/type-formatting.lua2
4 files changed, 20 insertions, 19 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index a3df659b..08d6f5f2 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -75,7 +75,8 @@ local function findNearestTableField(state, position)
end
local function findParent(state, text, position)
- for i = position, 1, -1 do
+ local offset = guide.positionToOffset(state, position)
+ for i = offset, 1, -1 do
local char = text:sub(i, i)
if lookBackward.isSpace(char) then
goto CONTINUE
@@ -92,10 +93,11 @@ local function findParent(state, text, position)
else
return nil, nil
end
- local anyPos = lookBackward.findAnyPos(text, i-1)
- if not anyPos then
+ local anyOffset = lookBackward.findAnyOffset(text, i-1)
+ if not anyOffset then
return nil, nil
end
+ local anyPos = guide.offsetToPosition(state, anyOffset)
local parent = guide.eachSourceContain(state.ast, anyPos, function (source)
if source.finish == anyPos then
return source
@@ -169,17 +171,18 @@ local function getSnip(source)
if def ~= source and def.type == 'function' then
local uri = guide.getUri(def)
local text = files.getText(uri)
- local lines = files.getLines(uri)
+ local state = files.getState(uri)
+ local lines = state.lines
if not text then
goto CONTINUE
end
if vm.isMetaFile(uri) then
goto CONTINUE
end
- local row = guide.rowColOf(def.start)
- local firstRow = lines[row]
- local lastRow = lines[math.min(row + context - 1, #lines)]
- local snip = text:sub(firstRow.start, lastRow.finish)
+ local firstRow = guide.rowColOf(def.start)
+ local lastRow = firstRow + context
+ local lastOffset = lines[lastRow] and (lines[lastRow] - 1) or #text
+ local snip = text:sub(lines[firstRow], lastOffset)
return snip
end
::CONTINUE::
@@ -698,7 +701,7 @@ local function checkCommon(myUri, word, text, position, results)
end
if #str >= 3
and not used[str]
- and guide.offsetToPosition(state, offset) ~= position then
+ and guide.offsetToPosition(state, offset - 1) ~= position then
used[str] = true
if matchKey(word, str) then
results[#results+1] = {
@@ -723,7 +726,7 @@ end
local function checkKeyWord(state, text, start, position, word, hasSpace, afterLocal, results)
local snipType = config.get 'Lua.completion.keywordSnippet'
- local symbol = lookBackward.findSymbol(text, guide.positionToOffset(state, start - 1))
+ local symbol = lookBackward.findSymbol(text, guide.positionToOffset(state, start))
local isExp = symbol == '(' or symbol == ',' or symbol == '='
local info = {
hasSpace = hasSpace,
@@ -1215,7 +1218,7 @@ local function tryWord(state, text, position, triggerCharacter, results)
return nil
end
else
- startPos = guide.offsetToPosition(state, start)
+ startPos = guide.offsetToPosition(state, start - 1)
end
local hasSpace = triggerCharacter ~= nil and finish ~= offset
if isInString(state, position) then
@@ -1416,7 +1419,7 @@ local function checkTableLiteralField(state, text, position, tbl, fields, result
-- {$}
local left = lookBackward.findWord(text, guide.positionToOffset(state, position))
if not left then
- local pos = lookBackward.findAnyPos(text, guide.positionToOffset(state, position))
+ local pos = lookBackward.findAnyOffset(text, guide.positionToOffset(state, position))
local char = text:sub(pos, pos)
if char == '{' or char == ',' or char == ';' then
left = ''
diff --git a/script/core/keyword.lua b/script/core/keyword.lua
index 8e041f1c..0825f1bc 100644
--- a/script/core/keyword.lua
+++ b/script/core/keyword.lua
@@ -24,14 +24,12 @@ end",
end
return true
end, function (info)
- return guide.eachSourceContain(info.ast.ast, info.start, function (source)
+ return guide.eachSourceContain(info.state.ast, info.start, function (source)
if source.type == 'while'
or source.type == 'in'
or source.type == 'loop' then
- for i = 1, #source.keyword do
- if info.start == source.keyword[i] then
- return true
- end
+ if source.finish - info.start <= 2 then
+ return true
end
end
end)
diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua
index ee89078f..2f90b768 100644
--- a/script/core/look-backward.lua
+++ b/script/core/look-backward.lua
@@ -77,7 +77,7 @@ function m.findTargetSymbol(text, offset, symbol)
return nil
end
-function m.findAnyPos(text, offset)
+function m.findAnyOffset(text, offset)
for i = offset, 1, -1 do
if not m.isSpace(text:sub(i, i)) then
return i
diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua
index 157a446d..d7bacbf8 100644
--- a/script/core/type-formatting.lua
+++ b/script/core/type-formatting.lua
@@ -27,7 +27,7 @@ local function findForward(text, offset, ...)
end
local function findBackward(text, offset, ...)
- local pos = lookBackward.findAnyPos(text, offset)
+ local pos = lookBackward.findAnyOffset(text, offset)
for _, symbol in ipairs { ... } do
if text:sub(pos - #symbol + 1, pos) == symbol then
return pos - #symbol + 1, symbol