diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-08 23:19:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-08 23:19:02 +0800 |
commit | 0ecd76a8ac07687e7c8a79ed2fc34a5794cc1c8f (patch) | |
tree | 06ae315dca91b532ca722d4f0319cf1437229858 | |
parent | 6ee179f6fbf2d9d89c07fa408c9218eb55422b39 (diff) | |
download | lua-language-server-0ecd76a8ac07687e7c8a79ed2fc34a5794cc1c8f.zip |
自增支持
-rw-r--r-- | script-beta/core/completion.lua | 25 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 21 |
2 files changed, 42 insertions, 4 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 8839952b..f3c330b5 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -699,7 +699,30 @@ local function checkLenPlusOne(ast, text, offset, results) guide.eachSourceContain(ast.ast, offset, function (source) if source.type == 'getindex' or source.type == 'setindex' then - local pos + local _, pos = text:find('%s*%[%s*%#', source.node.finish) + if not pos then + return + end + local nodeText = text:sub(source.node.start, source.node.finish) + local writingText = trim(text:sub(pos + 1, offset - 1)) or '' + 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 .. ' = ' + 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 a5f4868e..3250b838 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -596,12 +596,27 @@ self.results.list[#$] ]] { { - label = 'self.results.list+1', + label = '#self.results.list+1', kind = CompletionItemKind.Snippet, textEdit = { - start = 20, + start = 19, finish = 20, - newText = 'self.results.list+1] = ', + newText = '#self.results.list+1] = ', + }, + }, +} + +TEST [[ +self.results.list[#$] = 1 +]] +{ + { + label = '#self.results.list+1', + kind = CompletionItemKind.Snippet, + textEdit = { + start = 19, + finish = 20, + newText = '#self.results.list+1]', }, }, } |