summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-08 18:45:24 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-08 18:45:24 +0800
commitd4e35887aba9ed3794d5694a19b976eed5a68269 (patch)
tree702398520c060615da7bfdf5c1075014d1763262
parent9bcc9d55cd511c8e27930e6b1629a4b63bfa79c5 (diff)
downloadlua-language-server-d4e35887aba9ed3794d5694a19b976eed5a68269.zip
cleanup
-rw-r--r--.vscode/settings.json2
-rw-r--r--script/cli/doc.lua2
-rw-r--r--script/core/workspace-symbol.lua2
-rw-r--r--script/vm/compiler.lua86
-rw-r--r--script/vm/field.lua2
-rw-r--r--script/vm/global.lua5
-rw-r--r--script/vm/ref.lua1
-rw-r--r--script/vm/sign.lua2
-rw-r--r--test/completion/common.lua2
9 files changed, 40 insertions, 64 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 3c3813a7..74e81788 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,7 +1,7 @@
// Just some comment
{
"Lua.misc.parameters": [
- "--preview",
+ //"--preview",
"--develop=true",
"--dbgport=11413",
"--loglevel=trace",
diff --git a/script/cli/doc.lua b/script/cli/doc.lua
index 7ba40c78..e4448927 100644
--- a/script/cli/doc.lua
+++ b/script/cli/doc.lua
@@ -149,7 +149,7 @@ local function collect(global)
results[#results+1] = result
---@async
---@diagnostic disable-next-line: not-yieldable
- vm.getClassFields(rootUri, global, nil, false, function (source)
+ vm.getClassFields(rootUri, global, nil, function (source)
if source.type == 'doc.field' then
---@cast source parser.object
if files.isLibrary(guide.getUri(source)) then
diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua
index 8ac22b20..f7becf93 100644
--- a/script/core/workspace-symbol.lua
+++ b/script/core/workspace-symbol.lua
@@ -116,7 +116,7 @@ local function searchClassField(key, suri, results)
return
end
suri = suri or guide.getUri(set)
- vm.getClassFields(suri, global, nil, false, function (field, isMark)
+ vm.getClassFields(suri, global, nil, function (field, isMark)
if field.type == 'generic' then
return
end
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index aa5ffb6e..168ad536 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -62,21 +62,11 @@ end
---@param source parser.object
---@param key any
----@param ref boolean
---@param pushResult fun(res: parser.object, markDoc?: boolean)
-local function searchFieldByLocalID(source, key, ref, pushResult)
+local function searchFieldByLocalID(source, key, pushResult)
local fields
if key then
fields = vm.getLocalSourcesSets(source, key)
- if ref then
- local gets = vm.getLocalSourcesGets(source, key)
- if gets then
- fields = fields or {}
- for _, src in ipairs(gets) do
- fields[#fields+1] = src
- end
- end
- end
else
fields = vm.getLocalFields(source, false)
end
@@ -106,9 +96,8 @@ end
---@param suri uri
---@param source parser.object
---@param key any
----@param ref boolean
---@param pushResult fun(res: parser.object, markDoc?: boolean)
-local function searchFieldByGlobalID(suri, source, key, ref, pushResult)
+local function searchFieldByGlobalID(suri, source, key, pushResult)
local node = vm.getGlobalNode(source)
if not node then
return
@@ -123,9 +112,6 @@ local function searchFieldByGlobalID(suri, source, key, ref, pushResult)
for _, set in ipairs(global:getSets(suri)) do
pushResult(set)
end
- for _, get in ipairs(global:getGets(suri)) do
- pushResult(get)
- end
end
else
local globals = vm.getGlobalFields('variable', node.name)
@@ -133,20 +119,17 @@ local function searchFieldByGlobalID(suri, source, key, ref, pushResult)
for _, set in ipairs(global:getSets(suri)) do
pushResult(set)
end
- for _, get in ipairs(global:getGets(suri)) do
- pushResult(get)
- end
end
end
end
if node.cate == 'type' then
- vm.getClassFields(suri, node, key, ref, pushResult)
+ vm.getClassFields(suri, node, key, pushResult)
end
end
local searchFieldSwitch = util.switch()
: case 'table'
- : call(function (suri, source, key, ref, pushResult)
+ : call(function (suri, source, key, pushResult)
local hasFiled = false
for _, field in ipairs(source) do
if field.type == 'tablefield'
@@ -181,15 +164,15 @@ local searchFieldSwitch = util.switch()
end)
: case 'string'
: case 'doc.type.string'
- : call(function (suri, source, key, ref, pushResult)
+ : call(function (suri, source, key, pushResult)
-- change to `string: stringlib` ?
local stringlib = vm.getGlobal('type', 'stringlib')
if stringlib then
- vm.getClassFields(suri, stringlib, key, ref, pushResult)
+ vm.getClassFields(suri, stringlib, key, pushResult)
end
end)
: case 'doc.type.array'
- : call(function (suri, source, key, ref, pushResult)
+ : call(function (suri, source, key, pushResult)
if type(key) == 'number' then
if key < 1
or not math.tointeger(key) then
@@ -204,7 +187,7 @@ local searchFieldSwitch = util.switch()
end
end)
: case 'doc.type.table'
- : call(function (suri, source, key, ref, pushResult)
+ : call(function (suri, source, key, pushResult)
if type(key) == 'string' and key:find(vm.ID_SPLITE) then
return
end
@@ -240,7 +223,7 @@ local searchFieldSwitch = util.switch()
end
end)
: case 'global'
- : call(function (suri, node, key, ref, pushResult)
+ : call(function (suri, node, key, pushResult)
if node.cate == 'variable' then
if key then
if type(key) ~= 'string' then
@@ -251,11 +234,6 @@ local searchFieldSwitch = util.switch()
for _, set in ipairs(global:getSets(suri)) do
pushResult(set)
end
- if ref then
- for _, get in ipairs(global:getGets(suri)) do
- pushResult(get)
- end
- end
end
else
local globals = vm.getGlobalFields('variable', node.name)
@@ -263,29 +241,23 @@ local searchFieldSwitch = util.switch()
for _, set in ipairs(global:getSets(suri)) do
pushResult(set)
end
- if ref then
- for _, get in ipairs(global:getGets(suri)) do
- pushResult(get)
- end
- end
end
end
end
if node.cate == 'type' then
- vm.getClassFields(suri, node, key, ref, pushResult)
+ vm.getClassFields(suri, node, key, pushResult)
end
end)
- : default(function (suri, source, key, ref, pushResult)
- searchFieldByLocalID(source, key, ref, pushResult)
- searchFieldByGlobalID(suri, source, key, ref, pushResult)
+ : default(function (suri, source, key, pushResult)
+ searchFieldByLocalID(source, key, pushResult)
+ searchFieldByGlobalID(suri, source, key, pushResult)
end)
---@param suri uri
---@param object vm.global
---@param key? string|number|integer|boolean|vm.global
----@param ref boolean
---@param pushResult fun(field: vm.object, isMark?: boolean)
-function vm.getClassFields(suri, object, key, ref, pushResult)
+function vm.getClassFields(suri, object, key, pushResult)
local mark = {}
local function searchClass(class, searchedFields)
@@ -375,7 +347,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
if not searchedFields[key] and set.bindSource then
local src = set.bindSource
if src.value and src.value.type == 'table' then
- searchFieldSwitch('table', suri, src.value, key, ref, function (field)
+ searchFieldSwitch('table', suri, src.value, key, function (field)
local fieldKey = guide.getKeyName(field)
if fieldKey then
if not searchedFields[fieldKey]
@@ -395,7 +367,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
and args
and args[1]
and args[1].type == 'table' then
- searchFieldSwitch('table', suri, args[1], key, ref, function (field)
+ searchFieldSwitch('table', suri, args[1], key, function (field)
local fieldKey = guide.getKeyName(field)
if fieldKey then
if not searchedFields[fieldKey]
@@ -416,7 +388,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
if set.type == 'doc.class' then
if not searchedFields[key] and set.bindSource then
local src = set.bindSource
- searchFieldSwitch(src.type, suri, src, key, ref, function (field)
+ searchFieldSwitch(src.type, suri, src, key, function (field)
local fieldKey = guide.getKeyName(field)
if fieldKey and not searchedFields[fieldKey] then
if not searchedFields[fieldKey]
@@ -524,7 +496,7 @@ local function getReturnOfSetMetaTable(args)
node:merge(vm.compileNode(tbl))
end
if mt then
- vm.compileByParentNode(mt, '__index', false, function (src)
+ vm.compileByParentNode(mt, '__index', function (src)
for n in vm.compileNode(src):eachObject() do
if n.type == 'global'
or n.type == 'local'
@@ -652,7 +624,7 @@ end
---@param source parser.object
---@param key? string|vm.global
---@param pushResult fun(source: parser.object)
-function vm.compileByParentNode(source, key, ref, pushResult)
+function vm.compileByParentNode(source, key, pushResult)
local parentNode = vm.compileNode(source)
local docedResults = {}
local commonResults = {}
@@ -677,7 +649,7 @@ function vm.compileByParentNode(source, key, ref, pushResult)
and not guide.isBasicType(node.name)
)
or guide.isLiteral(node) then
- searchFieldSwitch(node.type, suri, node, key, ref, function (res, markDoc)
+ searchFieldSwitch(node.type, suri, node, key, function (res, markDoc)
if mark[res] then
return
end
@@ -692,7 +664,7 @@ function vm.compileByParentNode(source, key, ref, pushResult)
end
if not next(mark) then
- searchFieldByLocalID(source, key, ref, function (res, markDoc)
+ searchFieldByLocalID(source, key, function (res, markDoc)
if mark[res] then
return
end
@@ -1298,7 +1270,7 @@ local compilerSwitch = util.switch()
for k in key:eachObject() do
if k.type == 'global' and k.cate == 'type' then
---@cast k vm.global
- vm.compileByParentNode(source.node, k, false, function (src)
+ vm.compileByParentNode(source.node, k, function (src)
vm.setNode(source, vm.compileNode(src))
if src.value then
vm.setNode(source, vm.compileNode(src.value))
@@ -1308,7 +1280,7 @@ local compilerSwitch = util.switch()
end
else
---@cast key string
- vm.compileByParentNode(source.node, key, false, function (src)
+ vm.compileByParentNode(source.node, key, function (src)
if src.value then
if bindDocs(src) then
vm.setNode(source, vm.compileNode(src))
@@ -1331,7 +1303,7 @@ local compilerSwitch = util.switch()
return
end
local key = guide.getKeyName(source)
- vm.compileByParentNode(source.node, key, false, function (src)
+ vm.compileByParentNode(source.node, key, function (src)
if src.type == 'doc.type.field'
or src.type == 'doc.field' then
vm.setNode(source, vm.compileNode(src))
@@ -1347,7 +1319,7 @@ local compilerSwitch = util.switch()
return
end
local key = guide.getKeyName(source)
- vm.compileByParentNode(source.node, key, false, function (src)
+ vm.compileByParentNode(source.node, key, function (src)
vm.setNode(source, vm.compileNode(src))
end)
end)
@@ -1360,7 +1332,7 @@ local compilerSwitch = util.switch()
end
if not hasMarkDoc then
- vm.compileByParentNode(source.node, guide.getKeyName(source), false, function (src)
+ vm.compileByParentNode(source.node, guide.getKeyName(source), function (src)
if src.type == 'doc.field'
or src.type == 'doc.type.field'
or src.type == 'doc.type.name' then
@@ -1383,7 +1355,7 @@ local compilerSwitch = util.switch()
: case 'tableexp'
: call(function (source)
local hasMarkDoc
- vm.compileByParentNode(source.parent, source.tindex, false, function (src)
+ vm.compileByParentNode(source.parent, source.tindex, function (src)
if src.type == 'doc.field'
or src.type == 'doc.type.field'
or src.type == 'doc.type.name'
@@ -1894,7 +1866,7 @@ local nodeSwitch;nodeSwitch = util.switch()
key = key .. vm.ID_SPLITE .. lastKey
end
for pn in parentNode:eachObject() do
- searchFieldSwitch(pn.type, uri, pn, key, false, pushResult)
+ searchFieldSwitch(pn.type, uri, pn, key, pushResult)
end
return key, source.node
end)
@@ -1911,7 +1883,7 @@ local nodeSwitch;nodeSwitch = util.switch()
local uri = guide.getUri(source)
local parentNode = vm.compileNode(source.node)
for pn in parentNode:eachObject() do
- searchFieldSwitch(pn.type, uri, pn, key, false, pushResult)
+ searchFieldSwitch(pn.type, uri, pn, key, pushResult)
end
end)
diff --git a/script/vm/field.lua b/script/vm/field.lua
index db53509b..9e883505 100644
--- a/script/vm/field.lua
+++ b/script/vm/field.lua
@@ -31,7 +31,7 @@ local function searchByNode(source, pushResult, mark)
end
mark[source] = true
local uri = guide.getUri(source)
- vm.compileByParentNode(source, nil, true, function (field)
+ vm.compileByParentNode(source, nil, function (field)
searchByNodeSwitch(field.type, uri, field, pushResult)
end)
vm.compileByNodeChain(source, function (src)
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 37b54349..64bb0e9a 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -9,6 +9,7 @@ local vm = require 'vm.vm'
---@class vm.global.link
---@field gets parser.object[]
---@field sets parser.object[]
+---@field hasGet boolean?
---@class vm.global
---@field links table<uri, vm.global.link>
@@ -34,10 +35,11 @@ end
---@param uri uri
---@param source parser.object
function mt:addGet(uri, source)
+ local link = self.links[uri]
if PREVIEW then
+ link.hasGet = true
return
end
- local link = self.links[uri]
if not link.gets then
link.gets = {}
end
@@ -96,6 +98,7 @@ function mt:getAllSets()
return cache
end
+---@async
---@return parser.object[]
function mt:getGets(suri)
if not self.getsCache then
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index f342dae8..e2086c1a 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -216,6 +216,7 @@ function searchByParentNode(source, pushResult, defMap, fileNotify)
nodeSwitch(source.type, source, pushResult, defMap, fileNotify)
end
+---@async
local function searchByGlobal(source, pushResult)
if source.type == 'field'
or source.type == 'method'
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index b70aaec5..10b08884 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -91,7 +91,7 @@ function mt:resolve(uri, args)
if n.type == 'global' and n.cate == 'type' then
-- ---@field [integer]: number -> T[]
---@cast n vm.global
- vm.getClassFields(uri, n, vm.declareGlobal('type', 'integer'), false, function (field)
+ vm.getClassFields(uri, n, vm.declareGlobal('type', 'integer'), function (field)
resolve(object.node, vm.compileNode(field.extends))
end)
end
diff --git a/test/completion/common.lua b/test/completion/common.lua
index efbe9dd1..0bf9c606 100644
--- a/test/completion/common.lua
+++ b/test/completion/common.lua
@@ -630,7 +630,7 @@ self.results.list[#self.re<??>]
},
{
label = 'results',
- kind = define.CompletionItemKind.Field,
+ kind = define.CompletionItemKind.Text,
},
}