@@ -5,64 +5,84 @@ local NuiText = require("nui.text")
55
66local M = {}
77
8- function M .render_exceptions_to_buf (buf , exception_chain )
8+ function M .render_exception_to_buf (buf , exception , start_line )
9+ start_line = start_line or 0
10+
911 vim .api .nvim_set_option_value (" filetype" , " clojure" , {
1012 buf = buf ,
1113 })
12- vim .api .nvim_buf_set_lines (buf , 0 , - 1 , false , {})
14+ vim .api .nvim_buf_set_lines (buf , start_line , - 1 , false , {})
1315
1416 local lines = {}
1517
16- for _ , ex in ipairs (utils .reverse_table (exception_chain )) do
17- local exception_title = NuiLine ()
18- exception_title :append (ex [" class-name" ], " Error" )
19- exception_title :append (" : " , " Comment" )
18+ local exception_title = NuiLine ()
19+ exception_title :append (exception [" class-name" ], " Error" )
20+ exception_title :append (" : " , " Comment" )
2021
21- local title_lines = vim .split (ex .message , " \n " )
22- exception_title :append (title_lines [1 ], " TSParameter" )
22+ local title_lines = vim .split (exception .message , " \n " )
23+ exception_title :append (title_lines [1 ], " TSParameter" )
2324
24- table.insert (lines , exception_title )
25- table.remove (title_lines , 1 )
25+ table.insert (lines , exception_title )
26+ table.remove (title_lines , 1 )
2627
27- for _ , content in ipairs (title_lines ) do
28- table.insert (lines , NuiLine ({ NuiText (content , " TSParameter" ) }))
29- end
28+ for _ , content in ipairs (title_lines ) do
29+ table.insert (lines , NuiLine ({ NuiText (content , " TSParameter" ) }))
30+ end
3031
31- local stack_trace = ex [" stack-trace" ]
32- if stack_trace and stack_trace ~= vim .NIL then
33- for _ , frame in ipairs (stack_trace ) do
34- if frame .name and frame .name ~= " " then
35- local namespace_and_names = vim .split (frame .name , " /" )
36- local names = table.concat (namespace_and_names , " /" , 2 )
37-
38- local frame_line = NuiLine ()
39- frame_line :append (" " )
40- frame_line :append (namespace_and_names [1 ], " TSNamespace" )
41- frame_line :append (" /" , " TSMethodCall" )
42- frame_line :append (names , " TsMethodCall" )
43-
44- if frame .line and frame .line ~= vim .NIL then
45- frame_line :append (" @ " , " Comment" )
46- frame_line :append (tostring (frame .line ), " TSNumber" )
47- end
48-
49- table.insert (lines , frame_line )
32+ local stack_trace = exception [" stack-trace" ]
33+ if stack_trace and stack_trace ~= vim .NIL then
34+ for _ , frame in ipairs (stack_trace ) do
35+ if frame .name and frame .name ~= " " then
36+ local namespace_and_names = vim .split (frame .name , " /" )
37+ local names = table.concat (namespace_and_names , " /" , 2 )
38+
39+ local frame_line = NuiLine ()
40+ frame_line :append (" " )
41+ frame_line :append (namespace_and_names [1 ], " TSNamespace" )
42+ frame_line :append (" /" , " TSMethodCall" )
43+ frame_line :append (names , " TsMethodCall" )
44+
45+ if frame .line and frame .line ~= vim .NIL then
46+ frame_line :append (" @ " , " Comment" )
47+ frame_line :append (tostring (frame .line ), " TSNumber" )
5048 end
49+
50+ table.insert (lines , frame_line )
5151 end
5252 end
53+ end
5354
54- if ex .properties and ex .properties ~= vim .NIL then
55- table.insert (lines , NuiLine ())
55+ if exception .properties and exception .properties ~= vim .NIL then
56+ table.insert (lines , NuiLine ())
5657
57- for _ , content in ipairs (vim .split (ex .properties , " \n " )) do
58- table.insert (lines , NuiLine ({ NuiText (content ) }))
59- end
58+ for _ , content in ipairs (vim .split (exception .properties , " \n " )) do
59+ table.insert (lines , NuiLine ({ NuiText (content ) }))
6060 end
6161 end
6262
6363 for i , line in ipairs (lines ) do
64- line :render (buf , - 1 , i )
64+ line :render (buf , - 1 , start_line + i )
6565 end
66+
67+ return # lines
68+ end
69+
70+ function M .render_exceptions_to_buf (buf , exception_chain , start_line )
71+ start_line = start_line or 0
72+
73+ vim .api .nvim_set_option_value (" filetype" , " clojure" , {
74+ buf = buf ,
75+ })
76+ vim .api .nvim_buf_set_lines (buf , start_line , - 1 , false , {})
77+
78+ local total_lines = 0
79+
80+ for _ , ex in ipairs (utils .reverse_table (exception_chain )) do
81+ local lines = M .render_exception_to_buf (buf , ex , start_line + total_lines )
82+ total_lines = total_lines + lines
83+ end
84+
85+ return total_lines
6686end
6787
6888return M
0 commit comments