From 8f5725af96853b31afe6473b741e0b918b4a0210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 21 Dec 2018 18:27:37 +0800 Subject: =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=94=A8=E5=B8=B8=E9=87=8F=E5=81=9A?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=97=B6=E6=97=A0=E6=B3=95=E6=89=BE=E5=88=B0?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E5=87=BD=E6=95=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/completion.lua | 3 +++ server/src/matcher/vm.lua | 10 ++++++++-- server/src/method/textDocument/completion.lua | 2 +- server/test/completion/init.lua | 13 +++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index ce6fd277..5d651034 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -307,5 +307,8 @@ return function (vm, pos) searchAsSuffix(result, callback) end end + if #list == 0 then + return nil + end return list end diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index 6248e550..e7863e47 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -778,11 +778,17 @@ function mt:getSimple(simple, mode) local value = self:getExp(simple[1]) local field local parentName - if simple[1].type == 'name' then + local tp = simple[1].type + if tp == 'name' then field = self:getName(simple[1][1]) parentName = field.key + elseif tp == 'string' or tp == 'number' or tp == 'nil' or tp == 'boolean' then + local v = self:createValue(tp, simple[1], simple[1][1]) + field = self:createLocal('', simple[1], v) + parentName = '*' .. tp else - field = self:createValue('any', simple[1]) + local v = self:createValue('any', simple[1]) + field = self:createLocal('', simple[1], v) parentName = '?' end local object diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index d202f1a5..b866d18c 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -4,7 +4,7 @@ return function (lsp, params) local uri = params.textDocument.uri local vm, lines = lsp:loadVM(uri) if not vm then - return {} + return nil end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index df2b9c80..96a12032 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -67,8 +67,12 @@ function TEST(script) local vm = matcher.vm(ast) assert(vm) local result = matcher.completion(vm, pos) - assert(result) - assert(eq(expect, result)) + if expect then + assert(result) + assert(eq(expect, result)) + else + assert(result == nil) + end end end @@ -257,4 +261,9 @@ xxx() }, } +TEST [[ +(''):@ +]] +(EXISTS) + --TEST 'local s = "a:@"' (nil) TODO -- cgit v1.2.3