@@ -64,12 +64,10 @@ function META:__tostring()
6464 return str
6565end
6666
67- function META :OnDiagnostic (code , msg , severity , start , stop , node , ...)
68- local t = 0
67+ function META :OnDiagnostic (code , msg , severity , start , stop , node , level , ...)
68+ local t = # self . errors + 1
6969 msg = stringx .replace (msg , " because " , " \n because " )
70-
71- if t > 0 then msg = " \n " .. msg end
72-
70+ msg = formating .FormatMessage (msg , ... )
7371 local messages = {}
7472
7573 if self .analyzer then
@@ -90,19 +88,44 @@ function META:OnDiagnostic(code, msg, severity, start, stop, node, ...)
9088 table.insert (messages , path .. " :" .. info .line_start .. " :" .. info .character_start )
9189 else
9290 for k , v in pairs (v .obj ) do
93- print (k , v )
91+
92+ -- print(k, v)
9493 end
9594 end
9695 end
9796 end
9897 end
9998
100- table.insert (messages , formating .FormatMessage (msg , ... ))
101- local msg = formating .BuildSourceCodePointMessage2 (
102- code :GetString (),
99+ local title = severity
100+
101+ if
102+ level and
103+ self .Config and
104+ self .Config .analyzer and
105+ self .Config .analyzer .show_severity
106+ then
107+ title = severity .. " (" .. level .. " )"
108+ end
109+
110+ table.insert (messages , msg )
111+ local str_code = " unknown code"
112+ local path = " unknown path"
113+
114+ if code then
115+ str_code = code :GetString ()
116+ path = code :GetName ()
117+ end
118+
119+ msg = formating .BuildSourceCodePointMessage2 (
120+ str_code ,
103121 start ,
104122 stop ,
105- {path = code :GetName (), messages = messages , surrounding_line_count = 1 }
123+ {
124+ path = path ,
125+ messages = messages ,
126+ surrounding_line_count = 1 ,
127+ title = title ,
128+ }
106129 ) .. " \n "
107130
108131 if not NATTLUA_MARKDOWN_OUTPUT then
178201function META :Lex ()
179202 local lexer = Lexer (self .Code , self .Config and self .Config .lexer )
180203 lexer .OnError = function (lexer , code , msg , start , stop , ...)
181- self :OnDiagnostic (code , msg , " fatal" , start , stop , nil , ... )
204+ self :OnDiagnostic (code , msg , " fatal" , start , stop , nil , nil , ... )
182205 end
183206 local ok , tokens = xpcall (function ()
184207 return lexer :GetTokens ()
@@ -201,7 +224,7 @@ function META:Parse()
201224
202225 local parser = Parser (self .Tokens , self .Code , self .Config and self .Config .parser )
203226 parser .OnError = function (parser , code , msg , start , stop , ...)
204- self :OnDiagnostic (code , msg , " fatal" , start , stop , nil , ... )
227+ self :OnDiagnostic (code , msg , " fatal" , start , stop , nil , nil , ... )
205228 end
206229 parser .OnPreCreateNode = function (_ , node )
207230 self :OnPreCreateNode (node )
@@ -239,8 +262,8 @@ function META:Analyze(analyzer, ...)
239262 analyzer = analyzer or Analyzer (self .Config and self .Config .analyzer )
240263 analyzer .compiler = self
241264 self .analyzer = analyzer
242- analyzer .OnDiagnostic = function (analyzer , ... )
243- self :OnDiagnostic (... )
265+ analyzer .OnDiagnostic = function (analyzer , code , msg , severity , start , stop , node , level )
266+ self :OnDiagnostic (code , msg , severity , start , stop , node , level )
244267 end
245268
246269 if self .default_environment then
@@ -288,7 +311,7 @@ function META.New(
288311 config --[[ #: CompilerConfig]] ,
289312 level --[[ #: number | nil]]
290313)
291- local path , line , name = callstack .get_path_line (level or 2 )
314+ local path , line , parent_name = callstack .get_path_line (level or 2 )
292315 path = path or " unknown name"
293316 line = line or " unknown line"
294317 name = name or path .. " :" .. line
@@ -305,7 +328,7 @@ function META.New(
305328 return META .NewObject (
306329 {
307330 Code = Code (lua_code , name ),
308- ParentSourceLine = parent_line ,
331+ ParentSourceLine = line ,
309332 ParentSourceName = parent_name ,
310333 Config = config or false ,
311334 Tokens = false ,
0 commit comments