summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-18 20:25:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-18 20:25:54 +0800
commit170d9b5c7af761a2507727e4a9e303187a0f9120 (patch)
tree7c0fa455feca384b890cc11461de8d6c6ff83be0 /script
parentd845f923cb32aa08706cef2bff5c2af0bd35fa9a (diff)
downloadlua-language-server-170d9b5c7af761a2507727e4a9e303187a0f9120.zip
deep search
Diffstat (limited to 'script')
-rw-r--r--script/core/definition.lua2
-rw-r--r--script/core/hover/init.lua1
-rw-r--r--script/core/searcher.lua38
-rw-r--r--script/vm/eachDef.lua4
4 files changed, 33 insertions, 12 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua
index 27a9e553..589e4d79 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -128,7 +128,7 @@ return function (uri, offset)
end
end
- local defs = vm.getDefs(source)
+ local defs = vm.getAllDefs(source)
local values = {}
for _, src in ipairs(defs) do
local value = searcher.getObjectValue(src)
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua
index 41616bc9..51dacada 100644
--- a/script/core/hover/init.lua
+++ b/script/core/hover/init.lua
@@ -155,6 +155,7 @@ local function getHoverByUri(uri, offset)
if not source then
return nil
end
+ vm.getAllDefs(source)
local hover = getHover(source)
if SHOWSOURCE then
hover.description = ('%s\n---\n\n```lua\n%s\n```'):format(
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index ffb54c07..2da811b0 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -27,7 +27,7 @@ local ignoredIDs = {
local m = {}
----@alias guide.searchmode '"ref"'|'"def"'|'"field"'|'"allref"'
+---@alias guide.searchmode '"ref"'|'"def"'|'"field"'|'"allref"'|'"alldef"'
---添加结果
---@param status guide.status
@@ -49,7 +49,7 @@ function m.pushResult(status, mode, source, force)
return
end
local parent = source.parent
- if mode == 'def' then
+ if mode == 'def' or mode == 'alldef' then
if source.type == 'local'
or source.type == 'setlocal'
or source.type == 'setglobal'
@@ -428,7 +428,7 @@ function m.searchRefsByID(status, uri, expect, mode)
return
end
noder.eachBackward(node, function (backwardID, tag)
- if tag == 'deep' and mode ~= 'allref' then
+ if tag == 'deep' and mode ~= 'allref' and mode ~= 'alldef' then
return
end
if not checkThenPushTag('backward', tag) then
@@ -496,7 +496,7 @@ function m.searchRefsByID(status, uri, expect, mode)
if isCall then
goto CONTINUE
end
- if not field and mode == 'def' then
+ if not field and (mode == 'def' or mode == 'alldef') then
goto CONTINUE
end
if files.eq(uri, guri) then
@@ -565,7 +565,7 @@ function m.searchRefsByID(status, uri, expect, mode)
checkENV(node.source, field)
end
- if mode == 'allref' then
+ if mode == 'allref' or mode == 'alldef' then
checkMainReturn(id, node, field)
end
@@ -598,18 +598,18 @@ function m.searchRefsByID(status, uri, expect, mode)
local stepCount = 0
local stepMaxCount = 1e3
local statusMaxCount = 1e4
- if mode == 'allref' then
+ if mode == 'allref' or mode == 'alldef' then
stepMaxCount = 1e4
statusMaxCount = 1e5
end
function searchStep(id, field)
stepCount = stepCount + 1
status.count = status.count + 1
- if mode == 'allref' then
- if status.count % 1e4 == 0 then
- await.delay()
- end
- end
+ --if mode == 'allref' or mode == 'alldef' then
+ -- if status.count % 1e4 == 0 then
+ -- await.delay()
+ -- end
+ --end
if stepCount > stepMaxCount
or status.count > statusMaxCount then
if TEST then
@@ -886,4 +886,20 @@ function m.requestDefinition(obj, field)
return status.results
end
+--- 请求对象的全部定义(深度搜索)
+---@param obj parser.guide.object
+---@param field? string
+---@return parser.guide.object[]
+function m.requestAllDefinition(obj, field)
+ local status = m.status('alldef')
+
+ if field then
+ m.searchFields(status, obj, 'alldef', field)
+ else
+ m.searchRefs(status, obj, 'alldef')
+ end
+
+ return status.results
+end
+
return m
diff --git a/script/vm/eachDef.lua b/script/vm/eachDef.lua
index 6f7af295..2bfad4bf 100644
--- a/script/vm/eachDef.lua
+++ b/script/vm/eachDef.lua
@@ -5,3 +5,7 @@ local searcher = require 'core.searcher'
function vm.getDefs(source, field)
return searcher.requestDefinition(source, field)
end
+
+function vm.getAllDefs(source, field)
+ return searcher.requestAllDefinition(source, field)
+end