diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-01-30 20:04:02 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-01-30 20:04:02 +0800 |
commit | 76b8cf3236db2efc7f73f3508212d99199b73b52 (patch) | |
tree | 25c028edc02fd1b1732c64ed0d39b13cc8ec1fa6 /script/vm/type.lua | |
parent | 4a9ab5b1ae9889e9732b53ad8cdf3b6db5394c3b (diff) | |
download | lua-language-server-76b8cf3236db2efc7f73f3508212d99199b73b52.zip |
limit error message for type dismatch
resolve #1838
Diffstat (limited to 'script/vm/type.lua')
-rw-r--r-- | script/vm/type.lua | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/script/vm/type.lua b/script/vm/type.lua index d01ca020..756926ba 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -301,7 +301,9 @@ function vm.isSubType(uri, child, parent, mark, errs) end end if hasKnownType > 0 then - if errs and hasKnownType > 1 then + if errs + and hasKnownType > 1 + and #vm.getInfer(child):getSubViews(uri) > 1 then errs[#errs+1] = 'TYPE_ERROR_CHILD_ALL_DISMATCH' errs[#errs+1] = child errs[#errs+1] = parent @@ -376,7 +378,9 @@ function vm.isSubType(uri, child, parent, mark, errs) end end if hasKnownType > 0 then - if errs and hasKnownType > 1 then + if errs + and hasKnownType > 1 + and #vm.getInfer(parent):getSubViews(uri) > 1 then errs[#errs+1] = 'TYPE_ERROR_PARENT_ALL_DISMATCH' errs[#errs+1] = child errs[#errs+1] = parent @@ -703,6 +707,7 @@ local ErrorMessageMap = { ---@return string function vm.viewTypeErrorMessage(uri, errs) local lines = {} + local mark = {} local index = 1 while true do local name = errs[index] @@ -741,8 +746,17 @@ function vm.viewTypeErrorMessage(uri, errs) index = index + 1 end local line = lang.script(name, lparams) - lines[#lines+1] = '- ' .. line + if not mark[line] then + mark[line] = true + lines[#lines+1] = '- ' .. line + end end util.revertTable(lines) - return table.concat(lines, '\n') + if #lines > 15 then + lines[13] = ('...(+%d)'):format(#lines - 15) + table.move(lines, #lines - 2, #lines, 14) + return table.concat(lines, '\n', 1, 16) + else + return table.concat(lines, '\n') + end end |