summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json24
-rw-r--r--server-beta/src/core/diagnostics/duplicate-index.lua68
-rw-r--r--server-beta/src/core/diagnostics/newfield-call.lua24
-rw-r--r--server-beta/test/diagnostics/init.lua10
4 files changed, 77 insertions, 49 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 521f9fc4..a60710f0 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -12,7 +12,11 @@
],
"consoleCoding": "utf8",
"sourceCoding": "utf8",
- "luaRuntime": "5.4 64bit"
+ "luaRuntime": "5.4 64bit",
+ "outputCapture": [
+ "print",
+ "stderr",
+ ],
},
{
"name": "附加",
@@ -40,7 +44,11 @@
"consoleCoding": "utf8",
"sourceCoding": "utf8",
"preLaunchTask": "编译",
- "luaRuntime": "5.4 64bit"
+ "luaRuntime": "5.4 64bit",
+ "outputCapture": [
+ "print",
+ "stderr",
+ ],
},
{
"name": "发布",
@@ -52,7 +60,11 @@
],
"consoleCoding": "utf8",
"sourceCoding": "utf8",
- "luaRuntime": "5.4 64bit"
+ "luaRuntime": "5.4 64bit",
+ "outputCapture": [
+ "print",
+ "stderr",
+ ],
},
{
"name": "🍺测试-beta",
@@ -64,7 +76,11 @@
],
"consoleCoding": "utf8",
"sourceCoding": "utf8",
- "luaRuntime": "5.4 64bit"
+ "luaRuntime": "5.4 64bit",
+ "outputCapture": [
+ "print",
+ "stderr",
+ ],
},
{
"name": "附加-beta",
diff --git a/server-beta/src/core/diagnostics/duplicate-index.lua b/server-beta/src/core/diagnostics/duplicate-index.lua
index 8ebe0dee..76b1c958 100644
--- a/server-beta/src/core/diagnostics/duplicate-index.lua
+++ b/server-beta/src/core/diagnostics/duplicate-index.lua
@@ -9,8 +9,8 @@ return function (uri, callback)
return
end
- local mark = {}
guide.eachSourceType(ast.ast, 'table', function (source)
+ local mark = {}
for _, obj in ipairs(source) do
if obj.type == 'tablefield'
or obj.type == 'tableindex' then
@@ -23,40 +23,40 @@ return function (uri, callback)
end
end
end
- end)
- for name, defs in pairs(mark) do
- local sname = name:match '^.|(.+)$'
- if #defs > 1 and sname then
- local related = {}
- for i = 1, #defs do
- local def = defs[i]
- related[i] = {
- start = def.start,
- finish = def.finish,
- uri = uri,
- }
- end
- for i = 1, #defs - 1 do
- local def = defs[i]
- callback {
- start = def.start,
- finish = def.finish,
- related = related,
- message = lang.script('DIAG_DUPLICATE_INDEX', sname),
- level = define.DiagnosticSeverity.Hint,
- tags = { define.DiagnosticTag.Unnecessary },
- }
- end
- for i = #defs, #defs do
- local def = defs[i]
- callback {
- start = def.start,
- finish = def.finish,
- related = related,
- message = lang.script('DIAG_DUPLICATE_INDEX', sname),
- }
+ for name, defs in pairs(mark) do
+ local sname = name:match '^.|(.+)$'
+ if #defs > 1 and sname then
+ local related = {}
+ for i = 1, #defs do
+ local def = defs[i]
+ related[i] = {
+ start = def.start,
+ finish = def.finish,
+ uri = uri,
+ }
+ end
+ for i = 1, #defs - 1 do
+ local def = defs[i]
+ callback {
+ start = def.start,
+ finish = def.finish,
+ related = related,
+ message = lang.script('DIAG_DUPLICATE_INDEX', sname),
+ level = define.DiagnosticSeverity.Hint,
+ tags = { define.DiagnosticTag.Unnecessary },
+ }
+ end
+ for i = #defs, #defs do
+ local def = defs[i]
+ callback {
+ start = def.start,
+ finish = def.finish,
+ related = related,
+ message = lang.script('DIAG_DUPLICATE_INDEX', sname),
+ }
+ end
end
end
- end
+ end)
end
diff --git a/server-beta/src/core/diagnostics/newfield-call.lua b/server-beta/src/core/diagnostics/newfield-call.lua
index 87ece955..75681cbc 100644
--- a/server-beta/src/core/diagnostics/newfield-call.lua
+++ b/server-beta/src/core/diagnostics/newfield-call.lua
@@ -17,17 +17,19 @@ return function (uri, callback)
if field.type == 'call' then
local func = field.node
local args = field.args
- 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)
- )
- }
+ 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
end
end
end
diff --git a/server-beta/test/diagnostics/init.lua b/server-beta/test/diagnostics/init.lua
index ac76371d..1493494d 100644
--- a/server-beta/test/diagnostics/init.lua
+++ b/server-beta/test/diagnostics/init.lua
@@ -439,6 +439,16 @@ return {
]]
TEST [[
+return {
+ x = 1,
+ y = 2,
+}, {
+ x = 1,
+ y = 2,
+}
+]]
+
+TEST [[
local m = {}
function m.open()
end