@@ -22,79 +22,85 @@ setmetatable(result, console_popup)
22
22
--- @param hi string
23
23
function result :set_popup_border_hi (hi ) self .popup .border :set_highlight (hi ) end
24
24
25
+ function result :handle_accepted (item )
26
+ local function perc_hi (perc ) return perc >= 50 and " LeetCodeOk" or " LeetCodeError" end
27
+ local group = Group :init ({ opts = { spacing = 2 } })
28
+
29
+ local header = Text :init ()
30
+ header :append (item ._ .title , item ._ .hl )
31
+ group :append (header )
32
+
33
+ -- runtime
34
+ local status_runtime = NuiLine ()
35
+ local runtime_ms = item .display_runtime or vim .split (item .status_runtime , " " )[1 ] or " NIL"
36
+ status_runtime :append (runtime_ms )
37
+ status_runtime :append (" ms" , " Comment" )
38
+
39
+ local perc_runtime = NuiLine ()
40
+ perc_runtime :append (
41
+ " Beats " .. string.format (" %.2f" , item .runtime_percentile ) .. " % " ,
42
+ perc_hi (item .runtime_percentile )
43
+ )
44
+ perc_runtime :append (" of users with " .. item .pretty_lang )
45
+
46
+ local runtime = Pre :init (NuiText (" Runtime" , " LeetCodeNormal" ), {
47
+ status_runtime ,
48
+ perc_runtime ,
49
+ })
50
+ group :append (runtime )
51
+
52
+ -- memory
53
+ local status_memory = NuiLine ()
54
+ local s_mem = vim .split (item .status_memory , " " )
55
+ status_memory :append (s_mem [1 ] .. " " )
56
+ status_memory :append (s_mem [2 ], " Comment" )
57
+
58
+ local perc_mem = NuiLine ()
59
+ perc_mem :append (
60
+ " Beats " .. string.format (" %.2f" , item .memory_percentile ) .. " % " ,
61
+ perc_hi (item .memory_percentile )
62
+ )
63
+ perc_mem :append (" of users with " .. item .pretty_lang )
64
+
65
+ local memory = Pre :init (NuiText (" Memory" , " LeetCodeNormal" ), {
66
+ status_memory ,
67
+ perc_mem ,
68
+ })
69
+ group :append (memory )
70
+
71
+ self .layout :append (group )
72
+ end
73
+
25
74
--- @private
26
75
---
27
76
--- @param item lc.runtime
28
77
function result :handle_runtime (item ) -- status code = 10
78
+ if item ._ .submission then return self :handle_accepted (item ) end
79
+
29
80
local group = Group :init ({ opts = { spacing = 1 } })
30
81
local header = Text :init ()
31
- local is_submission = item .runtime_percentile ~= vim .NIL and item .memory_percentile ~= vim .NIL
32
-
33
- if not is_submission then
34
- local h = NuiLine ()
35
- h :append (item .lcnvim_title , item .lcnvim_hl )
36
- h :append (" | " )
37
- h :append (" Runtime: " .. item .status_runtime , " Comment" )
38
- header :append (h )
39
- group :append (header )
40
-
41
- for i , answer in ipairs (item .code_answer ) do
42
- local passed = item .compare_result :sub (i , i ) == " 1"
43
-
44
- local text = Case :init (
45
- i ,
46
- self .parent .testcase .testcases [i ],
47
- answer ,
48
- item .expected_code_answer [i ],
49
- passed
50
- )
51
- group :append (text )
52
-
53
- local stdout = Stdout :init (item .std_output_list [i ])
54
- if stdout then group :append (stdout ) end
55
- end
56
- else
57
- local function perc_hi (perc ) return perc >= 50 and " LeetCodeOk" or " LeetCodeError" end
58
-
59
- header :append (item .lcnvim_title , item .lcnvim_hl )
60
- group :append (header )
61
-
62
- local status_runtime = NuiLine ()
63
- local runtime_ms = item .display_runtime or vim .split (item .status_runtime , " " )[1 ] or " NIL"
64
- status_runtime :append (runtime_ms )
65
- status_runtime :append (" ms" , " Comment" )
66
82
67
- local perc_runtime = NuiLine ()
68
- perc_runtime :append (
69
- " Beats " .. string.format (" %.2f" , item .runtime_percentile ) .. " % " ,
70
- perc_hi (item .runtime_percentile )
83
+ local h = NuiLine ()
84
+ h :append (item ._ .title , item ._ .hl )
85
+ h :append (" | " )
86
+ h :append (" Runtime: " .. item .status_runtime , " Comment" )
87
+ header :append (h )
88
+ group :append (header )
89
+
90
+ for i , answer in ipairs (item .code_answer ) do
91
+ local passed = item .compare_result :sub (i , i ) == " 1"
92
+
93
+ local text = Case :init (
94
+ i ,
95
+ self .parent .testcase .testcases [i ],
96
+ answer ,
97
+ item .expected_code_answer [i ],
98
+ passed
71
99
)
72
- perc_runtime :append (" of users with " .. item .pretty_lang )
73
-
74
- local runtime = Pre :init (NuiText (" Runtime" ), {
75
- status_runtime ,
76
- perc_runtime ,
77
- })
78
-
79
- local status_memory = NuiLine ()
80
- local s_mem = vim .split (item .status_memory , " " )
81
- status_memory :append (s_mem [1 ] .. " " )
82
- status_memory :append (s_mem [2 ], " Comment" )
83
-
84
- local perc_mem = NuiLine ()
85
- perc_mem :append (
86
- " Beats " .. string.format (" %.2f" , item .memory_percentile ) .. " % " ,
87
- perc_hi (item .memory_percentile )
88
- )
89
- perc_mem :append (" of users with " .. item .pretty_lang )
90
-
91
- local memory = Pre :init (NuiText (" Memory" ), {
92
- status_memory ,
93
- perc_mem ,
94
- })
100
+ group :append (text )
95
101
96
- group : append ( runtime )
97
- group :append (memory )
102
+ local stdout = Stdout : init ( item . std_output_list [ i ] )
103
+ if stdout then group :append (stdout ) end
98
104
end
99
105
100
106
self .layout :append (group )
@@ -104,24 +110,24 @@ end
104
110
---
105
111
--- @param item lc.submission
106
112
function result :handle_submission (item ) -- status code = 11
113
+ local group = Group :init ({ opts = { spacing = 1 } })
114
+
107
115
local header = NuiLine ()
108
- header :append (item .lcnvim_title , item .lcnvim_hl )
116
+ header :append (item ._ . title , item ._ . hl )
109
117
header :append (" | " )
110
118
local testcases =
111
119
string.format (" %d/%d testcases passed" , item .total_correct , item .total_testcases )
112
120
header :append (testcases , " Comment" )
121
+ group :append (Text :init ({ lines = { header } }))
113
122
114
- self .layout :append (Text :init ({ lines = { header , NuiLine () } }))
115
-
116
- local group = Group :init ({ opts = { spacing = 1 } })
117
123
local text = Case :init (
118
124
item .total_correct + 1 ,
119
125
item .input_formatted ,
120
126
item .code_output ,
121
127
item .expected_output
122
128
)
123
-
124
129
group :append (text )
130
+
125
131
if item .std_output then
126
132
local stdout = Stdout :init (item .std_output )
127
133
if stdout then group :append (stdout ) end
@@ -145,7 +151,7 @@ function result:handle_limit_exceeded(item) -- status code = 14
145
151
last_testcase :append (item .last_testcase :gsub (" \n " , " " ), " LeetCodeIndent" )
146
152
147
153
local pre_header = NuiLine ()
148
- pre_header :append (" Last Executed Input" , " " )
154
+ pre_header :append (" Last Executed Input" , " LeetCodeNormal " )
149
155
150
156
local last_exec = Pre :init (pre_header , { last_testcase })
151
157
group :append (last_exec )
@@ -179,17 +185,22 @@ function result:handle_runtime_error(item) -- status code = 15
179
185
end
180
186
181
187
function result :handle_internal_error (item ) -- status code = 16
182
- local header = NuiLine ()
183
- header :append (item .lcnvim_title , item .lcnvim_hl )
188
+ local group = Group :init ({ opts = { spacing = 1 } })
184
189
190
+ local header = NuiLine ()
191
+ header :append (item ._ .title , item ._ .hl )
185
192
local text = Text :init ({ lines = { header } })
186
- self .layout :append (text )
193
+ group :append (text )
194
+
195
+ self .layout :append (group )
187
196
end
188
197
189
198
--- @private
190
199
---
191
200
--- @param item lc.compile_error
192
201
function result :handle_compile_error (item ) -- status code = 20
202
+ local group = Group :init ({ opts = { spacing = 1 } })
203
+
193
204
local header = NuiLine ()
194
205
header :append (item ._ .title , item ._ .hl )
195
206
@@ -198,7 +209,8 @@ function result:handle_compile_error(item) -- status code = 20
198
209
table.insert (t , NuiLine ():append (line , " LeetCodeError" ))
199
210
end
200
211
201
- self .layout :append (Pre :init (header , t ))
212
+ group :append (Pre :init (header , t ))
213
+ self .layout :append (group )
202
214
end
203
215
204
216
--- @param item lc.interpreter_response
@@ -208,17 +220,18 @@ function result:handle_item(item)
208
220
local success = false
209
221
if item .status_code == 10 then
210
222
success = item .compare_result :match (" ^[1]+$" ) and true or false
223
+ item .status_msg = success and " Accepted" or " Wrong Answer"
211
224
end
225
+
212
226
local submission = not item .submission_id :find (" runcode" ) and true or false
213
227
local hl = success and " LeetCodeOk" or " LeetCodeError"
214
228
215
229
item ._ = {
216
- title = item .status_msg ,
230
+ title = " " .. item .status_msg ,
217
231
hl = hl ,
218
232
success = success ,
219
233
submission = submission ,
220
234
}
221
- log .info (item )
222
235
223
236
return item
224
237
end
0 commit comments