summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-11 19:03:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-11 19:03:11 +0800
commit3b642df7cb6730f35342803089f2d6d495ddd554 (patch)
treebc767efc6c1c12fcb17024217d3adfd844af9922 /script
parent2e4f530b33467b94376321c7f9879f2a879429bb (diff)
downloadlua-language-server-3b642df7cb6730f35342803089f2d6d495ddd554.zip
fix #1037
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/completion.lua11
-rw-r--r--script/core/diagnostics/circle-doc-class.lua2
-rw-r--r--script/core/hover/description.lua5
-rw-r--r--script/library.lua2
-rw-r--r--script/vm/compiler.lua30
-rw-r--r--script/vm/global-manager.lua27
-rw-r--r--script/vm/local-id.lua4
7 files changed, 57 insertions, 24 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 27d1b20a..9f0c6695 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -420,7 +420,7 @@ local function checkModule(state, word, position, results)
end
local function checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position)
- if type(name) == 'string' and name:match '^[%a_][%w_]*$' then
+ if name:match '^[%a_][%w_]*$' then
return nil
end
local textEdit, additionalTextEdits
@@ -493,7 +493,7 @@ local function checkFieldThen(state, name, src, word, startPos, position, parent
kind = define.CompletionItemKind.Function
end
buildFunction(results, src, value, oop, {
- label = tostring(name),
+ label = name,
kind = kind,
match = name:match '^[^(]+',
insertText = name:match '^[^(]+',
@@ -526,7 +526,7 @@ local function checkFieldThen(state, name, src, word, startPos, position, parent
textEdit, additionalTextEdits = checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position)
end
results[#results+1] = {
- label = tostring(name),
+ label = name,
kind = kind,
deprecated = vm.isDeprecated(src) or nil,
textEdit = textEdit,
@@ -554,6 +554,7 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o
if isSameSource(state, src, startPos) then
goto CONTINUE
end
+ name = tostring(name)
if isGlobal and locals and locals[name] then
goto CONTINUE
end
@@ -1376,7 +1377,9 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
if left then
for _, field in ipairs(fields) do
local name = guide.getKeyName(field)
- if not mark[name] and matchKey(left, guide.getKeyName(field)) then
+ if name
+ and not mark[name]
+ and matchKey(left, tostring(name)) then
results[#results+1] = {
label = guide.getKeyName(field),
kind = define.CompletionItemKind.Property,
diff --git a/script/core/diagnostics/circle-doc-class.lua b/script/core/diagnostics/circle-doc-class.lua
index 9a3fa2f5..40d4afeb 100644
--- a/script/core/diagnostics/circle-doc-class.lua
+++ b/script/core/diagnostics/circle-doc-class.lua
@@ -37,7 +37,7 @@ return function (uri, callback)
}
goto CONTINUE
end
- if not mark[newName] then
+ if newName and not mark[newName] then
mark[newName] = true
local docs = vm.getDocSets(uri, newName)
for _, otherDoc in ipairs(docs) do
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 7b32c41c..5d350cf7 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -146,6 +146,9 @@ local function tryDocModule(source)
end
local function buildEnumChunk(docType, name)
+ if not docType then
+ return nil
+ end
local enums = {}
local types = {}
local lines = {}
@@ -164,7 +167,7 @@ local function buildEnumChunk(docType, name)
end
end
if #enums == 0 then
- return
+ return nil
end
lines[#lines+1] = ('%s:'):format(name)
for _, enum in ipairs(enums) do
diff --git a/script/library.lua b/script/library.lua
index af86fe95..66c4d364 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -109,7 +109,7 @@ local function compileSingleMetaDoc(uri, script, metaLang, status)
version = 5.1
jit = true
else
- version = tonumber(config.get(uri, 'Lua.runtime.version'):sub(-3))
+ version = tonumber(config.get(uri, 'Lua.runtime.version'):sub(-3)) or 5.4
jit = false
end
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index aff58c83..19a41540 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -87,7 +87,9 @@ local searchFieldSwitch = util.switch()
: call(function (suri, node, key, pushResult)
-- change to `string: stringlib` ?
local stringlib = globalMgr.getGlobal('type', 'stringlib')
- m.getClassFields(suri, stringlib, key, pushResult)
+ if stringlib then
+ m.getClassFields(suri, stringlib, key, pushResult)
+ end
end)
: case 'local'
: call(function (suri, node, key, pushResult)
@@ -302,8 +304,8 @@ function m.getReturnOfFunction(func, index)
end
local function getReturnOfSetMetaTable(args)
- local tbl = args and args[1]
- local mt = args and args[2]
+ local tbl = args[1]
+ local mt = args[2]
local node = union()
if tbl then
node:merge(m.compileNode(tbl))
@@ -325,9 +327,15 @@ end
local function getReturn(func, index, args)
if func.special == 'setmetatable' then
+ if not args then
+ return nil
+ end
return getReturnOfSetMetaTable(args)
end
if func.special == 'pcall' and index > 1 then
+ if not args then
+ return nil
+ end
local newArgs = {}
for i = 2, #args do
newArgs[#newArgs+1] = args[i]
@@ -335,6 +343,9 @@ local function getReturn(func, index, args)
return getReturn(args[1], index - 1, newArgs)
end
if func.special == 'xpcall' and index > 1 then
+ if not args then
+ return nil
+ end
local newArgs = {}
for i = 3, #args do
newArgs[#newArgs+1] = args[i]
@@ -342,6 +353,9 @@ local function getReturn(func, index, args)
return getReturn(args[1], index - 1, newArgs)
end
if func.special == 'require' then
+ if not args then
+ return nil
+ end
local nameArg = args[1]
if not nameArg or nameArg.type ~= 'string' then
return nil
@@ -941,9 +955,11 @@ local compilerSwitch = util.switch()
-- initValue
selectNode(source._iterArgs[2], source.exps, 3)
end
- for i, loc in ipairs(source.keys) do
- local node = getReturn(source._iterator, i, source._iterArgs)
- nodeMgr.setNode(loc, node)
+ if source.keys then
+ for i, loc in ipairs(source.keys) do
+ local node = getReturn(source._iterator, i, source._iterArgs)
+ nodeMgr.setNode(loc, node)
+ end
end
end)
: case 'doc.type'
@@ -1360,7 +1376,7 @@ local compilerSwitch = util.switch()
if source.op.type == '//' then
local a = valueMgr.getNumber(source[1])
local b = valueMgr.getNumber(source[2])
- if a and b then
+ if a and b and b ~= 0 then
local result = a // b
nodeMgr.setNode(source, {
type = math.type(result) == 'integer' and 'integer' or 'number',
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua
index bb4498ff..bd5b8696 100644
--- a/script/vm/global-manager.lua
+++ b/script/vm/global-manager.lua
@@ -74,7 +74,7 @@ local compilerGlobalSwitch = util.switch()
if parentName == '_G' then
name = keyName
else
- name = parentName .. m.ID_SPLITE .. keyName
+ name = ('%s%s%s'):format(parentName, m.ID_SPLITE, keyName)
end
elseif source.node.special == '_G' then
name = keyName
@@ -82,7 +82,7 @@ local compilerGlobalSwitch = util.switch()
if not name then
return
end
- local uri = guide.getUri(source)
+ local uri = guide.getUri(source)
local global = m.declareGlobal('variable', name, uri)
global:addSet(uri, source)
source._globalNode = global
@@ -92,17 +92,22 @@ local compilerGlobalSwitch = util.switch()
: case 'getindex'
---@param source parser.object
: call(function (source)
- local name = guide.getKeyName(source)
- if not name then
+ local name
+ local keyName = guide.getKeyName(source)
+ if not keyName then
return
end
if source.node._globalNode then
local parentName = source.node._globalNode:getName()
- if parentName ~= '_G' then
- name = parentName .. m.ID_SPLITE .. name
+ if parentName == '_G' then
+ name = keyName
+ else
+ name = ('%s%s%s'):format(parentName, m.ID_SPLITE, keyName)
end
+ elseif source.node.special == '_G' then
+ name = keyName
end
- local uri = guide.getUri(source)
+ local uri = guide.getUri(source)
local global = m.declareGlobal('variable', name, uri)
global:addGet(uri, source)
source._globalNode = global
@@ -337,9 +342,11 @@ function m.dropUri(uri)
m.globalSubs[uri] = nil
for key in pairs(globalSub) do
local global = m.globals[key]
- global:dropUri(uri)
- if not global:isAlive() then
- m.globals[key] = nil
+ if global then
+ global:dropUri(uri)
+ if not global:isAlive() then
+ m.globals[key] = nil
+ end
end
end
end
diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua
index b7a6e6d5..98b13632 100644
--- a/script/vm/local-id.lua
+++ b/script/vm/local-id.lua
@@ -121,6 +121,10 @@ function m.compileLocalID(source)
return
end
local root = guide.getRoot(source)
+ if not root then
+ log.error('No root?', require 'inspect' (source, { depth = 1 }))
+ return
+ end
if not root._localIDs then
root._localIDs = util.multiTable(2)
end