diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-17 18:15:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-17 18:15:13 +0800 |
commit | 166504aa87a5b2f7fe6bd41b2c572afccb717534 (patch) | |
tree | 5a61486aca3e1a98a4eeceed13e3ac583d0894eb /script/core | |
parent | 6431519640a087499ea497066a78a6079993b945 (diff) | |
download | lua-language-server-166504aa87a5b2f7fe6bd41b2c572afccb717534.zip |
update
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/assign-type-mismatch.lua | 47 | ||||
-rw-r--r-- | script/core/diagnostics/init.lua | 13 | ||||
-rw-r--r-- | script/core/diagnostics/type-check-assign.lua | 20 |
3 files changed, 54 insertions, 26 deletions
diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua new file mode 100644 index 00000000..38cfc674 --- /dev/null +++ b/script/core/diagnostics/assign-type-mismatch.lua @@ -0,0 +1,47 @@ +local files = require 'files' +local lang = require 'language' +local guide = require 'parser.guide' +local vm = require 'vm' +local await = require 'await' + +local checkTypes = { + 'setlocal', + 'setglobal', + 'setfield', + 'setindex', + 'setmethod', + 'tablefield', + 'tableindex' +} + +---@async +return function (uri, callback) + local state = files.getState(uri) + if not state then + return + end + + ---@async + guide.eachSourceTypes(state.ast, checkTypes, function (source) + local value = source.value + if not value then + return + end + await.delay() + local varNode = vm.compileNode(source) + local valueNode = vm.compileNode(value) + if vm.getInfer(varNode):hasUnknown(uri) then + return + end + if not vm.isSubType(uri, valueNode, varNode) then + callback { + start = source.start, + finish = source.finish, + message = lang.script('DIAG_ASSIGN_TYPE_MISMATCH', { + loc = vm.getInfer(varNode):view(uri), + ref = vm.getInfer(valueNode):view(uri), + }), + } + end + end) +end diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index e9af8ea3..746052b0 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -7,12 +7,13 @@ local util = require 'utility' -- 把耗时最长的诊断放到最后面 local diagSort = { - ['redundant-value'] = 100, - ['not-yieldable'] = 101, - ['deprecated'] = 102, - ['undefined-field'] = 103, - ['redundant-parameter'] = 104, - ['cast-local-type'] = 105, + ['redundant-value'] = 100, + ['not-yieldable'] = 101, + ['deprecated'] = 102, + ['undefined-field'] = 103, + ['redundant-parameter'] = 104, + ['cast-local-type'] = 105, + ['assign-type-mismatch'] = 106, } local diagList = {} diff --git a/script/core/diagnostics/type-check-assign.lua b/script/core/diagnostics/type-check-assign.lua deleted file mode 100644 index 6b3c73b3..00000000 --- a/script/core/diagnostics/type-check-assign.lua +++ /dev/null @@ -1,20 +0,0 @@ -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 |