diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-07 13:38:46 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-07 13:38:46 +0800 |
commit | 5b1886a9cfa7c8dc1947bf7bb19e9fd3d04d604d (patch) | |
tree | 6e779e13ecd76caef500650161fad3e4b345df6a | |
parent | 0e663b24ca12cd47a9a3d308fb0732f7f4b4b2e8 (diff) | |
download | lua-language-server-5b1886a9cfa7c8dc1947bf7bb19e9fd3d04d604d.zip |
记录Simple中的点与冒号
-rw-r--r-- | server/src/core/completion.lua | 1 | ||||
-rw-r--r-- | server/src/core/vm.lua | 31 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 8 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 6 | ||||
-rw-r--r-- | server/test/completion/init.lua | 38 |
5 files changed, 65 insertions, 19 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 8fe3888e..34409bd5 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -334,6 +334,7 @@ local function findClosePos(vm, pos) type = 'name', start = pos, finish = pos, + object = parent.source.colon and parent, [1] = '', } local result = { diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua index 549fdc80..290125f1 100644 --- a/server/src/core/vm.lua +++ b/server/src/core/vm.lua @@ -1008,22 +1008,23 @@ function mt:getSimple(simple, mode) else parentName = ('%s[?]'):format(parentName) end - else - if tp == 'name' then - field = self:getField(value, obj[1], obj) - field.parentValue = value - value = self:getValue(field) - if mode == 'value' or i < #simple then - self:addInfo(field, 'get', obj) - end - field.parent = lastField - lastField = field - obj.object = object - obj.parentName = parentName - parentName = parentName .. '.' .. field.key - elseif tp == ':' then - object = field + elseif tp == 'name' then + field = self:getField(value, obj[1], obj) + field.parentValue = value + value = self:getValue(field) + if mode == 'value' or i < #simple then + self:addInfo(field, 'get', obj) end + field.parent = lastField + lastField = field + obj.object = object + obj.parentName = parentName + parentName = parentName .. '.' .. field.key + elseif tp == ':' then + object = field + field.source.colon = obj + elseif tp == '.' then + field.source.dot = obj end end if mode == 'value' then diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index e807c46a..cc4409f8 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -223,6 +223,13 @@ local defs = { finish = start, } end, + DOT = function (start) + return { + type = '.', + start = start, + finish = start, + } + end, Function = function (start, name, arg, ...) local obj = { type = 'function', @@ -695,7 +702,6 @@ local defs = { } return function (self, lua, mode) - Errs = {} local suc, res, err = pcall(self.grammar, lua, mode, defs) if not suc then diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 6dfbeed6..5308c6fb 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -183,7 +183,7 @@ TR <- Sp '}' COMMA <- Sp ',' SEMICOLON <- Sp ';' DOTS <- Sp ({} '...') -> DOTS -DOT <- Sp '.' !'.' +DOT <- Sp ({} '.' !'.') -> DOT COLON <- Sp ({} ':' !':') -> COLON LABEL <- Sp '::' ASSIGN <- Sp '=' @@ -285,8 +285,8 @@ Simple <- (Prefix (Suffix)*) -> Simple Prefix <- PL Exp PR / Name -Suffix <- DOT MustName - / COLON MustName +Suffix <- DOT Name? + / COLON Name? / Sp ({} Table {}) -> Call / Sp ({} String {}) -> Call / Sp ({} BL DirtyExp (BR / Sp) {}) -> Index diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index ee4e5f30..6c469534 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -442,3 +442,41 @@ fff[#ff@] kind = CompletionItemKind.Field, } } + +do return end + +TEST [[ +local t = { + a = 1, +} + +t . @ +]] +(EXISTS) + +TEST [[ +local t = { + a = 1, +} + +t . @ b +]] +(EXISTS) + +TEST [[ +local t = { + a = 1, +} + +t @ +]] +(nil) + +TEST [[ +local t = { + a = 1, +} + +t @. +]] +(nil) |