summaryrefslogtreecommitdiff
path: root/server/src/core/definition.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/core/definition.lua')
-rw-r--r--server/src/core/definition.lua64
1 files changed, 43 insertions, 21 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)