summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-17 20:19:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-17 20:19:50 +0800
commita09f301b5bb3d2a2bbceec9881c4091a7665bf56 (patch)
treecd2bdc7dbb3edb4115280622225f050b8a6eb48d
parentb6c59b00a307b7cb6396e96c65611a08ac3c3339 (diff)
downloadlua-language-server-a09f301b5bb3d2a2bbceec9881c4091a7665bf56.zip
更新index支持
-rw-r--r--script-beta/core/completion.lua34
-rw-r--r--test-beta/completion/init.lua45
2 files changed, 66 insertions, 13 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 0dec6d3b..8c99b38e 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -283,26 +283,34 @@ local function checkFieldThen(ast, key, src, word, start, offset, parent, oop, r
end
local textEdit, additionalTextEdits
if not name:match '^[%a_][%w_]*$' then
- local nxt = parent.next
- local dotPos
- if nxt.type == 'setfield'
- or nxt.type == 'getfield'
- or nxt.type == 'tablefield' then
- dotPos = nxt.dot.start
- elseif nxt.type == 'getmethod'
- or nxt.type == 'setmethod' then
- dotPos = nxt.colon.start
+ local uri = guide.getUri(parent)
+ local text = files.getText(uri)
+ local wordStart
+ if word == '' then
+ wordStart = text:match('()%S', start + 1) or (offset + 1)
+ else
+ wordStart = offset - #word + 1
end
textEdit = {
- start = start + 1,
+ start = wordStart,
finish = offset,
newText = ('[%q]'):format(name),
}
- if dotPos then
+ local nxt = parent.next
+ local dotStart
+ if nxt.type == 'setfield'
+ or nxt.type == 'getfield'
+ or nxt.type == 'tablefield' then
+ dotStart = nxt.dot.start
+ elseif nxt.type == 'setmethod'
+ or nxt.type == 'getmethod' then
+ dotStart = nxt.colon.start
+ end
+ if dotStart then
additionalTextEdits = {
{
- start = dotPos,
- finish = start,
+ start = dotStart,
+ finish = dotStart,
newText = '',
}
}
diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua
index cf79d795..f2fa9edf 100644
--- a/test-beta/completion/init.lua
+++ b/test-beta/completion/init.lua
@@ -1065,6 +1065,51 @@ t.$
}
}
+TEST [[
+local t = {
+ ['a.b.c'] = {}
+}
+
+t. $
+]]
+{
+ {
+ label = 'a.b.c',
+ kind = CompletionItemKind.Field,
+ textEdit = {
+ start = 40,
+ finish = 39,
+ newText = '["a.b.c"]',
+ },
+ additionalTextEdits = {
+ {
+ start = 36,
+ finish = 36,
+ newText = '',
+ },
+ },
+ }
+}
+
+TEST [[
+local t = {
+ ['a.b.c'] = {}
+}
+
+t['$']
+]]
+{
+ {
+ label = 'a.b.c',
+ kind = CompletionItemKind.Field,
+ textEdit = {
+ start = 37,
+ finish = 36,
+ newText = 'a.b.c',
+ },
+ }
+}
+
-- TODO
do return end
TEST [[