summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-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
3 files changed, 45 insertions, 35 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