From 0007a89a9c9bb153c2475b85b11664761264566f 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, 28 Dec 2018 11:31:13 +0800 Subject: =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E5=8C=96index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + server/src/matcher/vm.lua | 15 +++++++-------- server/src/parser/ast.lua | 10 +++++++--- server/src/parser/grammar.lua | 2 +- server/test/definition/table.lua | 8 ++++---- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5350a68a..cd02b855 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ - [ ] Multi Workspace - [ ] Type Format - [ ] Accurate Type Inference +- [ ] Document Symbols ### Locale diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index 3d3fc4e5..6bd7e7c3 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -995,23 +995,22 @@ function mt:getSimple(simple, mode) func = func, } parentName = parentName .. '(...)' - elseif obj.index then - local index = self:getIndex(obj) - field = self:getField(value, index, obj) + elseif tp == 'index' then + local child = obj[1] + local index = self:getIndex(child) + field = self:getField(value, index, child) field.parentValue = value value = self:getValue(field) if mode == 'value' or i < #simple then - if obj.start then - self:addInfo(field, 'get', obj) - end + self:addInfo(field, 'get', obj) end field.parent = lastField lastField = field obj.object = object obj.parentName = parentName - if obj.type == 'string' then + if obj[1].type == 'string' then parentName = ('%s[%q]'):format(parentName, index) - elseif obj.type == 'number' or obj.type == 'boolean' then + elseif obj[1].type == 'number' or obj[1].type == 'boolean' then parentName = ('%s[%s]'):format(parentName, index) else parentName = ('%s[?]'):format(parentName) diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 4521ffd5..8c4e1a1c 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -93,9 +93,13 @@ local defs = { return first end end, - Index = function (exp) - exp.index = true - return exp + Index = function (start, exp, finish) + return { + type = 'index', + start = start, + finish = finish - 1, + [1] = exp, + } end, Call = function (start, arg, finish) if arg == nil then diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index d21f07b9..ce7e4794 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -264,7 +264,7 @@ Suffix <- DOT MustName / COLON MustName / Sp ({} Table {}) -> Call / Sp ({} String {}) -> Call - / BL DirtyExp -> Index BR? + / Sp ({} BL DirtyExp (BR / Sp) {}) -> Index / Sp ({} PL ExpList (PR / Sp) {}) -> Call DirtyExp <- Exp / DirtyName diff --git a/server/test/definition/table.lua b/server/test/definition/table.lua index b4585d16..6376d7f2 100644 --- a/server/test/definition/table.lua +++ b/server/test/definition/table.lua @@ -35,25 +35,25 @@ t.() TEST [[ local t -t[] = 1 +t = 1 t[]() ]] TEST [[ local t -t[] = 1 +t = 1 t[]() ]] TEST [[ local t -t[] = 1 +t = 1 t[]() ]] TEST [[ local t -t[] = 1 +t = 1 t[]() ]] -- cgit v1.2.3