summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-08 23:42:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-08 23:42:52 +0800
commit9a050f2aa27dc026d0121b80084fb68093c37ac8 (patch)
tree1ddf9f7d719a732b92c5c1db8dba21146f93c0a1
parent1dfee9623937c0619b3aaf3e2139afcc14351042 (diff)
downloadlua-language-server-9a050f2aa27dc026d0121b80084fb68093c37ac8.zip
exp的情况
-rw-r--r--script-beta/core/completion.lua44
-rw-r--r--test-beta/completion/init.lua27
2 files changed, 51 insertions, 20 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 24efbf7b..7ddc2c95 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -713,21 +713,37 @@ local function checkLenPlusOne(ast, text, offset, results)
if not matchKey(writingText, nodeText) then
return
end
- local eq = text:find('%s*%=', source.node.finish)
- local label = text:match('%#[ \t]*', pos) .. nodeText .. '+1'
- local newText = label .. ']'
- if not eq then
- newText = newText .. ' = '
+ if source.parent == guide.getParentBlock(source) then
+ -- state
+ local label = text:match('%#[ \t]*', pos) .. nodeText .. '+1'
+ local eq = text:find('%s*%=', source.node.finish)
+ local newText = label .. ']'
+ if not eq then
+ newText = newText .. ' = '
+ end
+ results[#results+1] = {
+ label = label,
+ kind = ckind.Snippet,
+ textEdit = {
+ start = pos,
+ finish = source.finish,
+ newText = newText,
+ },
+ }
+ else
+ -- exp
+ local label = text:match('%#[ \t]*', pos) .. nodeText
+ local newText = label .. ']'
+ results[#results+1] = {
+ label = label,
+ kind = ckind.Snippet,
+ textEdit = {
+ start = pos,
+ finish = source.finish,
+ newText = newText,
+ },
+ }
end
- results[#results+1] = {
- label = label,
- kind = ckind.Snippet,
- textEdit = {
- start = pos,
- finish = source.finish,
- newText = newText,
- },
- }
end
end)
end
diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua
index e950b40c..c042dd7b 100644
--- a/test-beta/completion/init.lua
+++ b/test-beta/completion/init.lua
@@ -653,25 +653,40 @@ fff[#ff$]
}
}
--- TODO
-do return end
-
TEST [[
local _ = fff.kkk[#$]
]]
{
{
- label = 'fff.kkk',
+ label = '#fff.kkk',
kind = CompletionItemKind.Snippet,
textEdit = {
- start = 20,
+ start = 19,
finish = 20,
- newText = 'fff.kkk]',
+ newText = '#fff.kkk]',
},
},
}
TEST [[
+fff.kkk[#$].yy
+]]
+{
+ {
+ label = '#fff.kkk',
+ kind = CompletionItemKind.Snippet,
+ textEdit = {
+ start = 9,
+ finish = 10,
+ newText = '#fff.kkk]',
+ },
+ },
+}
+
+-- TODO
+do return end
+
+TEST [[
local t = {
a = 1,
}