summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/completion.lua9
-rw-r--r--server/src/method/textDocument/completion.lua2
-rw-r--r--server/test/completion/init.lua4
3 files changed, 8 insertions, 7 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index c5810d7c..508c0320 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -444,7 +444,9 @@ end
local function searchSpecial(vm, pos, callback)
-- 尝试 #
local result, source = findResult(vm, pos, 2)
- if source and source.op == '#' and source.index then
+ if source and source.type == 'index'
+ and result.source and result.source.op == '#'
+ then
local name = {}
local var = result
while true do
@@ -462,11 +464,10 @@ local function searchSpecial(vm, pos, callback)
table.insert(name, 1, key)
end
local label = table.concat(name, '.') .. '+1'
- -- TODO 把index实例化才能拿到正确的位置
callback(label, CompletionItemKind.Snippet, {
textEdit = {
- start = source.start + 1,
- finish = source.finish + 1,
+ start = result.source.start + 1,
+ finish = source.finish,
newText = ('%s] = '):format(label),
}
})
diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua
index 81ef1446..9c3b00ac 100644
--- a/server/src/method/textDocument/completion.lua
+++ b/server/src/method/textDocument/completion.lua
@@ -10,7 +10,7 @@ local function posToRange(lines, start, finish)
},
['end'] = {
line = finish_row - 1,
- character = finish_col - 1,
+ character = finish_col,
},
}
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 4d1c3e64..46544b36 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -62,7 +62,7 @@ rawset(_G, 'TEST', true)
function TEST(script)
return function (expect)
local pos = script:find('@', 1, true)
- local new_script = script:gsub('@', '')
+ local new_script = script:gsub('@', ' ')
local ast = parser:ast(new_script)
local vm = matcher.vm(ast)
assert(vm)
@@ -433,7 +433,7 @@ fff[#ff@]
kind = CompletionItemKind.Snippet,
textEdit = {
start = 6,
- finish = 8,
+ finish = 9,
newText = 'fff+1] = ',
},
},