Skip to content

Commit 4503eff

Browse files
committed
cleanup
1 parent 4e8b4f2 commit 4503eff

File tree

11 files changed

+141
-116
lines changed

11 files changed

+141
-116
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
168168

169169
[#1153]: https://github.com/sumneko/lua-language-server/issues/1153
170170
[#1177]: https://github.com/sumneko/lua-language-server/issues/1177
171+
[#1201]: https://github.com/sumneko/lua-language-server/issues/1201
171172
[#1202]: https://github.com/sumneko/lua-language-server/issues/1202
172173
[#1332]: https://github.com/sumneko/lua-language-server/issues/1332
173174
[#1344]: https://github.com/sumneko/lua-language-server/issues/1344

locale/en-us/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ DIAG_REDUNDANT_RETURN_VALUE_RANGE =
139139
DIAG_MISSING_RETURN =
140140
'Return value is required here.'
141141
DIAG_RETURN_TYPE_MISMATCH =
142-
'The type of the {index} return value is `{def}`, but the actual return is `{ref}`.'
142+
'The type of the {index} return value is `{def}`, but the actual return is `{ref}`.\n{err}'
143143
DIAG_UNKNOWN_OPERATOR =
144144
'Unknown operator `{}`.'
145145
DIAG_UNREACHABLE_CODE =

locale/pt-br/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ DIAG_REDUNDANT_RETURN_VALUE_RANGE = -- TODO: need translate!
139139
DIAG_MISSING_RETURN = -- TODO: need translate!
140140
'Return value is required here.'
141141
DIAG_RETURN_TYPE_MISMATCH = -- TODO: need translate!
142-
'The type of the {index} return value is `{def}`, but the actual return is `{ref}`.'
142+
'The type of the {index} return value is `{def}`, but the actual return is `{ref}`.\n{err}'
143143
DIAG_UNKNOWN_OPERATOR = -- TODO: need translate!
144144
'Unknown operator `{}`.'
145145
DIAG_UNREACHABLE_CODE = -- TODO: need translate!

locale/zh-cn/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ DIAG_REDUNDANT_RETURN_VALUE_RANGE =
139139
DIAG_MISSING_RETURN =
140140
'此处需要返回值。'
141141
DIAG_RETURN_TYPE_MISMATCH =
142-
'第 {index} 个返回值的类型为 `{def}` ,但实际返回的是 `{ref}`。'
142+
'第 {index} 个返回值的类型为 `{def}` ,但实际返回的是 `{ref}`。\n{err}'
143143
DIAG_UNKNOWN_OPERATOR =
144144
'未知的运算符 `{}`。'
145145
DIAG_UNREACHABLE_CODE =

locale/zh-tw/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ DIAG_REDUNDANT_RETURN_VALUE_RANGE =
139139
DIAG_MISSING_RETURN =
140140
'此處需要回傳值。'
141141
DIAG_RETURN_TYPE_MISMATCH =
142-
'第 {index} 個回傳值的類型為 `{def}` ,但實際回傳的是 `{ref}`。'
142+
'第 {index} 個回傳值的類型為 `{def}` ,但實際回傳的是 `{ref}`。\n{err}'
143143
DIAG_UNKNOWN_OPERATOR = -- TODO: need translate!
144144
'Unknown operator `{}`.'
145145
DIAG_UNREACHABLE_CODE = -- TODO: need translate!

script/core/diagnostics/assign-type-mismatch.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ return function (uri, callback)
9696
end
9797

9898
local varNode = vm.compileNode(source)
99-
local suc, errs = vm.canCastType(uri, varNode, valueNode)
100-
if suc then
99+
local errs = {}
100+
if vm.canCastType(uri, varNode, valueNode, errs) then
101101
return
102102
end
103103

@@ -108,8 +108,6 @@ return function (uri, callback)
108108
end
109109
end
110110

111-
assert(errs)
112-
113111
callback {
114112
start = source.start,
115113
finish = source.finish,

script/core/diagnostics/cast-local-type.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ return function (uri, callback)
3434
refNode = refNode:copy():setTruthy()
3535
end
3636

37-
local suc, errs = vm.canCastType(uri, locNode, refNode)
38-
39-
if not suc then
40-
assert(errs)
37+
local errs = {}
38+
if not vm.canCastType(uri, locNode, refNode, errs) then
4139
callback {
4240
start = ref.start,
4341
finish = ref.finish,

script/core/diagnostics/cast-type-mismatch.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ return function (uri, callback)
2626
for _, cast in ipairs(doc.casts) do
2727
if not cast.mode and cast.extends then
2828
local refNode = vm.compileNode(cast.extends)
29-
local suc, errs = vm.canCastType(uri, defNode, refNode)
30-
if not suc then
29+
local errs = {}
30+
if not vm.canCastType(uri, defNode, refNode, errs) then
3131
assert(errs)
3232
callback {
3333
start = cast.extends.start,

script/core/diagnostics/param-type-mismatch.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ return function (uri, callback)
100100
-- 因此将假值移除再进行检查
101101
refNode = refNode:copy():setTruthy()
102102
end
103-
local suc, errs = vm.canCastType(uri, defNode, refNode)
104-
if not suc then
103+
local errs = {}
104+
if not vm.canCastType(uri, defNode, refNode, errs) then
105105
local rawDefNode = getRawDefNode(funcNode, i)
106106
assert(errs)
107107
callback {

script/core/diagnostics/return-type-mismatch.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ return function (uri, callback)
6161
retNode = retNode:copy():removeOptional()
6262
end
6363
end
64-
if not vm.canCastType(uri, docRet, retNode) then
64+
local errs = {}
65+
if not vm.canCastType(uri, docRet, retNode, errs) then
6566
callback {
6667
start = exp.start,
6768
finish = exp.finish,
6869
message = lang.script('DIAG_RETURN_TYPE_MISMATCH', {
6970
def = vm.getInfer(docRet):view(uri),
7071
ref = vm.getInfer(retNode):view(uri),
72+
err = vm.viewTypeErrorMessage(uri, errs),
7173
index = i,
7274
}),
7375
}

0 commit comments

Comments
 (0)