summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-16 20:37:00 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-16 20:37:00 +0800
commit8a9e8d9cfd12d43496c2bf16f70874af550d4e7e (patch)
tree5dfdec3988e74a8b4eae33849870051a96420d94 /script/core
parentea1c5197c469779ba7cd18f1a8da5da9908f2149 (diff)
downloadlua-language-server-8a9e8d9cfd12d43496c2bf16f70874af550d4e7e.zip
type-check: `cast-local-type`
Diffstat (limited to 'script/core')
-rw-r--r--script/core/diagnostics/cast-local-type.lua40
-rw-r--r--script/core/diagnostics/type-check-assign.lua20
-rw-r--r--script/core/diagnostics/type-check.lua3
3 files changed, 60 insertions, 3 deletions
diff --git a/script/core/diagnostics/cast-local-type.lua b/script/core/diagnostics/cast-local-type.lua
new file mode 100644
index 00000000..1284e934
--- /dev/null
+++ b/script/core/diagnostics/cast-local-type.lua
@@ -0,0 +1,40 @@
+local files = require 'files'
+local lang = require 'language'
+local guide = require 'parser.guide'
+local vm = require 'vm'
+local await = require 'await'
+
+---@async
+return function (uri, callback)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
+
+ ---@async
+ guide.eachSourceType(state.ast, 'local', function (loc)
+ if not loc.ref then
+ return
+ end
+ local locNode = vm.compileNode(loc)
+ if not locNode:getData 'hasDefined' then
+ return
+ end
+ for _, ref in ipairs(loc.ref) do
+ if ref.type == 'setlocal' then
+ await.delay()
+ local refNode = vm.compileNode(ref)
+ if not vm.isSubType(uri, refNode, locNode) then
+ callback {
+ start = ref.start,
+ finish = ref.finish,
+ message = lang.script('DIAG_CAST_LOCAL_TYPE', {
+ loc = vm.getInfer(locNode):view(uri),
+ ref = vm.getInfer(refNode):view(uri),
+ }),
+ }
+ end
+ end
+ end
+ end)
+end
diff --git a/script/core/diagnostics/type-check-assign.lua b/script/core/diagnostics/type-check-assign.lua
new file mode 100644
index 00000000..6b3c73b3
--- /dev/null
+++ b/script/core/diagnostics/type-check-assign.lua
@@ -0,0 +1,20 @@
+local files = require 'files'
+local lang = require 'language'
+local guide = require 'parser.guide'
+local vm = require 'vm'
+
+return function (uri, callback)
+ local state = files.getState(uri)
+ if not state then
+ return
+ end
+
+ guide.eachSourceType(state.ast, 'setlocal', function (source)
+ local value = source.value
+ if not value then
+ return
+ end
+ local locNode = vm.compileNode(source)
+ local valueNode = vm.compileNode(value)
+ end)
+end
diff --git a/script/core/diagnostics/type-check.lua b/script/core/diagnostics/type-check.lua
deleted file mode 100644
index cc2b3228..00000000
--- a/script/core/diagnostics/type-check.lua
+++ /dev/null
@@ -1,3 +0,0 @@
----@async
-return function(uri, callback)
-end