Skip to content

Commit 5b95074

Browse files
committed
cleanup
1 parent deac458 commit 5b95074

File tree

16 files changed

+103
-92
lines changed

16 files changed

+103
-92
lines changed

script/await.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ end
132132
---@param callback function
133133
---@async
134134
function m.wait(callback, ...)
135-
if not coroutine.isyieldable() then
136-
return
137-
end
138135
local co = coroutine.running()
139136
local resumed
140137
callback(function (...)

script/client.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ local function tryModifySpecifiedConfig(uri, finalChanges)
240240
return false
241241
end
242242
local path = workspace.getAbsolutePath(uri, CONFIGPATH)
243+
if not path then
244+
return false
245+
end
243246
util.saveFile(path, json.beautify(scp:get('lastLocalConfig'), { indent = ' ' }))
244247
return true
245248
end
@@ -254,6 +257,9 @@ local function tryModifyRC(uri, finalChanges, create)
254257
return false
255258
end
256259
path = fs.exists(path) and path or workspace.getAbsolutePath(uri, '.luarc.json')
260+
if not path then
261+
return false
262+
end
257263
local buf = util.loadFile(path)
258264
if not buf and not create then
259265
return false

script/config/loader.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717
---@class config.loader
1818
local m = {}
1919

20-
---@return table
20+
---@return table?
2121
function m.loadRCConfig(uri, filename)
2222
local scp = scope.getScope(uri)
2323
local path = workspace.getAbsolutePath(uri, filename)
@@ -35,6 +35,7 @@ function m.loadRCConfig(uri, filename)
3535
errorMessage(lang.script('CONFIG_LOAD_ERROR', res))
3636
return scp:get('lastRCConfig')
3737
end
38+
---@cast res table
3839
scp:set('lastRCConfig', res)
3940
return res
4041
end
@@ -62,6 +63,7 @@ function m.loadLocalConfig(uri, filename)
6263
errorMessage(lang.script('CONFIG_LOAD_ERROR', res))
6364
return scp:get('lastLocalConfig')
6465
end
66+
---@cast res table
6567
scp:set('lastLocalConfig', res)
6668
scp:set('lastLocalType', 'json')
6769
return res
@@ -81,7 +83,7 @@ end
8183

8284
---@async
8385
---@param uri? uri
84-
---@return table
86+
---@return table?
8587
function m.loadClientConfig(uri)
8688
local configs = proto.awaitRequest('workspace/configuration', {
8789
items = {

script/core/diagnostics/assign-type-mismatch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ return function (uri, callback)
3636
end
3737
end
3838
local valueNode = vm.compileNode(value)
39-
if source.type == 'setindex' then
39+
if source.type == 'setindex' then
4040
-- boolean[1] = nil
4141
valueNode = valueNode:copy():removeOptional()
4242
end

script/core/diagnostics/duplicate-set-field.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ return function (uri, callback)
4848
local blocks = {}
4949
for _, value in ipairs(values) do
5050
local block = guide.getBlock(value)
51-
if not blocks[block] then
52-
blocks[block] = {}
51+
if block then
52+
if not blocks[block] then
53+
blocks[block] = {}
54+
end
55+
blocks[block][#blocks[block]+1] = value
5356
end
54-
blocks[block][#blocks[block]+1] = value
5557
end
5658
for _, defs in pairs(blocks) do
5759
if #defs <= 1 then

script/core/diagnostics/return-type-mismatch.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ return function (uri, callback)
3838
if not exp then
3939
break
4040
end
41+
if retNode:hasName 'nil' then
42+
if exp.type == 'getfield'
43+
or exp.type == 'getindex' then
44+
retNode = retNode:copy():removeOptional()
45+
end
46+
end
4147
if not vm.canCastType(uri, docRet, retNode) then
4248
callback {
4349
start = exp.start,

script/core/diagnostics/unused-function.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ local function isToBeClosed(source)
1818
return false
1919
end
2020

21-
---@param source parser.object
21+
---@param source parser.object?
22+
---@return boolean
2223
local function isValidFunction(source)
2324
if not source then
2425
return false
@@ -55,7 +56,7 @@ local function collect(ast, white, roots, links)
5556
for _, ref in ipairs(loc.ref or {}) do
5657
if ref.type == 'getlocal' then
5758
local func = guide.getParentFunction(ref)
58-
if not isValidFunction(func) or roots[func] then
59+
if not func or not isValidFunction(func) or roots[func] then
5960
roots[src] = true
6061
return
6162
end

script/file-uri.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ end
6767
---@param uri uri
6868
---@return string path
6969
function m.decode(uri)
70-
if not uri then
71-
return nil
72-
end
7370
local scheme, authority, path = uri:match('([^:]*):?/?/?([^/]*)(.*)')
7471
if not scheme then
7572
return ''

script/files.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ end
344344

345345
--- 获取文件原始文本
346346
---@param uri uri
347-
---@return string text
347+
---@return string? text
348348
function m.getOriginText(uri)
349349
local file = m.fileMap[uri]
350350
if not file then
@@ -358,9 +358,7 @@ end
358358
---@return integer[]
359359
function m.getOriginLines(uri)
360360
local file = m.fileMap[uri]
361-
if not file then
362-
return nil
363-
end
361+
assert(file, 'file not exists:' .. uri)
364362
return file.originLines
365363
end
366364

script/fs-utility.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ end
261261

262262
---@param path string|fspath
263263
---@param option table
264-
---@return fspath
264+
---@return fspath?
265265
local function fsAbsolute(path, option)
266266
if type(path) == 'string' then
267267
local suc, res = pcall(fs.path, path)
@@ -451,6 +451,9 @@ local function fileRemove(path, option)
451451
end
452452
end
453453

454+
---@param source fspath?
455+
---@param target fspath?
456+
---@param option table
454457
local function fileCopy(source, target, option)
455458
if not source or not target then
456459
return
@@ -462,7 +465,7 @@ local function fileCopy(source, target, option)
462465
if isDir2 or fsCreateDirectories(target, option) then
463466
for filePath in fsPairs(source) do
464467
local name = filePath:filename():string()
465-
fileCopy(filePath, target / name, option)
468+
fileCopy(filePath, target / name--[[@as fspath]], option)
466469
end
467470
end
468471
else
@@ -513,7 +516,7 @@ local function fileSync(source, target, option)
513516
if fsCreateDirectories(target) then
514517
for filePath in fsPairs(source) do
515518
local name = filePath:filename():string()
516-
fileCopy(filePath, target / name, option)
519+
fileCopy(filePath, target / name--[[@as fspath]], option)
517520
end
518521
end
519522
end
@@ -595,10 +598,10 @@ end
595598
---@return table
596599
function m.fileCopy(source, target, option)
597600
option = buildOption(option)
598-
source = fsAbsolute(source, option)
599-
target = fsAbsolute(target, option)
601+
local fsSource = fsAbsolute(source, option)
602+
local fsTarget = fsAbsolute(target, option)
600603

601-
fileCopy(source, target, option)
604+
fileCopy(fsSource, fsTarget, option)
602605

603606
return option
604607
end
@@ -609,10 +612,10 @@ end
609612
---@return table
610613
function m.fileSync(source, target, option)
611614
option = buildOption(option)
612-
source = fsAbsolute(source, option)
613-
target = fsAbsolute(target, option)
615+
local fsSource = fsAbsolute(source, option)
616+
local fsTarget = fsAbsolute(target, option)
614617

615-
fileSync(source, target, option)
618+
fileSync(fsSource, fsTarget, option)
616619

617620
return option
618621
end

0 commit comments

Comments
 (0)