summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/definition.lua23
-rw-r--r--server-beta/src/core/engineer.lua3
-rw-r--r--server-beta/test/crossfile/definition.lua4
-rw-r--r--server-beta/test/definition/init.lua9
4 files changed, 21 insertions, 18 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index 2fe726e0..039effd5 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -1,22 +1,23 @@
local guide = require 'parser.guide'
local engineer = require 'core.engineer'
local workspace = require 'workspace'
+local files = require 'files'
local function findDef(searcher, source, callback)
- searcher:eachDef(source, function (src)
+ searcher:eachDef(source, function (src, uri)
if src.type == 'setfield'
or src.type == 'getfield'
or src.type == 'tablefield' then
- callback(src.field)
+ callback(src.field, uri)
elseif src.type == 'setindex'
or src.type == 'getindex'
or src.type == 'tableindex' then
- callback(src.index)
+ callback(src.index, uri)
elseif src.type == 'getmethod'
or src.type == 'setmethod' then
- callback(src.method)
+ callback(src.method, uri)
else
- callback(src)
+ callback(src, uri)
end
end)
end
@@ -53,9 +54,13 @@ local function checkRequire(searcher, source, offset, callback)
end
end
-return function (ast, offset)
+return function (uri, offset)
local results = {}
- local searcher = engineer(ast)
+ local ast = files.getAst(uri)
+ if not ast then
+ return nil
+ end
+ local searcher = engineer(ast, uri)
guide.eachSourceContain(ast.ast, offset, function (source)
checkRequire(searcher, source, offset, function (uri)
results[#results+1] = {
@@ -67,9 +72,9 @@ return function (ast, offset)
}
}
end)
- findDef(searcher, source, function (src)
+ findDef(searcher, source, function (src, uri)
results[#results+1] = {
- uri = ast.uri,
+ uri = uri,
source = source,
target = src,
}
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua
index a52bddc2..8404bee5 100644
--- a/server-beta/src/core/engineer.lua
+++ b/server-beta/src/core/engineer.lua
@@ -313,10 +313,11 @@ function mt:childMode(source)
return nil, nil
end
-return function (ast)
+return function (ast, uri)
local self = setmetatable({
step = 0,
ast = ast.ast,
+ uri = uri,
cache = {
def = {},
ref = {},
diff --git a/server-beta/test/crossfile/definition.lua b/server-beta/test/crossfile/definition.lua
index 74e0333c..cf54f30e 100644
--- a/server-beta/test/crossfile/definition.lua
+++ b/server-beta/test/crossfile/definition.lua
@@ -76,10 +76,8 @@ function TEST(datas)
files.setText(uri, data.content)
end
- local sourceAst = files.getAst(sourceUri)
- assert(sourceAst)
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
- local positions = core(sourceAst, sourcePos)
+ local positions = core(sourceUri, sourcePos)
if positions then
local result = {}
for i, position in ipairs(positions) do
diff --git a/server-beta/test/definition/init.lua b/server-beta/test/definition/init.lua
index f2c68f14..4e2d9de5 100644
--- a/server-beta/test/definition/init.lua
+++ b/server-beta/test/definition/init.lua
@@ -1,6 +1,5 @@
local core = require 'core.definition'
-local engineer = require 'core.engineer'
-local parser = require 'parser'
+local files = require 'files'
rawset(_G, 'TEST', true)
@@ -35,15 +34,15 @@ local function founded(targets, results)
end
function TEST(script)
+ files.removeAll()
local target = catch_target(script)
local start = script:find('<?', 1, true)
local finish = script:find('?>', 1, true)
local pos = (start + finish) // 2 + 1
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
- local ast = parser:compile(new_script, 'lua', 'Lua 5.3')
- assert(ast)
+ files.setText('', new_script)
- local results = core(ast, pos)
+ local results = core('', pos)
if results then
local positions = {}
for i, result in ipairs(results) do