Skip to content

Commit 9e66c95

Browse files
committed
feat(console): extmarks per line
1 parent f114abc commit 9e66c95

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

lua/leetcode-ui/popup/console/testcase.lua

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,34 @@ function Testcase:draw_extmarks()
7272

7373
if not md.params then return end
7474

75-
local max_lens = {}
76-
local j, k = 1, 1
77-
for _, line in ipairs(lines) do
78-
if line == "" then k = k + 1 end
79-
max_lens[k] = math.max(max_lens[k] or 1, line:len() + 1)
80-
end
81-
82-
local function get_param(idx, param_idx, len)
75+
local j = 1
76+
local function get_param(idx)
8377
return {
84-
{ (" "):rep(max_lens[idx] - len) },
78+
{ (" "):rep(2) },
8579
{ "", "Operator" },
8680
{ " " },
87-
{ md.params[param_idx].name, "Comment" },
81+
{ md.params[idx].name, "Comment" },
8882
{ " " },
89-
{ md.params[param_idx].type, "Type" },
83+
{ md.params[idx].type, "Type" },
9084
}
9185
end
9286

9387
local invalid = false
94-
k = 1
9588

9689
for i, line in ipairs(lines) do
9790
pcall(function()
9891
if lines[i - 1] == "" and lines[i] == "" then invalid = true end
9992
end)
10093

10194
if line ~= "" then
102-
local ok, text = pcall(get_param, k, j, line:len())
95+
local ok, text = pcall(get_param, j)
10396
if not ok or invalid then
104-
text = { { (" %s"):format(t("invalid")), "leetcode_error" } }
97+
text = { { (" "):rep(2) }, { (" %s"):format(t("invalid")), "leetcode_error" } }
10598
end
10699

107100
self:add_extmark(i - 1, -1, { virt_text = text })
108101
j = j + 1
109102
else
110-
k = k + 1
111103
j = 1
112104
end
113105
end

0 commit comments

Comments
 (0)