summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-28 21:06:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-28 21:06:53 +0800
commit08b9dd387a9b912c68749018b7dfe3c1df7094d5 (patch)
tree46c81598c214b10643f3d8083bb7b64b9e2ba21c /script
parent9ad317f2a1eb8dc5715103c8c62e0fcff88a482b (diff)
downloadlua-language-server-08b9dd387a9b912c68749018b7dfe3c1df7094d5.zip
cleanup
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/cast-type-mismatch.lua2
-rw-r--r--script/files.lua1
-rw-r--r--script/vm/compiler.lua10
-rw-r--r--script/vm/function.lua22
-rw-r--r--script/vm/generic.lua2
-rw-r--r--script/vm/local-id.lua4
-rw-r--r--script/vm/node.lua5
-rw-r--r--script/vm/runner.lua21
-rw-r--r--script/vm/sign.lua2
-rw-r--r--script/vm/type.lua1
-rw-r--r--script/vm/value.lua4
-rw-r--r--script/workspace/require-path.lua3
-rw-r--r--script/workspace/workspace.lua2
13 files changed, 49 insertions, 30 deletions
diff --git a/script/core/diagnostics/cast-type-mismatch.lua b/script/core/diagnostics/cast-type-mismatch.lua
index 0561a8da..a48e6cca 100644
--- a/script/core/diagnostics/cast-type-mismatch.lua
+++ b/script/core/diagnostics/cast-type-mismatch.lua
@@ -30,7 +30,7 @@ return function (uri, callback)
callback {
start = cast.extends.start,
finish = cast.extends.finish,
- message = lang.script('DIAG_UNKNOWN_CAST_VARIABLE', {
+ message = lang.script('DIAG_CAST_TYPE_MISMATCH', {
def = vm.getInfer(defNode):view(uri),
ref = vm.getInfer(refNode):view(uri),
})
diff --git a/script/files.lua b/script/files.lua
index 56ccb60b..3b2b120b 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -136,6 +136,7 @@ function m.isLibrary(uri, excludeFolder)
end
--- 获取库文件的根目录
+---@return uri?
function m.getLibraryUri(suri, uri)
local scp = scope.getScope(suri)
return scp:getLinkedUri(uri)
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 9a5eba7f..c25b7df1 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -400,7 +400,7 @@ end
---@field _sign vm.sign|false
---@param source parser.object
----@return vm.sign?
+---@return vm.sign|false
local function getObjectSign(source)
if source._sign ~= nil then
return source._sign
@@ -1542,7 +1542,7 @@ local compilerSwitch = util.switch()
end)
end
if hasGeneric then
- ---@cast sign -?
+ ---@cast sign -false
vm.setNode(source, vm.createGeneric(rtn, sign))
else
vm.setNode(source, vm.compileNode(rtn))
@@ -1955,7 +1955,9 @@ function vm.compileNode(source)
if source.type == 'generic' then
vm.setNode(source, source)
- return vm.getNode(source)
+ local node = vm.getNode(source)
+ ---@cast node -?
+ return node
end
---@cast source parser.object
@@ -1965,6 +1967,6 @@ function vm.compileNode(source)
matchCall(source)
local node = vm.getNode(source)
-
+ ---@cast node -?
return node
end
diff --git a/script/vm/function.lua b/script/vm/function.lua
index d94e7561..5723fbc6 100644
--- a/script/vm/function.lua
+++ b/script/vm/function.lua
@@ -18,7 +18,7 @@ end
---@param func parser.object
---@return integer min
----@return integer max
+---@return number max
function vm.countParamsOfFunction(func)
local min = 0
local max = 0
@@ -60,7 +60,7 @@ end
---@param node vm.node
---@return integer min
----@return integer max
+---@return number max
function vm.countParamsOfNode(node)
local min, max
for n in node:eachObject() do
@@ -82,15 +82,21 @@ end
---@param func parser.object
---@param mark? table
---@return integer min
----@return integer max
+---@return number max
function vm.countReturnsOfFunction(func, mark)
if func.type == 'function' then
- local min, max
+ ---@type integer?
+ local min
+ ---@type number?
+ local max
local hasDocReturn
if func.bindDocs then
local lastReturn
local n = 0
- local dmin, dmax
+ ---@type integer?
+ local dmin
+ ---@type number?
+ local dmax
for _, doc in ipairs(func.bindDocs) do
if doc.type == 'doc.return' then
hasDocReturn = true
@@ -139,10 +145,12 @@ end
---@param func parser.object
---@param mark? table
---@return integer min
----@return integer max
+---@return number max
function vm.countReturnsOfCall(func, args, mark)
local funcs = vm.getMatchedFunctions(func, args)
+ ---@type integer?
local min
+ ---@type number?
local max
for _, f in ipairs(funcs) do
local rmin, rmax = vm.countReturnsOfFunction(f, mark)
@@ -159,7 +167,7 @@ end
---@param list parser.object[]?
---@param mark? table
---@return integer min
----@return integer max
+---@return number max
function vm.countList(list, mark)
if not list then
return 0, 0
diff --git a/script/vm/generic.lua b/script/vm/generic.lua
index 16965fe3..5163e155 100644
--- a/script/vm/generic.lua
+++ b/script/vm/generic.lua
@@ -13,7 +13,7 @@ mt.type = 'generic'
---@param source vm.object
---@param resolved? table<string, vm.node>
----@return parser.object
+---@return vm.object
local function cloneObject(source, resolved)
if not resolved then
return source
diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua
index 802cea3a..9168d680 100644
--- a/script/vm/local-id.lua
+++ b/script/vm/local-id.lua
@@ -147,7 +147,7 @@ function compileLocalID(source)
end
---@param source parser.object
----@return string?
+---@return string|false
function vm.getLocalID(source)
if source._localID ~= nil then
return source._localID
@@ -205,7 +205,7 @@ end
---@param source parser.object
---@param includeGets boolean
----@return parser.object[]
+---@return parser.object[]?
function vm.getLocalFields(source, includeGets)
local id = vm.getLocalID(source)
if not id then
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 6f0554f0..3b6e9afb 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -62,7 +62,7 @@ function mt:clear()
end
---@param n integer
----@return vm.object?
+---@return vm.node.object?
function mt:get(n)
return self[n]
end
@@ -284,7 +284,8 @@ function mt:removeNode(node)
self:remove(c.name)
elseif c.type == 'nil' then
self:remove 'nil'
- elseif c.type == 'boolean' then
+ elseif c.type == 'boolean'
+ or c.type == 'doc.type.boolean' then
if c[1] == true then
self:remove 'true'
else
diff --git a/script/vm/runner.lua b/script/vm/runner.lua
index fcd0f681..9f9a53a2 100644
--- a/script/vm/runner.lua
+++ b/script/vm/runner.lua
@@ -117,20 +117,20 @@ end
---@return vm.node outNode
function mt:_lookInto(action, topNode, outNode)
if not action then
- return topNode, outNode
+ return topNode, outNode or topNode
end
if self._mark[action] then
- return topNode, outNode
+ return topNode, outNode or topNode
end
self._mark[action] = true
local top = self._objs[self._index]
if not top then
- return topNode, outNode
+ return topNode, outNode or topNode
end
if not guide.isInRange(action, top.finish)
-- trick for `local tp = type(x);if tp == 'string' then`
and action.type ~= 'binary' then
- return topNode, outNode
+ return topNode, outNode or topNode
end
local set
local value = vm.getObjectValue(action)
@@ -151,7 +151,9 @@ function mt:_lookInto(action, topNode, outNode)
self:_fastWard(action.filter.finish, blockNode)
end
blockNode = self:_launchBlock(action, blockNode:copy())
- topNode = mainNode:merge(blockNode)
+ if mainNode then
+ topNode = mainNode:merge(blockNode)
+ end
elseif action.type == 'if' then
local hasElse
local mainNode = topNode:copy()
@@ -314,7 +316,7 @@ function mt:_lookInto(action, topNode, outNode)
if set then
topNode = self:_fastWard(set.range or set.finish, topNode)
end
- return topNode, outNode
+ return topNode, outNode or topNode
end
---@param block parser.object
@@ -356,7 +358,10 @@ function vm.launchRunner(loc, callback)
if #self._objs == 0 then
return
end
-
- local topNode = self:_launchBlock(guide.getParentBlock(loc), vm.getNode(loc):copy())
+ local main = guide.getParentBlock(loc)
+ if not main then
+ return
+ end
+ local topNode = self:_launchBlock(main, vm.getNode(loc):copy())
self:_fastWard(math.maxinteger, topNode)
end
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index 14d289eb..0022538a 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -17,7 +17,7 @@ end
---@param uri uri
---@param args parser.object
---@param removeGeneric true?
----@return table<string, vm.node>
+---@return table<string, vm.node>?
function mt:resolve(uri, args, removeGeneric)
if not args then
return nil
diff --git a/script/vm/type.lua b/script/vm/type.lua
index be411899..399cbffc 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -7,6 +7,7 @@ local config = require 'config.config'
---@return string?
local function getNodeName(object)
if object.type == 'global' and object.cate == 'type' then
+ ---@cast object vm.global
return object.name
end
if object.type == 'nil'
diff --git a/script/vm/value.lua b/script/vm/value.lua
index d826d908..92f1a2b9 100644
--- a/script/vm/value.lua
+++ b/script/vm/value.lua
@@ -51,7 +51,7 @@ function vm.testCondition(source)
end
---@param v vm.node.object
----@return string?
+---@return string|false
local function getUnique(v)
if v.type == 'boolean' then
if v[1] == nil then
@@ -79,7 +79,7 @@ local function getUnique(v)
---@cast v parser.object
return ('func:%s@%d'):format(guide.getUri(v), v.start)
end
- return nil
+ return false
end
---@param a parser.object?
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index aec298a6..fbe559ad 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -51,7 +51,8 @@ function m.getVisiblePath(suri, path)
and not scp:isLinkedUri(uri) then
return {}
end
- local libraryPath = furi.decode(files.getLibraryUri(suri, uri))
+ local libUri = files.getLibraryUri(suri, uri)
+ local libraryPath = libUri and furi.decode(libUri)
local cache = scp:get('visiblePath') or scp:set('visiblePath', {})
local result = cache[path]
if not result then
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 6425af06..9620f8a8 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -154,7 +154,7 @@ function m.getNativeMatcher(scp)
end
local matcher = glob.gitignore(pattern, {
- root = furi.decode(scp.uri),
+ root = scp.uri and furi.decode(scp.uri),
ignoreCase = platform.OS == 'Windows',
}, globInteferFace)