Skip to content

Commit 23db2ff

Browse files
committed
move ErrorMessageToString to error_messages
1 parent 85ed49d commit 23db2ff

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

language_server/editor_helper.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,10 @@ function META:Recompile(path, lol, diagnostics)
218218

219219
function compiler.OnDiagnostic(_, code, msg, severity, start, stop, node, ...)
220220
local name = code:GetName()
221+
local str_msg = formating.FormatMessage(msg, ...)
221222

222223
if severity == "fatal" then
223-
self:DebugLog("[ " .. entry_point .. " ] " .. formating.FormatMessage(msg, ...))
224+
self:DebugLog("[ " .. entry_point .. " ] " .. str_msg)
224225
end
225226

226227
diagnostics[name] = diagnostics[name] or {}
@@ -231,7 +232,7 @@ function META:Recompile(path, lol, diagnostics)
231232
code = code,
232233
start = start,
233234
stop = stop,
234-
message = formating.FormatMessage(msg, ...),
235+
message = str_msg,
235236
trace = debug.traceback(),
236237
}
237238
)

nattlua/analyzer/base/error_handling.lua

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local io = io
66
local debug = debug
77
local error = error
88
local Any = require("nattlua.types.any").Any
9+
local error_messages = require("nattlua.error_messages")
910
local math_abs = math.abs
1011
local assert = _G.assert
1112
return function(META)
@@ -81,28 +82,10 @@ return function(META)
8182

8283
function META:ErrorAssert(ok, err)
8384
if not ok then
84-
error(self:ErrorMessageToString(err or "assertion failed!"), 2)
85+
error(error_messages.ErrorMessageToString(err or "assertion failed!"), 2)
8586
end
8687
end
8788

88-
function META:ErrorMessageToString(tbl)
89-
local out = {}
90-
91-
for i, v in ipairs(tbl) do
92-
if type(v) == "table" then
93-
if v.Type then
94-
table.insert(out, tostring(v))
95-
else
96-
table.insert(out, self:ErrorMessageToString(v))
97-
end
98-
else
99-
table.insert(out, tostring(v))
100-
end
101-
end
102-
103-
return table.concat(out, " ")
104-
end
105-
10689
function META:ReportDiagnostic(
10790
msg--[[#: {reasons = {[number] = string}} | {[number] = string}]],
10891
severity--[[#: "warning" | "error"]],
@@ -123,7 +106,7 @@ return function(META)
123106
print(debug.traceback())
124107
end
125108

126-
local msg_str = self:ErrorMessageToString(msg)
109+
local msg_str = error_messages.ErrorMessageToString(msg)
127110

128111
if self.processing_deferred_calls then
129112
msg_str = "DEFERRED CALL: " .. msg_str

nattlua/error_messages.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,30 @@ local table = _G.table
33
local type = _G.type
44
local ipairs = _G.ipairs
55
local table_insert = table.insert
6+
local table_concat = table.concat
7+
local tostring = _G.tostring
68
local callstack = require("nattlua.other.callstack")
79
local error_messages = {}
810
--[[#local type Reason = string | {[number] = any | string}]]
911

12+
function error_messages.ErrorMessageToString(tbl--[[#: List<|string | Reason|>]])--[[#: string]]
13+
local out = {}
14+
15+
for i, v in ipairs(tbl) do
16+
if type(v) == "table" then
17+
if v.Type then
18+
table_insert(out, tostring(v))
19+
else
20+
table_insert(out, error_messages.ErrorMessageToString(v))
21+
end
22+
else
23+
table_insert(out, tostring(v))
24+
end
25+
end
26+
27+
return table_concat(out, " ")
28+
end
29+
1030
function error_messages.because(msg--[[#: Reason]], reason--[[#: nil | Reason]])--[[#: Reason]]
1131
if type(msg) ~= "table" then msg = {msg} end
1232

0 commit comments

Comments
 (0)