summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-11 18:37:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-11 18:37:09 +0800
commit8f5bc53c9fd5d289cf82e5dfb55a8e9912fb8e82 (patch)
tree1b6b994a344b0cf152fbcceb1aa9eb6e9fc34afa /server-beta
parentd0e4afaa8c498c2404516b6fdd41ec85719375a0 (diff)
downloadlua-language-server-8f5bc53c9fd5d289cf82e5dfb55a8e9912fb8e82.zip
更新引用实现
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/main.lua2
-rw-r--r--server-beta/src/core/reference.lua1
-rw-r--r--server-beta/src/parser/compile.lua5
-rw-r--r--server-beta/src/searcher/eachRef.lua69
-rw-r--r--server-beta/test.lua2
-rw-r--r--server-beta/test/references/init.lua3
6 files changed, 54 insertions, 28 deletions
diff --git a/server-beta/main.lua b/server-beta/main.lua
index 8edc0740..748227ac 100644
--- a/server-beta/main.lua
+++ b/server-beta/main.lua
@@ -5,7 +5,7 @@ local fs = require 'bee.filesystem'
ROOT = fs.path(rootPath)
LANG = LANG or 'en-US'
---collectgarbage 'generational'
+collectgarbage 'generational'
log = require 'log'
log.init(ROOT, ROOT / 'log' / 'service.log')
diff --git a/server-beta/src/core/reference.lua b/server-beta/src/core/reference.lua
index 96d1b635..092b6218 100644
--- a/server-beta/src/core/reference.lua
+++ b/server-beta/src/core/reference.lua
@@ -10,6 +10,7 @@ local function findDef(source, callback)
and source.type ~= 'setglobal'
and source.type ~= 'getglobal'
and source.type ~= 'field'
+ and source.type ~= 'tablefield'
and source.type ~= 'method'
and source.type ~= 'string'
and source.type ~= 'number'
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index 1a187e96..bf60e7ba 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -423,7 +423,10 @@ local function compileGoTo(obj)
}
return
end
- label.ref = obj
+ if not label.ref then
+ label.ref = {}
+ end
+ label.ref[#label.ref+1] = obj
-- 如果有局部变量在 goto 与 label 之间声明,
-- 并在 label 之后使用,则算作语法错误
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 7f43cbac..61aab081 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -271,19 +271,34 @@ end
local function ofField(source, callback)
local parent = source.parent
- local node = parent.node
local key = guide.getKeyName(source)
- searcher.eachField(node, function (info)
- if key == info.key then
- callback {
- source = info.source,
- mode = info.mode,
- }
- if info.value then
- ofValue(info.value, callback)
+ if parent.type == 'tablefield' then
+ local tbl = parent.parent
+ searcher.eachField(tbl, function (info)
+ if key == info.key then
+ callback {
+ source = info.source,
+ mode = info.mode,
+ }
+ if info.value then
+ ofValue(info.value, callback)
+ end
end
- end
- end)
+ end)
+ else
+ local node = parent.node
+ searcher.eachField(node, function (info)
+ if key == info.key then
+ callback {
+ source = info.source,
+ mode = info.mode,
+ }
+ if info.value then
+ ofValue(info.value, callback)
+ end
+ end
+ end)
+ end
end
local function ofLiteral(source, callback)
@@ -297,23 +312,26 @@ local function ofLiteral(source, callback)
end
end
+local function ofLabel(source, callback)
+ callback {
+ source = source,
+ mode = 'set',
+ }
+ if source.ref then
+ for _, ref in ipairs(source.ref) do
+ callback {
+ source = ref,
+ mode = 'get',
+ }
+ end
+ end
+end
+
local function ofGoTo(source, callback)
local name = source[1]
local label = guide.getLabel(source, name)
if label then
- callback {
- source = label,
- mode = 'set',
- }
- end
-end
-
-local function ofLabel(source, callback)
- if source.ref then
- callback {
- source = source.ref,
- mode = 'get',
- }
+ ofLabel(label, callback)
end
end
@@ -347,7 +365,8 @@ local function eachRef(source, callback)
or stype == 'index' then
ofField(source, callback)
elseif stype == 'setfield'
- or stype == 'getfield' then
+ or stype == 'getfield'
+ or stype == 'tablefield' then
ofField(source.field, callback)
elseif stype == 'setmethod'
or stype == 'getmethod' then
diff --git a/server-beta/test.lua b/server-beta/test.lua
index 3ebfca70..ad282687 100644
--- a/server-beta/test.lua
+++ b/server-beta/test.lua
@@ -38,7 +38,7 @@ local function main()
test 'definition'
test 'diagnostics'
- --test 'references'
+ test 'references'
--test 'highlight'
--test 'rename'
--test 'type_inference'
diff --git a/server-beta/test/references/init.lua b/server-beta/test/references/init.lua
index 6f0f74fc..e66449fb 100644
--- a/server-beta/test/references/init.lua
+++ b/server-beta/test/references/init.lua
@@ -65,6 +65,9 @@ t.<!a!> = t.<!a!>
TEST [[
:: <!LABEL!> ::
goto <?LABEL?>
+if true then
+ goto <!LABEL!>
+end
]]
TEST [[