summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-28 11:31:13 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-28 11:31:13 +0800
commit0007a89a9c9bb153c2475b85b11664761264566f (patch)
tree10f4eec41c202d446fc7663b636a3f2dab3ae06c
parent8d63f26209a4e241bb30551d81ceb4ca246b228a (diff)
downloadlua-language-server-0007a89a9c9bb153c2475b85b11664761264566f.zip
实例化index
-rw-r--r--README.md1
-rw-r--r--server/src/matcher/vm.lua15
-rw-r--r--server/src/parser/ast.lua10
-rw-r--r--server/src/parser/grammar.lua2
-rw-r--r--server/test/definition/table.lua8
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.<?x?>()
TEST [[
local t
-t[<!1!>] = 1
+t<![1]!> = 1
t[<?1?>]()
]]
TEST [[
local t
-t[<!true!>] = 1
+t<![true]!> = 1
t[<?true?>]()
]]
TEST [[
local t
-t[<!"method"!>] = 1
+t<!["method"]!> = 1
t[<?"method"?>]()
]]
TEST [[
local t
-t[<!"longString"!>] = 1
+t<!["longString"]!> = 1
t[<?[==[longString]==]?>]()
]]