diff options
-rw-r--r-- | server/src/matcher/completion.lua | 48 | ||||
-rw-r--r-- | server/src/matcher/find_result.lua | 12 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 11 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 4 | ||||
-rw-r--r-- | server/test/completion/init.lua | 4 |
5 files changed, 41 insertions, 38 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index d0480cc4..1b07e5fb 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -313,26 +313,26 @@ local function findClosePos(vm, pos) found(object, sources) end end - if parent and parent.type ~= 'local' and parent.type ~= 'field' then - parent = nil - end - if parent then - -- 造个假的 DirtyName - local source = { - type = 'name', - start = pos, - finish = pos, - [1] = '', - } - local result = { - type = 'field', - parent = parent, - key = '', - source = source, - } - return result, source + if not parent then + return nil end - return nil + if parent.type ~= 'local' and parent.type ~= 'field' then + return nil + end + -- 造个假的 DirtyName + local source = { + type = 'name', + start = pos, + finish = pos, + [1] = '', + } + local result = { + type = 'field', + parent = parent, + key = '', + source = source, + } + return result, source end local function isContainPos(obj, pos) @@ -443,20 +443,22 @@ end return function (vm, pos) local result, source = findResult(vm, pos) - local closeResult, closeSource = findClosePos(vm, pos) + if not result then + result, source = findClosePos(vm, pos) + end - if not result and not closeResult then + if not result then return nil end - local list, callback = makeList(source or closeSource) + local list, callback = makeList(source) local inCall = findCall(vm, pos) local inString = findString(vm, pos) if inCall then searchInArg(vm, inCall, inString, callback) end if not inString then - searchInResult(result or closeResult, source or closeSource, vm, pos, callback) + searchInResult(result, source, vm, pos, callback) end if #list == 0 then return nil diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua index 940ef80c..ac8dc3f4 100644 --- a/server/src/matcher/find_result.lua +++ b/server/src/matcher/find_result.lua @@ -5,7 +5,7 @@ local function isContainPos(obj, pos) return false end -local function findAtPos(results, pos) +local function findAtPos(results, pos, level) local res = {} for sources, object in pairs(results.sources) do if sources.type == 'multi-source' then @@ -35,9 +35,13 @@ local function findAtPos(results, pos) table.sort(res, function (a, b) return a.range < b.range end) - return res[1].object, res[1].source + local data = res[level or 1] + if not data then + return nil + end + return data.object, data.source end -return function (vm, pos) - return findAtPos(vm.results, pos) +return function (vm, pos, level) + return findAtPos(vm.results, pos, level) end diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index b02daefa..4521ffd5 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -141,18 +141,15 @@ local defs = { return e1 end, Unary = function (...) - local e1, op = ... - if not op then - return e1 - end local args = {...} local e1 = args[#args] - for i = #args - 1, 1, -1 do - op = args[i] + for i = #args - 1, 1, -2 do + local start = args[i-1] + local op = args[i] e1 = { type = 'unary', op = op, - start = e1.start, + start = start, finish = e1.finish, [1] = e1, } diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 4a483514..a125bfe4 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -120,7 +120,7 @@ IF <- Sp 'if' Cut IN <- Sp 'in' Cut LOCAL <- Sp 'local' Cut NIL <- Sp 'nil' Cut -NOT <- Sp 'not' Cut +NOT <- Sp 'not' Cut OR <- Sp {'or'} Cut REPEAT <- Sp 'repeat' Cut RETURN <- Sp 'return' Cut @@ -169,7 +169,7 @@ MulsList <- '*' / '//' / '/' / '%' -Unary <- Sp {UnaryList} +Unary <- Sp {} {UnaryList} UnaryList <- NOT / '#' / '-' diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 98c91acf..3ad3f9c2 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -410,11 +410,11 @@ end (nil) TEST [[ -list[#@] +self.results.list[#@] ]] { { - label = 'list+1', + label = 'self.results.list+1', kind = CompletionItemKind.Snippet, } } |