summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/files.lua9
-rw-r--r--server-beta/src/parser/guide.lua22
-rw-r--r--server-beta/src/proto/provider.lua5
-rw-r--r--server-beta/src/searcher/eachRef.lua26
4 files changed, 37 insertions, 25 deletions
diff --git a/server-beta/src/files.lua b/server-beta/src/files.lua
index 1a1cf347..6c0d8dae 100644
--- a/server-beta/src/files.lua
+++ b/server-beta/src/files.lua
@@ -31,6 +31,15 @@ function m.close(uri)
m.openMap[uri] = nil
end
+--- 是否存在
+---@return boolean
+function m.exists(uri)
+ if platform.OS == 'Windows' then
+ uri = uri:lower()
+ end
+ return m.fileMap[uri] ~= nil
+end
+
--- 设置文件文本
---@param uri string
---@param text string
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index a561e49c..f8330438 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -247,28 +247,6 @@ function m.getLabel(block, name)
error('guide.getLocal overstack')
end
---- 获取指定区块中的 return
-function m.getReturns(block)
- local list = { block }
- local returns = {}
- for i = 1, 1000 do
- local len = #list
- if len == 0 then
- return
- end
- local obj = list[len]
- list[len] = nil
- if obj.type == 'return' then
- returns[#returns+1] = obj
- end
- if i > 1 and obj.type == 'function' then
- else
- m.addChilds(list, obj, m.actionMap)
- end
- end
- return returns
-end
-
--- 判断source是否包含offset
function m.isContain(source, offset)
return source.start <= offset and source.finish >= offset - 1
diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua
index 9ad5147a..a27066aa 100644
--- a/server-beta/src/proto/provider.lua
+++ b/server-beta/src/proto/provider.lua
@@ -150,14 +150,13 @@ end)
proto.on('textDocument/definition', function (params)
local core = require 'core.definition'
local uri = params.textDocument.uri
- local ast = files.getAst(uri)
- if not ast then
+ if not files.exists(uri) then
return nil
end
local lines = files.getLines(uri)
local text = files.getText(uri)
local offset = inte.offset(lines, text, params.position)
- local result = core(ast, offset)
+ local result = core(uri, offset)
if not result then
return nil
end
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 65fd3529..93a05079 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -1,5 +1,25 @@
local guide = require 'parser.guide'
+local function ofCall(searcher, func, index, callback)
+ searcher:eachRef(func, function (info)
+ local src = info.source
+ local funcDef = src.value
+ if funcDef and funcDef.type == 'function' then
+ -- 搜索函数第 index 个返回值
+ end
+ end)
+end
+
+local function ofValue(searcher, value, callback)
+ -- 检查函数返回值
+ if value.type == 'select' then
+ local call = value.vararg
+ if call.type == 'call' then
+ ofCall(searcher, call.node, value.index, callback)
+ end
+ end
+end
+
local function ofSelf(searcher, loc, callback)
-- self 的2个特殊引用位置:
-- 1. 当前方法定义时的对象(mt)
@@ -32,12 +52,18 @@ local function ofLocal(searcher, loc, callback)
source = ref,
mode = 'set',
}
+ if ref.value then
+ ofValue(searcher, ref.value, callback)
+ end
end
end
end
if loc.tag == 'self' then
ofSelf(searcher, loc, callback)
end
+ if loc.value then
+ ofValue(searcher, loc.value, callback)
+ end
end
local function checkField(key, info, callback)