summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-30 20:04:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-30 20:04:02 +0800
commit76b8cf3236db2efc7f73f3508212d99199b73b52 (patch)
tree25c028edc02fd1b1732c64ed0d39b13cc8ec1fa6 /script/vm
parent4a9ab5b1ae9889e9732b53ad8cdf3b6db5394c3b (diff)
downloadlua-language-server-76b8cf3236db2efc7f73f3508212d99199b73b52.zip
limit error message for type dismatch
resolve #1838
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/infer.lua9
-rw-r--r--script/vm/ref.lua3
-rw-r--r--script/vm/type.lua22
3 files changed, 30 insertions, 4 deletions
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index 0b20700c..2f482116 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -11,6 +11,7 @@ local vm = require 'vm.vm'
---@field _lastView? string
---@field _lastViewUri? uri
---@field _lastViewDefault? any
+---@field _subViews? string[]
local mt = {}
mt.__index = mt
mt._hasTable = false
@@ -413,6 +414,7 @@ function mt:view(uri, default)
end
local array = {}
+ self._subViews = array
for view in pairs(self.views) do
if not self._drop[view] then
array[#array+1] = view
@@ -471,6 +473,13 @@ function mt:eachView(uri)
return next, self.views
end
+---@param uri uri
+---@return string[]
+function mt:getSubViews(uri)
+ self:view(uri)
+ return self._subViews
+end
+
---@return string?
function mt:viewLiterals()
if not self.node then
diff --git a/script/vm/ref.lua b/script/vm/ref.lua
index ba9bf453..b6760493 100644
--- a/script/vm/ref.lua
+++ b/script/vm/ref.lua
@@ -29,7 +29,10 @@ simpleSwitch = util.switch()
---@async
local function searchInAllFiles(suri, searcher, notify)
+ await.delay()
+
searcher(suri)
+ await.delay()
local uris = {}
for uri in files.eachFile(suri) do
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