diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-14 21:10:55 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-14 21:10:55 +0800 |
commit | 92a5388138c2d916eaa0160df1cebfbec70a6b16 (patch) | |
tree | 64592aef3c7deac08649e511d6fed1afcfb69c59 | |
parent | 834d5e70092d38c884b23fe2bc176ed06f362c69 (diff) | |
download | lua-language-server-92a5388138c2d916eaa0160df1cebfbec70a6b16.zip |
diagnostic supporting `tableexp`
-rw-r--r-- | script/core/diagnostics/duplicate-index.lua | 5 | ||||
-rw-r--r-- | script/core/diagnostics/newfield-call.lua | 38 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 7 |
3 files changed, 32 insertions, 18 deletions
diff --git a/script/core/diagnostics/duplicate-index.lua b/script/core/diagnostics/duplicate-index.lua index 5d354329..d1141901 100644 --- a/script/core/diagnostics/duplicate-index.lua +++ b/script/core/diagnostics/duplicate-index.lua @@ -15,13 +15,14 @@ return function (uri, callback) local mark = {} for _, obj in ipairs(source) do if obj.type == 'tablefield' - or obj.type == 'tableindex' then + or obj.type == 'tableindex' + or obj.type == 'tableexp' then local name = noder.getID(obj) if name and name:sub(-1) ~= '*' then if not mark[name] then mark[name] = {} end - mark[name][#mark[name]+1] = obj.field or obj.index + mark[name][#mark[name]+1] = obj.field or obj.index or obj.value end end end diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua index 2cbc13ee..27ac6fce 100644 --- a/script/core/diagnostics/newfield-call.lua +++ b/script/core/diagnostics/newfield-call.lua @@ -14,24 +14,30 @@ return function (uri, callback) guide.eachSourceType(ast.ast, 'table', function (source) for i = 1, #source do local field = source[i] - if field.type == 'call' then - local func = field.node - local args = field.args - if args then - local funcLine = guide.positionOf(lines, func.finish) - local argsLine = guide.positionOf(lines, args.start) - if argsLine > funcLine then - callback { - start = field.start, - finish = field.finish, - message = lang.script('DIAG_PREFIELD_CALL' - , text:sub(func.start, func.finish) - , text:sub(args.start, args.finish) - ) - } - end + if field.type ~= 'tableexp' then + goto CONTINUE + end + local call = field.value + if not call then + goto CONTINUE + end + local func = call.node + local args = call.args + if args then + local funcLine = guide.positionOf(lines, func.finish) + local argsLine = guide.positionOf(lines, args.start) + if argsLine > funcLine then + callback { + start = call.start, + finish = call.finish, + message = lang.script('DIAG_PREFIELD_CALL' + , text:sub(func.start, func.finish) + , text:sub(args.start, args.finish) + ) + } end end + ::CONTINUE:: end end) end diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index d9069b9b..b90b4b26 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -1158,3 +1158,10 @@ TEST [[ ---@type { x: number, y: number} ---| "'resume'" ]] + +TEST [[ +return { + 1, <!2!>, 3, + [<!2!>] = 4, +} +]] |