summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/definition.lua64
-rw-r--r--server/src/method/textDocument/definition.lua14
-rw-r--r--server/src/method/textDocument/references.lua2
-rw-r--r--server/test/crossfile/definition.lua3
-rw-r--r--server/test/crossfile/references.lua2
-rw-r--r--server/test/definition/init.lua3
-rw-r--r--server/test/references/init.lua2
7 files changed, 49 insertions, 41 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 7d97bdee..a9b9469d 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -1,4 +1,7 @@
-local function parseValueSimily(callback, vm, source, lsp)
+local findSource = require 'core.find_source'
+local Mode
+
+local function parseValueSimily(callback, vm, source)
local key = source[1]
if not key then
return nil
@@ -19,7 +22,7 @@ local function parseValueSimily(callback, vm, source, lsp)
end)
end
-local function parseLocal(callback, vm, source, lsp)
+local function parseLocal(callback, vm, source)
local loc = source:bindLocal()
local locSource = loc:getSource()
callback(locSource)
@@ -28,18 +31,22 @@ end
local function parseValueByValue(callback, vm, source, value, isGlobal)
value:eachInfo(function (info, src)
if info.type == 'set' or info.type == 'local' or info.type == 'return' then
- if vm.uri == src:getUri() then
- if isGlobal or source.id > src.id then
+ if Mode == 'definition' then
+ if vm.uri == src:getUri() then
+ if isGlobal or source.id > src.id then
+ callback(src)
+ end
+ elseif value.uri == src:getUri() then
callback(src)
end
- elseif value.uri == src:getUri() then
+ elseif Mode == 'reference' then
callback(src)
end
end
end)
end
-local function parseValue(callback, vm, source, lsp)
+local function parseValue(callback, vm, source)
local value = source:bindValue()
local isGlobal
if value then
@@ -57,9 +64,16 @@ local function parseValue(callback, vm, source, lsp)
for _ = 1, 3 do
if parent then
local ok = parent:eachInfo(function (info, src)
- if info.type == 'set child' and info[1] == source[1] then
- callback(src)
- return true
+ if Mode == 'definition' then
+ if info.type == 'set child' and info[1] == source[1] then
+ callback(src)
+ return true
+ end
+ elseif Mode == 'reference' then
+ if (info.type == 'set child' or info.type == 'get child') and info[1] == source[1] then
+ callback(src)
+ return true
+ end
end
end)
if ok then
@@ -71,15 +85,21 @@ local function parseValue(callback, vm, source, lsp)
return isGlobal
end
-local function parseLabel(callback, vm, label, lsp)
+local function parseLabel(callback, vm, label)
label:eachInfo(function (info, src)
- if info.type == 'set' then
- callback(src)
+ if Mode == 'definition' then
+ if info.type == 'set' then
+ callback(src)
+ end
+ elseif Mode == 'reference' then
+ if info.type == 'set' or info.type == 'get' then
+ callback(src)
+ end
end
end)
end
-local function jumpUri(callback, vm, source, lsp)
+local function jumpUri(callback, vm, source)
local uri = source:get 'target uri'
callback {
start = 0,
@@ -121,28 +141,30 @@ local function makeList(source)
end
end
-return function (vm, source, lsp)
+return function (vm, pos, mode)
+ local source = findSource(vm, pos)
if not source then
return nil
end
+ Mode = mode
local list, callback = makeList(source)
local isGlobal
if source:bindLocal() then
- parseLocal(callback, vm, source, lsp)
+ parseLocal(callback, vm, source)
end
if source:bindValue() then
- isGlobal = parseValue(callback, vm, source, lsp)
- --parseValueSimily(callback, vm, source, lsp)
+ isGlobal = parseValue(callback, vm, source)
+ --parseValueSimily(callback, vm, source)
end
if source:bindLabel() then
- parseLabel(callback, vm, source:bindLabel(), lsp)
+ parseLabel(callback, vm, source:bindLabel())
end
if source:get 'target uri' then
- jumpUri(callback, vm, source, lsp)
+ jumpUri(callback, vm, source)
end
if source:get 'in index' then
- isGlobal = parseValue(callback, vm, source, lsp)
- --parseValueSimily(callback, vm, source, lsp)
+ isGlobal = parseValue(callback, vm, source)
+ --parseValueSimily(callback, vm, source)
end
if source:get 'target class' then
parseClass(callback, vm, source)
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua
index 50076c1c..d33fd739 100644
--- a/server/src/method/textDocument/definition.lua
+++ b/server/src/method/textDocument/definition.lua
@@ -1,15 +1,5 @@
local core = require 'core'
-local function checkWorkSpaceComplete(lsp, source)
- if not source:bindValue() then
- return
- end
- if not source:bindValue():get 'cross file' then
- return
- end
- lsp:checkWorkSpaceComplete()
-end
-
local function findResult(lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
@@ -24,9 +14,7 @@ local function findResult(lsp, params)
return nil
end
- checkWorkSpaceComplete(lsp, source)
-
- local positions, isGlobal = core.definition(vm, source, lsp)
+ local positions, isGlobal = core.definition(vm, position, 'definition', lsp)
if not positions then
return nil, isGlobal
end
diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua
index 397b1491..4a876121 100644
--- a/server/src/method/textDocument/references.lua
+++ b/server/src/method/textDocument/references.lua
@@ -4,7 +4,7 @@ local LastTask
local function findReferences(lsp, uri, position, declarat)
local vm = lsp:getVM(uri)
- local positions, isGlobal = core.references(vm, position, declarat)
+ local positions, isGlobal = core.references(vm, position, 'reference')
if not positions then
return nil
end
diff --git a/server/test/crossfile/definition.lua b/server/test/crossfile/definition.lua
index 4e3a00ef..f49530ea 100644
--- a/server/test/crossfile/definition.lua
+++ b/server/test/crossfile/definition.lua
@@ -89,8 +89,7 @@ function TEST(datas)
local sourceVM = lsp:getVM(sourceUri)
assert(sourceVM)
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
- local source = core.findSource(sourceVM, sourcePos)
- local positions = core.definition(sourceVM, source, lsp)
+ local positions = core.definition(sourceVM, sourcePos, 'definition', lsp)
if positions then
assert(founded(targetList, positions))
else
diff --git a/server/test/crossfile/references.lua b/server/test/crossfile/references.lua
index 5f29eb25..07bdf185 100644
--- a/server/test/crossfile/references.lua
+++ b/server/test/crossfile/references.lua
@@ -109,7 +109,7 @@ function TEST(data)
compileAll(lsp)
assert(vm)
- local result = core.references(vm, pos, true)
+ local result = core.references(vm, pos, 'reference')
if expect then
assert(result)
assert(founded(expect, result))
diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua
index d699744a..cad120f7 100644
--- a/server/test/definition/init.lua
+++ b/server/test/definition/init.lua
@@ -45,8 +45,7 @@ function TEST(script)
local vm = buildVM(ast)
assert(vm)
- local source = core.findSource(vm, pos)
- local positions = core.definition(vm, source, nil)
+ local positions = core.definition(vm, pos, 'definition', nil)
if positions then
assert(founded(target, positions))
else
diff --git a/server/test/references/init.lua b/server/test/references/init.lua
index ad84eb80..782007f3 100644
--- a/server/test/references/init.lua
+++ b/server/test/references/init.lua
@@ -43,7 +43,7 @@ function TEST(script)
local vm = buildVM(ast)
assert(vm)
- local positions = core.references(vm, pos, true)
+ local positions = core.references(vm, pos, 'reference')
if positions then
assert(founded(target, positions))
else