summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-08-10 10:19:42 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-08-10 10:19:42 +0800
commitd7ab66b25db024f2cb375192f36d3c72313e0e34 (patch)
treee63320e3c127fdd438b7c708989ed5f84771406d /script
parentf616bd2baf6a03324d1d5d6df90607f770ea0a51 (diff)
downloadlua-language-server-d7ab66b25db024f2cb375192f36d3c72313e0e34.zip
cleanup
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua8
-rw-r--r--script/core/noder.lua10
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/vm/getDocs.lua28
-rw-r--r--script/vm/getGlobals.lua30
5 files changed, 55 insertions, 23 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index ad8dd466..63492689 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1600,7 +1600,7 @@ end
local function tryLuaDocBySource(ast, offset, source, results)
if source.type == 'doc.extends.name' then
if source.parent.type == 'doc.class' then
- for _, doc in ipairs(vm.getDocDefines()) do
+ for _, doc in ipairs(vm.getDocDefines '*') do
if doc.type == 'doc.class.name'
and doc.parent ~= source.parent
and matchKey(source[1], doc[1]) then
@@ -1618,7 +1618,7 @@ local function tryLuaDocBySource(ast, offset, source, results)
end
return true
elseif source.type == 'doc.type.name' then
- for _, doc in ipairs(vm.getDocDefines()) do
+ for _, doc in ipairs(vm.getDocDefines '*') do
if (doc.type == 'doc.class.name' or doc.type == 'doc.alias.name')
and doc.parent ~= source.parent
and matchKey(source[1], doc[1]) then
@@ -1692,7 +1692,7 @@ end
local function tryLuaDocByErr(ast, offset, err, docState, results)
if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then
- for _, doc in ipairs(vm.getDocDefines()) do
+ for _, doc in ipairs(vm.getDocDefines '*') do
if doc.type == 'doc.class.name'
and doc.parent ~= docState then
results[#results+1] = {
@@ -1702,7 +1702,7 @@ local function tryLuaDocByErr(ast, offset, err, docState, results)
end
end
elseif err.type == 'LUADOC_MISS_TYPE_NAME' then
- for _, doc in ipairs(vm.getDocDefines()) do
+ for _, doc in ipairs(vm.getDocDefines '*') do
if (doc.type == 'doc.class.name' or doc.type == 'doc.alias.name') then
results[#results+1] = {
label = doc[1],
diff --git a/script/core/noder.lua b/script/core/noder.lua
index c63dfeed..1cb49e5e 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -1024,11 +1024,9 @@ compileNodeMap = util.switch()
local defID = 'def:' .. id
collector.subscribe(uri, defID, noders)
- m.pushSource(noders, source, defID)
local defAnyID = 'def:dn:'
collector.subscribe(uri, defAnyID, noders)
- m.pushSource(noders, source, defAnyID)
end)
: case 'function'
: call(function (noders, id, source)
@@ -1217,12 +1215,10 @@ function m.compileNode(noders, source)
local defID = 'def:' .. id
collector.subscribe(uri, defID, noders)
- m.pushSource(noders, source, defID)
if guide.isGlobal(source) then
local defAnyID = 'def:g:'
collector.subscribe(uri, defAnyID, noders)
- m.pushSource(noders, source, defAnyID)
end
end
end
@@ -1362,6 +1358,12 @@ function m.getDocState(doc)
return getDocStateWithoutCrossFunction(doc)
end
+---@param noders noders
+---@return fun():node.id
+function m.eachID(noders)
+ return next, noders.source
+end
+
---获取对象的noders
---@param source parser.guide.object
---@return noders
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 71360b38..8fb94bca 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -836,6 +836,8 @@ local isSetMap = {
['tablefield'] = true,
['tableindex'] = true,
['tableexp'] = true,
+ ['doc.class.name'] = true,
+ ['doc.alias.name'] = true,
['doc.field.name'] = true,
['doc.field'] = true,
['doc.type.field'] = true,
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua
index ba4fb560..8ee942d1 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -12,18 +12,32 @@ local noder = require 'core.noder'
---@param name? string
---@return parser.guide.object[]
function vm.getDocDefines(name)
- name = name or ''
local cache = vm.getCache 'getDocDefines'
if cache[name] then
return cache[name]
end
local results = {}
- local id = 'def:dn:' .. name
- for noders in collector.each(id) do
- for source in noder.eachSource(noders, id) do
- if source.type == 'doc.class.name'
- or source.type == 'doc.alias.name' then
- results[#results+1] = source
+ if name == '*' then
+ for noders in collector.each('def:dn:') do
+ for id in noder.eachID(noders) do
+ if id:sub(1, 3) == 'dn:'
+ and not id:find(noder.SPLIT_CHAR) then
+ for source in noder.eachSource(noders, id) do
+ if guide.isSet(source) then
+ results[#results+1] = source
+ end
+ end
+ end
+ end
+ end
+ else
+ local id = 'dn:' .. name
+ for noders in collector.each('def:' .. id) do
+ for source in noder.eachSource(noders, id) do
+ if source.type == 'doc.class.name'
+ or source.type == 'doc.alias.name' then
+ results[#results+1] = source
+ end
end
end
end
diff --git a/script/vm/getGlobals.lua b/script/vm/getGlobals.lua
index 5d64cef6..d794a394 100644
--- a/script/vm/getGlobals.lua
+++ b/script/vm/getGlobals.lua
@@ -1,4 +1,5 @@
local collector = require 'core.collector'
+local guide = require 'parser.guide'
---@diagnostic disable-next-line
---@class vm
local vm = require 'vm.vm'
@@ -21,19 +22,32 @@ function vm.getGlobalSets(name)
end
local results = {}
cache[name] = results
- local id
if name == '*' then
- id = 'def:g:'
+ for noders in collector.each('def:g:') do
+ for id in noder.eachID(noders) do
+ if id:sub(1, 2) == 'g:'
+ and not id:find(noder.SPLIT_CHAR) then
+ for source in noder.eachSource(noders, id) do
+ if guide.isSet(source) then
+ results[#results+1] = source
+ end
+ end
+ end
+ end
+ end
else
+ local id
if type(name) == 'string' then
- id = ('def:g:%s%s'):format(noder.STRING_CHAR, name)
+ id = ('g:%s%s'):format(noder.STRING_CHAR, name)
else
- id = ('def:g:%s'):format(noder.STRING_CHAR, name)
+ id = ('g:%s'):format(noder.STRING_CHAR, name)
end
- end
- for noders in collector.each(id) do
- for source in noder.eachSource(noders, id) do
- results[#results+1] = source
+ for noders in collector.each('def:' .. id) do
+ for source in noder.eachSource(noders, id) do
+ if guide.isSet(source) then
+ results[#results+1] = source
+ end
+ end
end
end
return results