diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-27 17:27:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-27 17:27:29 +0800 |
commit | 9f60f0982ed46448714044a394f3f1143563c581 (patch) | |
tree | c255d9f9cc569fe14d2361cb0159e10b92659554 | |
parent | 0583a7dd28bb21012ac8334b5b2479a378263b6f (diff) | |
download | lua-language-server-9f60f0982ed46448714044a394f3f1143563c581.zip |
#的自动完成会检查场合
-rw-r--r-- | server/src/core/completion.lua | 27 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 2 | ||||
-rw-r--r-- | server/test/completion/init.lua | 10 |
3 files changed, 31 insertions, 8 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 54f96295..16b2ad4c 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -488,14 +488,25 @@ local function searchSpecial(vm, source, word, callback, pos) end end -- 4. 创建代码片段 - local label = table.concat(chars) .. '+1' - callback(label, nil, CompletionItemKind.Snippet, { - textEdit = { - start = inside.start + 1, - finish = index.finish, - newText = ('%s] = '):format(label), - }, - }) + if simple:get 'as action' then + local label = table.concat(chars) .. '+1' + callback(label, nil, CompletionItemKind.Snippet, { + textEdit = { + start = inside.start + 1, + finish = index.finish, + newText = ('%s] = '):format(label), + }, + }) + else + local label = table.concat(chars) + callback(label, nil, CompletionItemKind.Snippet, { + textEdit = { + start = inside.start + 1, + finish = index.finish, + newText = ('%s]'):format(label), + }, + }) + end end local function makeList(source, word) diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index 77f428ae..332f4a69 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -974,6 +974,7 @@ function mt:doAction(action) elseif tp == 'simple' then -- call self:getSimple(action) + action:set('as action', true) elseif tp == 'if' then self:doIf(action) elseif tp == 'loop' then @@ -990,6 +991,7 @@ function mt:doAction(action) self:doLocalFunction(action) else self:getExp(action) + action:set('as action', true) end end diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 962befa0..5d1ab35a 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -577,6 +577,16 @@ fff[#ff@] } TEST [[ +local _ = fff.kkk[#@] +]] +{ + { + label = 'fff.kkk', + kind = CompletionItemKind.Snippet, + }, +} + +TEST [[ local t = { a = 1, } |