Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0a801bb

Browse files
committed
feat(result): improved time limit error handler
1 parent 1027bee commit 0a801bb

File tree

8 files changed

+144
-120
lines changed

8 files changed

+144
-120
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ To see full configuration types see [template.lua](./lua/leetcode/config/templat
139139
height = "75%", ---@type string | integer
140140
},
141141
dir = "row", ---@type "col" | "row"
142-
143-
result = {
144-
max_stdout_length = 200, ---@type integer
145-
},
146142
},
147143

148144
description = {
@@ -215,10 +211,6 @@ console = {
215211
height = "75%", ---@type string | integer
216212
},
217213
dir = "row", ---@type "col" | "row"
218-
219-
result = {
220-
max_stdout_length = 200, ---@type integer
221-
},
222214
}
223215
```
224216

lua/leetcode/api/interpreter.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function interpreter.interpret_solution(title_slug, body, callback)
5757

5858
local url = string.format(config.domain .. "/problems/%s/interpret_solution/", title_slug)
5959

60-
---@type boolean, submission
60+
---@type boolean, lc.submission
6161
local ok, res = pcall(utils.post, url, body)
6262
if not ok then return end
6363

@@ -69,7 +69,7 @@ function interpreter.submit(title_slug, body, callback)
6969

7070
local url = string.format(config.domain .. "/problems/%s/submit/", title_slug)
7171

72-
---@type boolean, submission
72+
---@type boolean, lc.submission
7373
local ok, res = pcall(utils.post, url, body)
7474
if not ok then return end
7575

lua/leetcode/api/types.lua

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---@field interpret_id string
33
---@field test_case string
44

5-
---@alias submission lc.Interpreter.Submission
5+
---@alias lc.submission lc.Interpreter.Submission
66

77
---@alias interpret.state
88
---| "PENDING"
@@ -64,7 +64,7 @@
6464
---@field status_msg string
6565
---@field state string
6666

67-
---@alias runtime_error lc.Interpreter.Response.runtime_error
67+
---@alias lc.runtime_error lc.Interpreter.Response.runtime_error
6868

6969
--------------------------------------------
7070
--- Runtime | 10
@@ -104,8 +104,11 @@
104104
---@field submission_id string
105105
---@field status_msg string
106106
---@field state string
107+
---@field lcnvim_is_submission boolean
108+
---@field lcnvim_title string
109+
---@field lcnvim_hl string
107110

108-
---@alias runtime lc.Interpreter.Response.runtime
111+
---@alias lc.runtime lc.Interpreter.Response.runtime
109112

110113
--------------------------------------------
111114
--- Compile Error | 20
@@ -133,34 +136,63 @@
133136
---@field status_msg string
134137
---@field state string
135138

136-
---@alias compile_error lc.Interpreter.Response.compile_error
139+
---@alias lc.compile_error lc.Interpreter.Response.compile_error
137140

138141
--------------------------------------------
139142
--- Time Limit Exceeded | 13, 14
140143
--------------------------------------------
144+
-- -@class lc.Interpreter.Response.limit.exceeded
145+
-- -@field code_answer table
146+
-- -@field code_output table
147+
-- -@field elapsed_time integer
148+
-- -@field lang string
149+
-- -@field memory number
150+
-- -@field memory_percentile number | nil
151+
-- -@field pretty_lang string
152+
-- -@field run_success boolean
153+
-- -@field runtime_percentile number | nil
154+
-- -@field state string
155+
-- -@field status_code number
156+
-- -@field status_memory string
157+
-- -@field status_msg string
158+
-- -@field status_runtime string
159+
-- -@field std_output_list table
160+
-- -@field std_output string
161+
-- -@field submission_id string
162+
-- -@field task_finish_time number
163+
-- -@field task_name string
164+
-- -@field total_correct number | nil
165+
-- -@field total_testcases number | nil
166+
141167
---@class lc.Interpreter.Response.limit.exceeded
142-
---@field code_answer table
143-
---@field code_output table
144-
---@field elapsed_time integer
168+
---@field status_code number
145169
---@field lang string
146-
---@field memory number
147-
---@field memory_percentile number | nil
148-
---@field pretty_lang string
149170
---@field run_success boolean
150-
---@field runtime_percentile number | nil
151-
---@field state string
152-
---@field status_code number
153-
---@field status_memory string
154-
---@field status_msg string
155171
---@field status_runtime string
172+
---@field memory number
173+
---@field code_answer table
174+
---@field code_output table
156175
---@field std_output_list table
157-
---@field submission_id string
176+
---@field std_output string
158177
---@field task_finish_time number
159178
---@field task_name string
160179
---@field total_correct number | nil
161180
---@field total_testcases number | nil
181+
---@field runtime_percentile number | nil
182+
---@field status_memory string
183+
---@field memory_percentile number | nil
184+
---@field pretty_lang string
185+
---@field submission_id string
186+
---@field status_msg string
187+
---@field state string
188+
---@field compare_result string | nil
189+
---@field question_id string | nil
190+
---@field elapsed_time number | nil
191+
---@field last_testcase string | nil
192+
---@field expected_output string | nil
193+
---@field finished boolean | nil
162194

163-
---@alias limit_exceeded_error lc.Interpreter.Response.limit.exceeded
195+
---@alias lc.limit_exceeded_error lc.Interpreter.Response.limit.exceeded
164196

165197
--------------------------------------------
166198
--- Time Limit Exceeded | 13, 14
@@ -170,17 +202,17 @@
170202
---@field status_msg string
171203
---@field state interpret.state
172204

173-
---@alias internal_error lc.Interpreter.Response.internal.error
205+
---@alias lc.internal_error lc.Interpreter.Response.internal.error
174206

175207
--------------------------------------------
176208
--- Interpreter responses
177209
--------------------------------------------
178-
---@alias interpreter_response
179-
---| runtime
180-
---| runtime_error
181-
---| compile_error
182-
---| limit_exceeded_error
183-
---| internal_error
210+
---@alias lc.interpreter_response
211+
---| lc.runtime
212+
---| lc.runtime_error
213+
---| lc.compile_error
214+
---| lc.limit_exceeded_error
215+
---| lc.internal_error
184216

185217
--------------------------------------------
186218
--- Code snipppet
@@ -283,4 +315,4 @@
283315
---@field status_msg string
284316
---@field state string
285317

286-
---@alias submission lc.Interpreter.Response.submission
318+
---@alias lc.submission lc.Interpreter.Response.submission

lua/leetcode/config/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local config = {
77

88
name = "leetcode.nvim",
99
domain = "https://leetcode.com",
10-
debug = false,
10+
debug = true,
1111
lang = "cpp",
1212
}
1313

lua/leetcode/config/template.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ local M = {
5555
height = "75%", ---@type string | integer
5656
},
5757
dir = "row", ---@type "col" | "row"
58-
59-
result = {
60-
max_stdout_length = 200, ---@type integer
61-
},
6258
},
6359

6460
description = {

lua/leetcode/runner/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function runner:run(submit)
3535
end
3636

3737
---@private
38-
---@param item interpreter_response
38+
---@param item lc.interpreter_response
3939
function runner:callback(item) self.question.console.result:handle(item) end
4040

4141
---@param question lc.Question

lua/leetcode/ui/console/components/stdout.lua

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
local config = require("leetcode.config")
2-
local NuiLine = require("nui.line")
3-
local log = require("leetcode.logger")
42
local Pre = require("leetcode.ui.console.components.pre")
53

4+
local NuiLine = require("nui.line")
5+
66
local stdout = {}
77

8-
---@param item interpreter_response
9-
---@param case_idx integer
8+
---@param output string
109
---
1110
---@return lc-ui.Text | nil
12-
function stdout:init(case_idx, item)
13-
if not item.std_output_list then item.std_output_list = { [case_idx] = item.std_output } end
14-
15-
if item.std_output_list[case_idx] == "" then return nil end
16-
17-
local output_list = vim.split(item.std_output_list[case_idx], "\n", { trimempty = true })
18-
local max_stdout_len = config.user.console.result.max_stdout_length
19-
local stdout_len = #output_list
11+
function stdout:init(output)
12+
local output_list = vim.split(output, "\n", { trimempty = true })
2013

2114
local t = {}
22-
for i = 1, math.min(max_stdout_len, stdout_len), 1 do
15+
for i = 1, #output_list, 1 do
2316
table.insert(t, NuiLine():append(output_list[i]))
2417
end
2518

26-
if stdout_len > max_stdout_len then
27-
local diff = stdout_len - max_stdout_len
28-
table.insert(t, NuiLine():append("" .. diff .. " more lines"))
29-
end
30-
3119
return Pre:init(NuiLine():append(" Stdout", "Comment"), t)
3220
end
3321

0 commit comments

Comments
 (0)