summaryrefslogtreecommitdiff
path: root/script/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-03 16:49:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-03 16:49:46 +0800
commit07d99d97c0612608829d001b80773b1619de9a90 (patch)
tree791e6ede2cd14e426e4401de52e842ee35fb578d /script/core/diagnostics
parent696fde0354eb955ff631c985eedd076af0d72a4f (diff)
downloadlua-language-server-07d99d97c0612608829d001b80773b1619de9a90.zip
unbalanced-assignments
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r--script/core/diagnostics/unbalanced-assignments.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/script/core/diagnostics/unbalanced-assignments.lua b/script/core/diagnostics/unbalanced-assignments.lua
new file mode 100644
index 00000000..35aebb45
--- /dev/null
+++ b/script/core/diagnostics/unbalanced-assignments.lua
@@ -0,0 +1,43 @@
+local files = require 'files'
+local define = require 'proto.define'
+local lang = require 'language'
+local guide = require 'parser.guide'
+
+return function (uri, callback, code)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+
+ local last
+
+ local function checkSet(source)
+ if source.value then
+ last = source
+ else
+ if not last then
+ return
+ end
+ if last.start <= source.start
+ and last.value.start >= source.finish then
+ callback {
+ start = source.start,
+ finish = source.finish,
+ message = lang.script('DIAG_UNBALANCED_ASSIGNMENTS')
+ }
+ else
+ last = nil
+ end
+ end
+ end
+
+ guide.eachSource(ast.ast, function (source)
+ if source.type == 'local'
+ or source.type == 'setlocal'
+ or source.type == 'setglobal'
+ or source.type == 'setfield'
+ or source.type == 'setindex' then
+ checkSet(source)
+ end
+ end)
+end