summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/definition.lua45
-rw-r--r--server/src/matcher/find_result.lua41
-rw-r--r--server/src/matcher/vm.lua14
-rw-r--r--server/test/definition/init.lua2
-rw-r--r--server/test/main.lua2
5 files changed, 39 insertions, 65 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua
index dbb24a47..3dc4f8ff 100644
--- a/server/src/matcher/definition.lua
+++ b/server/src/matcher/definition.lua
@@ -23,41 +23,28 @@ end
local function parseResult(result)
local positions = {}
local tp = result.type
- if tp == 'var' then
- local var = result.var
- if var.type == 'local' then
- for _, info in ipairs(var) do
- if info.type == 'local' then
- positions[#positions+1] = {info.source.start, info.source.finish}
- end
- end
- elseif var.type == 'field' then
- for _, info in ipairs(var) do
- if info.type == 'set' then
- positions[#positions+1] = {info.source.start, info.source.finish}
- end
- end
- local metavar = tryMeta(var)
- if metavar then
- for _, info in ipairs(metavar) do
- if info.type == 'set' then
- positions[#positions+1] = {info.source.start, info.source.finish}
- end
- end
+ if tp == 'local' then
+ for _, info in ipairs(result.object) do
+ if info.type == 'local' then
+ positions[#positions+1] = {info.source.start, info.source.finish}
end
- else
- error('unknow var.type:' .. var.type)
end
- elseif tp == 'dots' then
- local dots = result.dots
- for _, info in ipairs(dots) do
- if info.type == 'local' then
+ elseif tp == 'field' then
+ for _, info in ipairs(result.object) do
+ if info.type == 'set' then
positions[#positions+1] = {info.source.start, info.source.finish}
end
end
+ --local metavar = tryMeta(var)
+ --if metavar then
+ -- for _, info in ipairs(metavar) do
+ -- if info.type == 'set' then
+ -- positions[#positions+1] = {info.source.start, --info.source.finish}
+ -- end
+ -- end
+ --end
elseif tp == 'label' then
- local label = result.label
- for _, info in ipairs(label) do
+ for _, info in ipairs(result.object) do
if info.type == 'set' then
positions[#positions+1] = {info.source.start, info.source.finish}
end
diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua
index 0b06ccad..e8128008 100644
--- a/server/src/matcher/find_result.lua
+++ b/server/src/matcher/find_result.lua
@@ -2,39 +2,22 @@ local function isContainPos(obj, pos)
return obj.start <= pos and obj.finish + 1 >= pos
end
-return function (results, pos)
- for _, var in ipairs(results.vars) do
- for _, info in ipairs(var) do
- if isContainPos(info.source, pos) then
- return {
- type = 'var',
- var = var,
- info = info,
- }
- end
- end
- end
- for _, dots in ipairs(results.dots) do
- for _, info in ipairs(dots) do
- if isContainPos(info.source, pos) then
- return {
- type = 'dots',
- dots = dots,
- info = info,
- }
- end
- end
- end
- for _, label in ipairs(results.labels) do
- for _, info in ipairs(label) do
+local function findIn(name, group, pos)
+ for _, obj in ipairs(group) do
+ for _, info in ipairs(obj) do
if isContainPos(info.source, pos) then
return {
- type = 'label',
- label = label,
- info = info,
+ type = name,
+ object = obj,
+ info = info,
}
end
end
end
- return nil
+end
+
+return function (results, pos)
+ return findIn('local', results.locals, pos)
+ or findIn('field', results.fields, pos)
+ or findIn('label', results.labels, pos)
end
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index e5230015..38e64f5e 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -14,13 +14,17 @@ function mt:createLocal(key, source)
}
self.results.locals[#self.results.locals+1] = loc
self.scope.locals[key] = loc
+ self:addInfo(loc, 'local', source)
return loc
end
function mt:addInfo(obj, type, source)
+ if source and not source.start then
+ error('Miss start')
+ end
obj[#obj+1] = {
type = type,
- source = source,
+ source = source or DefaultSource,
}
return obj
end
@@ -155,7 +159,7 @@ function mt:createFunction(exp, object)
end
end)
if object then
- local var = self:createLocal('self', object)
+ local var = self:createLocal('self', object.source)
table.insert(func.args, 1, var)
end
@@ -592,7 +596,7 @@ function mt:doLoop(action)
local arg = self:createLocal(action.arg[1], action.arg)
self:setValue(arg, min)
- self:addInfo(arg, 'set', arg)
+ self:addInfo(arg, 'set', action.arg)
self:doActions(action)
@@ -656,7 +660,7 @@ function mt:doFunction(action)
end
local func = self:createFunction(action, object)
self:setValue(var, func)
- self:addInfo(var, 'set', action.name)
+ self:addInfo(var, 'set', var.source)
end
function mt:doLocalFunction(action)
@@ -664,7 +668,7 @@ function mt:doLocalFunction(action)
local var = self:createLocal(name[1], name)
local func = self:createFunction(action)
self:setValue(var, func)
- self:addInfo(var, 'set', action.name)
+ self:addInfo(var, 'set', name)
end
function mt:doAction(action)
diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua
index 11a79391..263a73cb 100644
--- a/server/test/definition/init.lua
+++ b/server/test/definition/init.lua
@@ -47,7 +47,7 @@ function TEST(script)
local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
local ast = parser:ast(new_script)
assert(ast)
- local results = matcher.compile(ast)
+ local results = matcher.vm(ast)
assert(results)
local result = matcher.definition(results, pos)
diff --git a/server/test/main.lua b/server/test/main.lua
index 80bfea76..c16346c9 100644
--- a/server/test/main.lua
+++ b/server/test/main.lua
@@ -23,11 +23,11 @@ local function main()
print(('测试[%s]用时[%.3f]'):format(name, os.clock() - clock))
end
+ test 'vm'
test 'compile'
--test 'type_inference'
test 'definition'
test 'find_lib'
- test 'vm'
print('测试完成')
end