summaryrefslogtreecommitdiff
path: root/script/core/diagnostics
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-22 19:04:39 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-22 19:04:39 +0800
commitf0f26c65db90cddd7e45d751fb394e50165c4cb3 (patch)
treee4a306d20ea0e89c62e19002ef08eee0fd2c2d7c /script/core/diagnostics
parenteb3d39eaedce44c8e4e25cf03494b32e874f3ca9 (diff)
downloadlua-language-server-f0f26c65db90cddd7e45d751fb394e50165c4cb3.zip
close #319 close-non-object
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r--script/core/diagnostics/close-non-object.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/script/core/diagnostics/close-non-object.lua b/script/core/diagnostics/close-non-object.lua
new file mode 100644
index 00000000..cfefb037
--- /dev/null
+++ b/script/core/diagnostics/close-non-object.lua
@@ -0,0 +1,40 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+local define = require 'proto.define'
+
+return function (uri, callback)
+ local state = files.getAst(uri)
+ if not state then
+ return
+ end
+
+ guide.eachSourceType(state.ast, 'local', function (source)
+ if not source.attrs then
+ return
+ end
+ if source.attrs[1][1] ~= 'close' then
+ return
+ end
+ if not source.value then
+ callback {
+ start = source.start,
+ finish = source.finish,
+ message = lang.script.DIAG_COSE_NON_OBJECT,
+ }
+ return
+ end
+ if source.value.type == 'nil'
+ or source.value.type == 'number'
+ or source.value.type == 'boolean'
+ or source.value.type == 'table'
+ or source.value.type == 'function' then
+ callback {
+ start = source.value.start,
+ finish = source.value.finish,
+ message = lang.script.DIAG_COSE_NON_OBJECT,
+ }
+ return
+ end
+ end)
+end