summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-05 05:56:03 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-05 05:56:03 +0800
commit0e159ee03730b74c284c5ad079215b31461d266e (patch)
tree9fd2d7aef9903d9c9c2d07749ea9f1175b0eee77 /script/core
parent9310038417408a5c2f6c148447d951f248fce2fe (diff)
downloadlua-language-server-0e159ee03730b74c284c5ad079215b31461d266e.zip
update
Diffstat (limited to 'script/core')
-rw-r--r--script/core/completion/completion.lua83
-rw-r--r--script/core/definition.lua5
-rw-r--r--script/core/diagnostics/circle-doc-class.lua2
-rw-r--r--script/core/diagnostics/duplicate-doc-class.lua2
-rw-r--r--script/core/diagnostics/type-check.lua14
-rw-r--r--script/core/diagnostics/undefined-doc-class.lua2
-rw-r--r--script/core/diagnostics/undefined-doc-name.lua2
-rw-r--r--script/core/hover/description.lua4
-rw-r--r--script/core/semantic-tokens.lua18
9 files changed, 60 insertions, 72 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 76dd6480..aed3e83a 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -19,6 +19,7 @@ local guide = require 'parser.guide'
local infer = require 'vm.infer'
local await = require 'await'
local postfix = require 'core.completion.postfix'
+local globalMgr = require 'vm.global-manager'
local diagnosticModes = {
'disable-next-line',
@@ -287,7 +288,7 @@ local function checkLocal(state, word, position, results)
if name:sub(1, 1) == '@' then
goto CONTINUE
end
- if infer.hasType(source, 'function') then
+ if infer.getInfer(source):hasType 'function' then
for _, def in ipairs(vm.getDefs(source)) do
if def.type == 'function'
or def.type == 'doc.type.function' then
@@ -335,7 +336,7 @@ local function checkModule(state, word, position, results)
local fileName = path:match '[^/\\]*$'
local stemName = fileName:gsub('%..+', '')
if not locals[stemName]
- and not vm.hasGlobalSets(state.uri, stemName)
+ and not globalMgr.hasGlobalSets(state.uri, 'variable', stemName)
and not config.get(state.uri, 'Lua.diagnostics.globals')[stemName]
and stemName:match '^[%a_][%w_]*$'
and matchKey(word, stemName) then
@@ -482,7 +483,7 @@ local function checkFieldThen(state, name, src, word, startPos, position, parent
})
return
end
- if oop and not infer.hasType(src, 'function') then
+ if oop and not infer.getInfer(src):hasType 'function' then
return
end
local literal = guide.getLiteral(value)
@@ -584,17 +585,17 @@ end
---@async
local function checkGlobal(state, word, startPos, position, parent, oop, results)
local locals = guide.getVisibleLocals(state.ast, position)
- local globals = vm.getGlobalSets(state.uri, '*')
+ local globals = globalMgr.getGlobalSets(state.uri, 'variable')
checkFieldOfRefs(globals, state, word, startPos, position, parent, oop, results, locals, 'global')
end
---@async
local function checkField(state, word, start, position, parent, oop, results)
if parent.tag == '_ENV' or parent.special == '_G' then
- local globals = vm.getGlobalSets(state.uri, '*')
+ local globals = globalMgr.getGlobalSets(state.uri, 'variable')
checkFieldOfRefs(globals, state, word, start, position, parent, oop, results)
else
- local refs = vm.getRefs(parent, '*')
+ local refs = vm.getFields(parent)
checkFieldOfRefs(refs, state, word, start, position, parent, oop, results)
end
end
@@ -1106,7 +1107,7 @@ local function checkTypingEnum(state, position, defs, str, results)
local enums = {}
for _, def in ipairs(defs) do
if def.type == 'doc.type.string'
- or def.type == 'doc.resume' then
+ or def.type == 'doc.type.integer' then
enums[#enums+1] = {
label = def[1],
description = def.comment and def.comment.text,
@@ -1312,20 +1313,20 @@ function (%s)\
end"):format(table.concat(args, ', '))
end
-local function pushCallEnumsAndFuncs(defs)
+local function pushCallEnumsAndFuncs(source)
+ local defs = vm.getDefs(source)
local results = {}
for _, def in ipairs(defs) do
- if def.type == 'doc.type.string'
- or def.type == 'doc.resume' then
+ if def.type == 'doc.type.string' then
results[#results+1] = {
- label = def[1],
+ label = util.viewLiteral(def[1]),
description = def.comment,
kind = define.CompletionItemKind.EnumMember,
}
end
if def.type == 'doc.type.function' then
results[#results+1] = {
- label = infer.viewDocFunction(def),
+ label = infer.getInfer(def):view(),
description = def.comment,
kind = define.CompletionItemKind.Function,
insertText = buildInsertDocFunction(def),
@@ -1354,17 +1355,17 @@ local function getCallEnumsAndFuncs(source, index, oop, call)
for _, doc in ipairs(source.bindDocs) do
if doc.type == 'doc.param'
and doc.param[1] == arg[1] then
- return pushCallEnumsAndFuncs(vm.getDefs(doc.extends))
+ return pushCallEnumsAndFuncs(doc.extends)
elseif doc.type == 'doc.vararg'
and arg.type == '...' then
- return pushCallEnumsAndFuncs(vm.getDefs(doc.vararg))
+ return pushCallEnumsAndFuncs(doc.vararg)
end
end
end
if source.type == 'doc.type.function' then
local arg = source.args[index]
if arg and arg.extends then
- return pushCallEnumsAndFuncs(vm.getDefs(arg.extends))
+ return pushCallEnumsAndFuncs(arg.extends)
end
end
if source.type == 'doc.field.name' then
@@ -1400,7 +1401,7 @@ local function getCallEnumsAndFuncs(source, index, oop, call)
if eventName and eventName == myEventName then
local docFunc = doc.extends.types[1].args[2].extends.types[1]
results[#results+1] = {
- label = infer.viewDocFunction(docFunc),
+ label = infer.getInfer(docFunc):view(),
description = doc.comment,
kind = define.CompletionItemKind.Function,
insertText = buildInsertDocFunction(docFunc),
@@ -1520,7 +1521,7 @@ local function tryTable(state, position, results)
if source.type ~= 'table' then
tbl = source.parent
end
- local defs = vm.getDefs(tbl, '*')
+ local defs = vm.getFields(tbl)
for _, field in ipairs(defs) do
local name = guide.getKeyName(field)
if name and not mark[name] then
@@ -1635,19 +1636,20 @@ local function tryluaDocBySource(state, position, source, results)
if source.type == 'doc.extends.name' then
if source.parent.type == 'doc.class' then
local used = {}
- for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
- if doc.type == 'doc.class.name'
- and doc.parent ~= source.parent
- and not used[doc[1]]
- and matchKey(source[1], doc[1]) then
- used[doc[1]] = true
+ for _, doc in ipairs(vm.getDocSets(state.uri)) do
+ local name = doc.type == 'doc.class' and doc.class[1]
+ if name
+ and name ~= source.parent.class[1]
+ and not used[name]
+ and matchKey(source[1], name) then
+ used[name] = true
results[#results+1] = {
- label = doc[1],
+ label = name,
kind = define.CompletionItemKind.Class,
- textEdit = doc[1]:find '[^%w_]' and {
+ textEdit = name:find '[^%w_]' and {
start = source.start,
finish = position,
- newText = doc[1],
+ newText = name,
},
}
end
@@ -1656,19 +1658,20 @@ local function tryluaDocBySource(state, position, source, results)
return true
elseif source.type == 'doc.type.name' then
local used = {}
- for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
- if (doc.type == 'doc.class.name' or doc.type == 'doc.alias.name')
- and doc.parent ~= source.parent
- and not used[doc[1]]
- and matchKey(source[1], doc[1]) then
- used[doc[1]] = true
+ for _, doc in ipairs(vm.getDocSets(state.uri)) do
+ local name = (doc.type == 'doc.class' and doc.class[1])
+ or (doc.type == 'doc.alias' and doc.alias[1])
+ if name
+ and not used[name]
+ and matchKey(source[1], name) then
+ used[name] = true
results[#results+1] = {
- label = doc[1],
+ label = name,
kind = define.CompletionItemKind.Class,
- textEdit = doc[1]:find '[^%w_]' and {
+ textEdit = name:find '[^%w_]' and {
start = source.start,
finish = position,
- newText = doc[1],
+ newText = name,
},
}
end
@@ -1734,17 +1737,17 @@ end
local function tryluaDocByErr(state, position, err, docState, results)
if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then
- for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
- if doc.type == 'doc.class.name'
- and doc.parent ~= docState then
+ for _, doc in ipairs(vm.getDocSets(state.uri)) do
+ if doc.type == 'doc.class'
+ and doc.class[1] ~= docState.class[1] then
results[#results+1] = {
- label = doc[1],
+ label = doc.class[1],
kind = define.CompletionItemKind.Class,
}
end
end
elseif err.type == 'LUADOC_MISS_TYPE_NAME' then
- for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
+ for _, doc in ipairs(vm.getDocSets(state.uri)) 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/definition.lua b/script/core/definition.lua
index 78ebce8f..ef183496 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -152,7 +152,10 @@ return function (uri, offset)
goto CONTINUE
end
else
- if guide.isLiteral(src) and src.type ~= 'function' then
+ if guide.isLiteral(src)
+ and src.type ~= 'function'
+ and src.type ~= 'doc.type.function'
+ and src.type ~= 'doc.type.table' then
goto CONTINUE
end
end
diff --git a/script/core/diagnostics/circle-doc-class.lua b/script/core/diagnostics/circle-doc-class.lua
index 6bdad1be..407b7e83 100644
--- a/script/core/diagnostics/circle-doc-class.lua
+++ b/script/core/diagnostics/circle-doc-class.lua
@@ -39,7 +39,7 @@ return function (uri, callback)
end
if not mark[newName] then
mark[newName] = true
- local docs = vm.getDocDefines(uri, newName)
+ local docs = vm.getDocSets(uri, newName)
for _, otherDoc in ipairs(docs) do
if otherDoc.type == 'doc.class.name' then
list[#list+1] = otherDoc.parent
diff --git a/script/core/diagnostics/duplicate-doc-class.lua b/script/core/diagnostics/duplicate-doc-class.lua
index 1a37826b..a7f432df 100644
--- a/script/core/diagnostics/duplicate-doc-class.lua
+++ b/script/core/diagnostics/duplicate-doc-class.lua
@@ -18,7 +18,7 @@ return function (uri, callback)
if doc.type == 'doc.alias' then
local name = guide.getKeyName(doc)
if not cache[name] then
- local docs = vm.getDocDefines(uri, name)
+ local docs = vm.getDocSets(uri, name)
cache[name] = {}
for _, otherDoc in ipairs(docs) do
if otherDoc.type == 'doc.class.name'
diff --git a/script/core/diagnostics/type-check.lua b/script/core/diagnostics/type-check.lua
index ebfffea0..931e1cf6 100644
--- a/script/core/diagnostics/type-check.lua
+++ b/script/core/diagnostics/type-check.lua
@@ -17,8 +17,8 @@ local typeNameMap = {
['doc.class.name'] = true,
['doc.alias.name'] = true,
['doc.type.name'] = true,
- ['doc.type.string'] = true,
- ['doc.resume'] = true,
+ ['doc.type.string'] = true,
+ ['doc.type.integer'] = true,
}
@@ -37,10 +37,10 @@ local function isTable(name)
end
local function isUserDefineClass(uri, name)
- if vm.isBuiltinType(name) then
+ if guide.isBasicType(name) then
return false
else
- local defs = vm.getDocDefines(uri, name)
+ local defs = vm.getDocSets(uri, name)
for _, v in ipairs(defs) do
if v.type == 'doc.class.name' then
return true
@@ -54,7 +54,7 @@ local function isClassOralias(typeName)
if not typeName then
return false
elseif typeNameMap[typeName]
- or vm.isBuiltinType(typeName) then
+ or guide.isBasicType(typeName) then
return true
else
return false
@@ -99,7 +99,7 @@ end
-- if not type[1] then
-- return
-- end
--- local docDefs = vm.getDocDefines(type[1])
+-- local docDefs = vm.getDocSets(type[1])
-- for _, doc in ipairs(docDefs) do
-- if doc.parent
-- and doc.parent.type == 'doc.class'
@@ -119,7 +119,7 @@ end
local function addFatherClass(uri, infers)
for k in pairs(infers) do
if type(k) == 'string' then
- local docDefs = vm.getDocDefines(uri, k)
+ local docDefs = vm.getDocSets(uri, k)
for _, doc in ipairs(docDefs) do
if doc.parent
and doc.parent.type == 'doc.class'
diff --git a/script/core/diagnostics/undefined-doc-class.lua b/script/core/diagnostics/undefined-doc-class.lua
index 715583e7..c9678c13 100644
--- a/script/core/diagnostics/undefined-doc-class.lua
+++ b/script/core/diagnostics/undefined-doc-class.lua
@@ -23,7 +23,7 @@ return function (uri, callback)
end
for _, ext in ipairs(doc.extends) do
local name = ext[1]
- local docs = vm.getDocDefines(uri, name)
+ local docs = vm.getDocSets(uri, name)
if cache[name] == nil then
cache[name] = false
for _, otherDoc in ipairs(docs) do
diff --git a/script/core/diagnostics/undefined-doc-name.lua b/script/core/diagnostics/undefined-doc-name.lua
index a8c75c3c..69edb380 100644
--- a/script/core/diagnostics/undefined-doc-name.lua
+++ b/script/core/diagnostics/undefined-doc-name.lua
@@ -35,7 +35,7 @@ return function (uri, callback)
if name == '...' then
return
end
- if vm.isDocDefined(uri, name)
+ if #vm.getDocSets(uri, name) > 0
or hasNameOfGeneric(name, source) then
return
end
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 83f4bcca..49e8d2bc 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -158,8 +158,8 @@ local function buildEnumChunk(docType, name)
end
local types = {}
for _, tp in ipairs(docType.types) do
- if tp.type ~= 'doc.enum'
- and tp.type ~= 'doc.resume' then
+ if tp.type ~= 'doc.string'
+ and tp.type ~= 'doc.integer' then
types[#types+1] = tp[1]
end
end
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index 7f58014b..8d991df9 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -513,24 +513,6 @@ local Care = util.switch()
modifieres = define.TokenModifiers.static,
}
end)
- : case 'doc.resume'
- : call(function (source, options, results)
- if not options.annotation then
- return
- end
- results[#results+1] = {
- start = source.start,
- finish = source.finish,
- type = define.TokenTypes.string,
- modifieres = define.TokenModifiers.static,
- }
- local row = guide.rowColOf(source.start)
- results[#results+1] = {
- start = source.finish,
- finish = guide.positionOf(row, guide.getLineRange(options.state, row)),
- type = define.TokenTypes.comment,
- }
- end)
: case 'doc.type.function'
: call(function (source, options, results)
if not options.annotation then