summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-07 20:06:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-07 20:06:45 +0800
commita80d62baf3568e42ffa796509a2056dd9021c462 (patch)
treeebdbff6bda538d728e797e4c48ddb15c8e74db61 /server-beta
parent0f4da273013ed0b311debefb8824c47d8be7e58f (diff)
downloadlua-language-server-a80d62baf3568e42ffa796509a2056dd9021c462.zip
诊断测试完成
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/diagnostics/duplicate-method.lua3
-rw-r--r--server-beta/src/core/diagnostics/newfield-call.lua36
-rw-r--r--server-beta/src/core/diagnostics/set-const.lua3
-rw-r--r--server-beta/src/proto/define.lua2
-rw-r--r--server-beta/test/diagnostics/init.lua37
5 files changed, 63 insertions, 18 deletions
diff --git a/server-beta/src/core/diagnostics/duplicate-method.lua b/server-beta/src/core/diagnostics/duplicate-method.lua
deleted file mode 100644
index b3d19c21..00000000
--- a/server-beta/src/core/diagnostics/duplicate-method.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-return function ()
-
-end
diff --git a/server-beta/src/core/diagnostics/newfield-call.lua b/server-beta/src/core/diagnostics/newfield-call.lua
index b3d19c21..87ece955 100644
--- a/server-beta/src/core/diagnostics/newfield-call.lua
+++ b/server-beta/src/core/diagnostics/newfield-call.lua
@@ -1,3 +1,35 @@
-return function ()
-
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+
+return function (uri, callback)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+
+ local lines = files.getLines(uri)
+ local text = files.getText(uri)
+
+ 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
+ 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)
end
diff --git a/server-beta/src/core/diagnostics/set-const.lua b/server-beta/src/core/diagnostics/set-const.lua
deleted file mode 100644
index b3d19c21..00000000
--- a/server-beta/src/core/diagnostics/set-const.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-return function ()
-
-end
diff --git a/server-beta/src/proto/define.lua b/server-beta/src/proto/define.lua
index 9401e9e5..6acd2348 100644
--- a/server-beta/src/proto/define.lua
+++ b/server-beta/src/proto/define.lua
@@ -93,11 +93,9 @@ m.DiagnosticDefaultSeverity = {
['lowercase-global'] = 'Information',
['undefined-env-child'] = 'Information',
['duplicate-index'] = 'Warning',
- ['duplicate-method'] = 'Warning',
['empty-block'] = 'Hint',
['redundant-value'] = 'Hint',
['emmy-lua'] = 'Warning',
- ['set-const'] = 'Error',
}
--- 诊断报告标签
diff --git a/server-beta/test/diagnostics/init.lua b/server-beta/test/diagnostics/init.lua
index 2bb99323..ac76371d 100644
--- a/server-beta/test/diagnostics/init.lua
+++ b/server-beta/test/diagnostics/init.lua
@@ -203,6 +203,34 @@ print()
]]
TEST [[
+return {
+ <!print
+ 'string'!>
+}
+]]
+
+TEST [[
+return {
+ <!print
+ {
+ x = 1,
+ }!>
+}
+]]
+
+TEST [[
+print()
+'string'
+]]
+
+TEST [[
+print
+{
+ x = 1,
+}
+]]
+
+TEST [[
local function x(a, b)
return a, b
end
@@ -619,14 +647,7 @@ x = (x + y) or 0
TEST [[
local t = {}
-function t:<!a!>()
-end
-function t:<!a!>()
-end
-]]
-
-TEST [[
-local t = {}
t.a = 1
t.a = 2
+return t
]]