irongit

A Neovim plugin enabling you to solve LeetCode problems.

refactor(stylua): disable `collapse_simple_statement`

kawreauthored
parent b44c5e5commit 144c5b655ea3d21687d9e26943897bdc77583f3eBrowse files

65 files changed, +971 -385

+0-2.stylua.toml
@@ -4,5 +4,3 @@ indent_type = "Spaces"
44 indent_width = 4
55 quote_style = "ForceDouble"
66 call_parentheses = "Always"
7-# collapse_simple_statement = "FunctionOnly"
8-collapse_simple_statement = "Always"
+12-4lua/leetcode-plugins/cn/api.lua
@@ -17,7 +17,9 @@ statistics.solved = function(cb) ---@diagnostic disable-line
1717 utils.query(query, variables, {
1818 endpoint = urls.solved,
1919 callback = function(res, err)
20- if err then return cb(nil, err) end
20+ if err then
21+ return cb(nil, err)
22+ end
2123
2224 local data = res.data
2325 local submit_stats = data["submit_stats"]
@@ -38,7 +40,9 @@ statistics.session_progress = function(cb)
3840
3941 utils.query(query, variables, {
4042 callback = function(res, err)
41- if err then return cb(nil, err) end
43+ if err then
44+ return cb(nil, err)
45+ end
4246
4347 local data = res.data
4448 local session_progress = data["userProfileUserQuestionProgress"]["numAcceptedQuestions"]
@@ -57,7 +61,9 @@ statistics.calendar = function(cb) ---@diagnostic disable-line
5761 utils.query(query, variables, {
5862 endpoint = urls.calendar,
5963 callback = function(res, err)
60- if err then return cb(nil, err) end
64+ if err then
65+ return cb(nil, err)
66+ end
6167
6268 local data = res.data
6369 local calendar = data["calendar"]
@@ -83,7 +89,9 @@ statistics.languages = function(cb) ---@diagnostic disable-line
8389 utils.query(query, variables, {
8490 endpoint = urls.languages,
8591 callback = function(res, err)
86- if err then return cb(nil, err) end
92+ if err then
93+ return cb(nil, err)
94+ end
8795
8896 local data = res.data
8997 local lang_prob_count = data["languageProblemCount"]
+3-1lua/leetcode-plugins/cn/utils.lua
@@ -3,7 +3,9 @@ local log = require("leetcode.logger")
33 local cn_utils = {}
44
55 ---@param str string
6-local function capitalizeFirst(str) return str:lower():gsub("^%l", string.upper) end
6+local function capitalizeFirst(str)
7+ return str:lower():gsub("^%l", string.upper)
8+end
79
810 ---@return table
911 function cn_utils.calc_question_count(stats)
+12-6lua/leetcode-plugins/non_standalone/leetcode.lua
@@ -7,10 +7,14 @@ local prev_cwd = nil
77 ---@param on_vimenter boolean
88 leetcode.should_skip = function(on_vimenter)
99 if on_vimenter then
10- if vim.fn.argc() ~= 1 then return true end
10+ if vim.fn.argc() ~= 1 then
11+ return true
12+ end
1113
1214 local usr_arg, arg = vim.fn.argv()[1], config.user.arg
13- if usr_arg ~= arg then return true end
15+ if usr_arg ~= arg then
16+ return true
17+ end
1418
1519 local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
1620 if #lines > 1 or (#lines == 1 and lines[1]:len() > 0) then
@@ -21,7 +25,7 @@ leetcode.should_skip = function(on_vimenter)
2125 else
2226 for _, buf_id in pairs(vim.api.nvim_list_bufs()) do
2327 local bufinfo = vim.fn.getbufinfo(buf_id)[1]
24- if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then --
28+ if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then
2529 return false, true
2630 end
2731 end
@@ -33,7 +37,7 @@ end
3337 ---@param on_vimenter boolean
3438 leetcode.start = function(on_vimenter)
3539 local skip, buflisted = leetcode.should_skip(on_vimenter)
36- if skip then --
40+ if skip then
3741 return false
3842 end
3943
@@ -44,7 +48,7 @@ leetcode.start = function(on_vimenter)
4448 local theme = require("leetcode.theme")
4549 theme.setup()
4650
47- if not on_vimenter then --
51+ if not on_vimenter then
4852 if buflisted then
4953 prev_cwd = vim.fn.getcwd()
5054 vim.cmd.tabe()
@@ -67,7 +71,9 @@ leetcode.start = function(on_vimenter)
6771 end
6872
6973 leetcode.stop = vim.schedule_wrap(function()
70- if standalone then return vim.cmd("qa!") end
74+ if standalone then
75+ return vim.cmd("qa!")
76+ end
7177
7278 _Lc_state.menu:unmount()
7379
+9-3lua/leetcode-ui/group/cases.lua
@@ -20,13 +20,17 @@ function Cases:make_nav()
2020 local nav = Lines({}, { padding = { top = 1 } })
2121
2222 for i, case in ipairs(self.cases) do
23- self.console.result:map("n", i, function() self:change(i) end, { clearable = true })
23+ self.console.result:map("n", i, function()
24+ self:change(i)
25+ end, { clearable = true })
2426
2527 local hl = self:nav_case_hl(case, i)
2628 local msg = (" Case (%d) "):format(i)
2729
2830 nav:append(msg, hl)
29- if i ~= #self.cases then nav:append(" ") end
31+ if i ~= #self.cases then
32+ nav:append(" ")
33+ end
3034 end
3135
3236 return nav
@@ -43,7 +47,9 @@ end
4347
4448 ---@param idx integer
4549 function Cases:change(idx)
46- if not self.cases[idx] or idx == self.idx then return end
50+ if not self.cases[idx] or idx == self.idx then
51+ return
52+ end
4753
4854 self.idx = idx
4955 self.console.result:draw()
+16-6lua/leetcode-ui/group/init.lua
@@ -36,7 +36,9 @@ function Group:contents()
3636 local items = utils.shallowcopy(self._.items)
3737
3838 local contents = Group.super.contents(self)
39- if not vim.tbl_isempty(contents) then table.insert(items, Lines(contents)) end
39+ if not vim.tbl_isempty(contents) then
40+ table.insert(items, Lines(contents))
41+ end
4042
4143 return items
4244 end
@@ -51,27 +53,35 @@ function Group:draw(layout, opts)
5153 local toppad = padding and padding.top
5254 local botpad = padding and padding.bot
5355
54- if toppad then Pad(toppad):draw(layout) end
56+ if toppad then
57+ Pad(toppad):draw(layout)
58+ end
5559
5660 local items = self:contents()
5761 for i, item in ipairs(items) do
5862 item:draw(layout, options:get())
59- if i ~= #items and spacing then Pad(spacing):draw(layout) end
63+ if i ~= #items and spacing then
64+ Pad(spacing):draw(layout)
65+ end
6066 end
6167
62- if botpad then Pad(botpad):draw(layout) end
68+ if botpad then
69+ Pad(botpad):draw(layout)
70+ end
6371 end
6472
6573 ---@param item lc.ui.Lines
6674 function Group:insert(item)
67- if not vim.tbl_isempty(Group.super.contents(self)) then self:endgrp() end
75+ if not vim.tbl_isempty(Group.super.contents(self)) then
76+ self:endgrp()
77+ end
6878 table.insert(self._.items, item)
6979
7080 return self
7181 end
7282
7383 function Group:append(content, highlight)
74- if type(content) == "table" and O.is_instance(content, Group) then --
84+ if type(content) == "table" and O.is_instance(content, Group) then
7585 local items = content:contents()
7686
7787 for _, item in ipairs(items) do
+3-1lua/leetcode-ui/group/page/cache.lua
@@ -18,7 +18,9 @@ page:insert(Title({ "Menu" }, "Cache"))
1818 local update_btn = Button("Update", {
1919 icon = "󱘴",
2020 sc = "u",
21- on_press = function() cmd.cache_update() end,
21+ on_press = function()
22+ cmd.cache_update()
23+ end,
2224 })
2325
2426 local back_btn = BackButton("menu")
+12-4lua/leetcode-ui/group/page/menu.lua
@@ -18,28 +18,36 @@ page:insert(Title({}, "Menu"))
1818 local problems = Button("Problems", {
1919 icon = "",
2020 sc = "p",
21- on_press = function() cmd.set_menu_page("problems") end,
21+ on_press = function()
22+ cmd.set_menu_page("problems")
23+ end,
2224 expandable = true,
2325 })
2426
2527 local statistics = Button("Statistics", {
2628 icon = "󰄪",
2729 sc = "s",
28- on_press = function() cmd.set_menu_page("stats") end,
30+ on_press = function()
31+ cmd.set_menu_page("stats")
32+ end,
2933 expandable = true,
3034 })
3135
3236 local cookie = Button("Cookie", {
3337 icon = "󰆘",
3438 sc = "i",
35- on_press = function() cmd.set_menu_page("cookie") end,
39+ on_press = function()
40+ cmd.set_menu_page("cookie")
41+ end,
3642 expandable = true,
3743 })
3844
3945 local cache = Button("Cache", {
4046 icon = "",
4147 sc = "c",
42- on_press = function() cmd.set_menu_page("cache") end,
48+ on_press = function()
49+ cmd.set_menu_page("cache")
50+ end,
4351 expandable = true,
4452 })
4553
+3-1lua/leetcode-ui/group/page/stats.lua
@@ -38,7 +38,9 @@ local skills = Button("Skills", {
3838 sc = "s",
3939 on_press = cmd.ui_skills,
4040 })
41-if not config.is_cn then buttons:insert(skills) end
41+if not config.is_cn then
42+ buttons:insert(skills)
43+end
4244
4345 local languages = Button("Languages", {
4446 icon = "",
+1-1lua/leetcode-ui/group/pre/init.lua
@@ -23,7 +23,7 @@ end
2323 function Pre:init(title, item)
2424 Pre.super.init(self, {}, { spacing = 1, position = "left" })
2525
26- if title then --
26+ if title then
2727 self:insert(title)
2828 end
2929
+6-2lua/leetcode-ui/group/pre/input.lua
@@ -13,8 +13,12 @@ function Input:init(title, input, params) --
1313 local group = Group({}, { spacing = 1 })
1414
1515 for i, case in ipairs(input) do
16- local ok, param = pcall(function() return params[i].name end)
17- if ok then group:append(param .. " =", "leetcode_normal"):endl() end
16+ local ok, param = pcall(function()
17+ return params[i].name
18+ end)
19+ if ok then
20+ group:append(param .. " =", "leetcode_normal"):endl()
21+ end
1822 group:append(case):endgrp()
1923 end
2024
+6-2lua/leetcode-ui/group/tag/a.lua
@@ -6,11 +6,15 @@ local log = require("leetcode.logger")
66 local A = Tag:extend("LeetTagA")
77
88 ---@param url string
9-local function norm_url(url) return url:lower():gsub("/$", ""):gsub("#.-$", "") end
9+local function norm_url(url)
10+ return url:lower():gsub("/$", ""):gsub("#.-$", "")
11+end
1012
1113 ---@param u1 string
1214 ---@param u2 string
13-local function is_same_url(u1, u2) return norm_url(u1) == norm_url(u2) end
15+local function is_same_url(u1, u2)
16+ return norm_url(u1) == norm_url(u2)
17+end
1418
1519 function A:contents()
1620 local Group = require("leetcode-ui.group")
+20-8lua/leetcode-ui/group/tag/init.lua
@@ -51,7 +51,9 @@ function Tag.normalize(text)
5151 :gsub("\n", "&lcnl;")
5252 :gsub("\t", "&lctab;")
5353 :gsub("%s", " ")
54- :gsub("<[^>]*>", function(match) return match:gsub("&nbsp;", " ") end)
54+ :gsub("<[^>]*>", function(match)
55+ return match:gsub("&nbsp;", " ")
56+ end)
5557 -- :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end)
5658
5759 log.debug(text)
@@ -71,7 +73,9 @@ function Tag:add_indent(item, text)
7173 end
7274 end
7375
74-function Tag:get_text(node) return ts.get_node_text(node, self.text) end
76+function Tag:get_text(node)
77+ return ts.get_node_text(node, self.text)
78+end
7579
7680 ---@param node TSNode
7781 ---
@@ -95,7 +99,9 @@ end
9599 -- 1206
96100 ---@param node TSNode
97101 function Tag:get_el_data(node)
98- if node:type() ~= "element" then return {} end
102+ if node:type() ~= "element" then
103+ return {}
104+ end
99105
100106 local start_tag
101107 for child in node:iter_children() do
@@ -107,7 +113,9 @@ function Tag:get_el_data(node)
107113 end
108114 end
109115
110- if not start_tag then return {} end
116+ if not start_tag then
117+ return {}
118+ end
111119
112120 local tag, attrs = nil, {}
113121 for child in start_tag:iter_children() do
@@ -147,7 +155,9 @@ function Tag:parse_node() --
147155 end
148156
149157 function Tag.trim(lines) --
150- if not lines or vim.tbl_isempty(lines) then return {} end
158+ if not lines or vim.tbl_isempty(lines) then
159+ return {}
160+ end
151161
152162 while not vim.tbl_isempty(lines) and lines[1]:content() == "" do
153163 table.remove(lines, 1)
@@ -160,7 +170,9 @@ function Tag.trim(lines) --
160170 return lines
161171 end
162172
163-local function req_tag(str) return require("leetcode-ui.group.tag." .. str) end
173+local function req_tag(str)
174+ return require("leetcode-ui.group.tag." .. str)
175+end
164176
165177 function Tag:contents()
166178 local items = Tag.super.contents(self)
@@ -224,13 +236,13 @@ end
224236 local LeetTag = Tag
225237
226238 ---@param text string
227-function Tag.static:parse(text) --
239+function Tag.static:parse(text)
228240 ---@type string
229241 local normalized = Normalizer:norm(text)
230242
231243 local ok, parser = pcall(ts.get_string_parser, normalized, "html")
232244
233- if not ok then --
245+ if not ok then
234246 local Plain = require("leetcode.parser.plain")
235247 return Plain:parse(text)
236248 end
+12-4lua/leetcode-ui/layout/console.lua
@@ -44,10 +44,18 @@ function ConsoleLayout:mount()
4444 ConsoleLayout.super.mount(self)
4545
4646 self:set_keymaps({
47- [keys.reset_testcases] = function() self.testcase:reset() end,
48- [keys.use_testcase] = function() self:use_testcase() end,
49- [keys.focus_testcases] = function() self.testcase:focus() end,
50- [keys.focus_result] = function() self.result:focus() end,
47+ [keys.reset_testcases] = function()
48+ self.testcase:reset()
49+ end,
50+ [keys.use_testcase] = function()
51+ self:use_testcase()
52+ end,
53+ [keys.focus_testcases] = function()
54+ self.testcase:focus()
55+ end,
56+ [keys.focus_result] = function()
57+ self.result:focus()
58+ end,
5159 })
5260 end
5361
+3-1lua/leetcode-ui/layout/init.lua
@@ -17,7 +17,9 @@ function Layout:show()
1717 end
1818
1919 function Layout:hide()
20- if not self.visible then return end
20+ if not self.visible then
21+ return
22+ end
2123 Layout.super.hide(self)
2224 self.visible = false
2325 end
+7-3lua/leetcode-ui/line/init.lua
@@ -7,10 +7,14 @@ local log = require("leetcode.logger")
77 ---@class lc.ui.Line : NuiLine
88 local Line = NuiLine:extend("LeetLine")
99
10-function Line:contents() return self._texts end
10+function Line:contents()
11+ return self._texts
12+end
1113
1214 function Line:longest()
13- if self.class.name == "LeetLine" then return vim.api.nvim_strwidth(self:content()) end
15+ if self.class.name == "LeetLine" then
16+ return vim.api.nvim_strwidth(self:content())
17+ end
1418
1519 local max_len = 0
1620 for _, item in pairs(self:contents()) do
@@ -29,7 +33,7 @@ function Line:draw(layout, opts)
2933 local pad = options:get_padding()
3034
3135 if pad then
32- if pad.left then --
36+ if pad.left then
3337 table.insert(texts, 1, NuiText((" "):rep(pad.left)))
3438 elseif pad.right then
3539 table.insert(texts, NuiText((" "):rep(pad.right)))
+3-1lua/leetcode-ui/lines/button/init.lua
@@ -24,7 +24,9 @@ function Button:draw(renderer, opts)
2424 Button.super.draw(self, renderer, opts)
2525 end
2626
27-function Button:press() self._.opts.on_press() end
27+function Button:press()
28+ self._.opts.on_press()
29+end
2830
2931 ---@param lines lc.ui.Line[]
3032 ---@param opts lc.ui.Button.opts
+3-1lua/leetcode-ui/lines/button/menu/back.lua
@@ -9,7 +9,9 @@ function MenuBackButton:init(page)
99 MenuBackButton.super.init(self, "Back", {
1010 icon = "",
1111 sc = "q",
12- on_press = function() cmd.set_menu_page(page) end,
12+ on_press = function()
13+ cmd.set_menu_page(page)
14+ end,
1315 })
1416 end
1517
+6-2lua/leetcode-ui/lines/button/menu/init.lua
@@ -25,13 +25,17 @@ function MenuButton:init(text, opts)
2525 self:append(" ")
2626 self:append(text)
2727
28- if opts.expandable then self:append(" " .. opts.expand_icon, "leetcode_alt") end
28+ if opts.expandable then
29+ self:append(" " .. opts.expand_icon, "leetcode_alt")
30+ end
2931
3032 local len = vim.api.nvim_strwidth(self:content()) + vim.api.nvim_strwidth(opts.sc or "")
3133 local padding = (" "):rep(opts.width - len)
3234
3335 self:append(padding)
34- if opts.sc then self:append(opts.sc, "leetcode_info") end
36+ if opts.sc then
37+ self:append(opts.sc, "leetcode_info")
38+ end
3539 end
3640
3741 ---@type fun(text: string, opts: lc.ui.Button.Menu.opts): lc.ui.Button
+12-4lua/leetcode-ui/lines/calendar.lua
@@ -18,7 +18,9 @@ local Calendar = Lines:extend("LeetCalendar")
1818
1919 local function get_days_in_month(month, year)
2020 local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
21- if (year % 4 == 0 and year % 100 ~= 0) or (year % 400 == 0) then days_in_month[2] = 29 end
21+ if (year % 4 == 0 and year % 100 ~= 0) or (year % 400 == 0) then
22+ days_in_month[2] = 29
23+ end
2224 return days_in_month[month]
2325 end
2426
@@ -57,7 +59,9 @@ function Calendar:handle_res(res)
5759 hour = 1,
5860 isdst = false,
5961 })
60- if self.threshold <= os.time(time) then self.threshold = self.threshold + 24 * 60 * 60 end
62+ if self.threshold <= os.time(time) then
63+ self.threshold = self.threshold + 24 * 60 * 60
64+ end
6165
6266 self.last_year_sub_count = 0
6367 self.month_lens = {}
@@ -161,7 +165,9 @@ local function square_hl(count, max_count)
161165 end
162166
163167 function Calendar:handle_weekdays()
164- if self.curr_time > self.threshold then return end
168+ if self.curr_time > self.threshold then
169+ return
170+ end
165171
166172 local curr = os.date("*t", self.curr_time)
167173 local count = self:get_submission(curr) or 0
@@ -174,7 +180,9 @@ end
174180
175181 function Calendar:fetch()
176182 statistics.calendar(function(res, err)
177- if err then return log.err(err) end
183+ if err then
184+ return log.err(err)
185+ end
178186 self:handle_res(res)
179187 end)
180188 end
+3-1lua/leetcode-ui/lines/footer.lua
@@ -15,7 +15,9 @@ function Footer:contents()
1515 self:endgrp()
1616
1717 self:append(t("Signed in as") .. ": ", "leetcode_alt")
18- if config.auth.is_premium then self:append(config.icons.star .. " ", "leetcode_medium") end
18+ if config.auth.is_premium then
19+ self:append(config.icons.star .. " ", "leetcode_medium")
20+ end
1921 self:append(config.auth.name):endl()
2022 end
2123
+16-6lua/leetcode-ui/lines/init.lua
@@ -14,7 +14,9 @@ function Lines:contents()
1414 local lines = utils.shallowcopy(self._.lines)
1515
1616 local contents = Lines.super.contents(self)
17- if not vim.tbl_isempty(contents) then table.insert(lines, Line(contents)) end
17+ if not vim.tbl_isempty(contents) then
18+ table.insert(lines, Line(contents))
19+ end
1820
1921 return lines
2022 end
@@ -57,10 +59,14 @@ function Lines:draw(layout, opts)
5759 options:set({ padding = { left = leftpad } })
5860
5961 local toppad = padding and padding.top
60- if toppad then lines = vim.list_extend(create_pad(toppad), lines) end
62+ if toppad then
63+ lines = vim.list_extend(create_pad(toppad), lines)
64+ end
6165
6266 local botpad = padding and padding.bot
63- if botpad then lines = vim.list_extend(lines, create_pad(botpad)) end
67+ if botpad then
68+ lines = vim.list_extend(lines, create_pad(botpad))
69+ end
6470
6571 for _, line in pairs(lines) do
6672 line:draw(layout, options:get())
@@ -68,12 +74,14 @@ function Lines:draw(layout, opts)
6874 end
6975
7076 function Lines:append(content, highlight)
71- if type(content) == "table" and O.is_instance(content, Lines) then --
77+ if type(content) == "table" and O.is_instance(content, Lines) then
7278 local lines = content:contents()
7379
7480 for i, line in ipairs(lines) do
7581 Lines.super.append(self, line)
76- if i ~= #lines then self:endl() end
82+ if i ~= #lines then
83+ self:endl()
84+ end
7785 end
7886 else
7987 Lines.super.append(self, content, highlight)
@@ -90,7 +98,9 @@ function Lines:clear()
9098 end
9199
92100 function Lines:insert(item) --
93- if not vim.tbl_isempty(Lines.super.contents(self)) then self:endl() end
101+ if not vim.tbl_isempty(Lines.super.contents(self)) then
102+ self:endl()
103+ end
94104 table.insert(self._.lines, item)
95105
96106 return self
+6-5lua/leetcode-ui/lines/solved.lua
@@ -34,10 +34,9 @@ function Solved:handle_res(res)
3434
3535 local max_count_len = 0
3636 for _, stat in ipairs(res.submit_stats.acSubmissionNum) do
37- local total_count = vim.tbl_filter(
38- function(c) return c.difficulty == stat.difficulty end,
39- res.questions_count
40- )[1].count
37+ local total_count = vim.tbl_filter(function(c)
38+ return c.difficulty == stat.difficulty
39+ end, res.questions_count)[1].count
4140
4241 local solved_line = Line()
4342 solved_line:append(tostring(stat.count))
@@ -93,7 +92,9 @@ end
9392
9493 function Solved:fetch()
9594 statistics.solved(function(res, err)
96- if err then return log.err(err) end
95+ if err then
96+ return log.err(err)
97+ end
9798 self:handle_res(res)
9899 end)
99100 end
+6-2lua/leetcode-ui/opts.lua
@@ -30,9 +30,13 @@ function Opts:merge(opts) --
3030 return self
3131 end
3232
33-function Opts:set(opts) self.opts = vim.tbl_deep_extend("force", self.opts, opts) end
33+function Opts:set(opts)
34+ self.opts = vim.tbl_deep_extend("force", self.opts, opts)
35+end
3436
35-function Opts:get() return self.opts end
37+function Opts:get()
38+ return self.opts
39+end
3640
3741 function Opts:init(opts) --
3842 self.opts = vim.tbl_deep_extend("force", {
+3-1lua/leetcode-ui/popup/console/init.lua
@@ -8,7 +8,9 @@ local ConsolePopup = Popup:extend("LeetConsolePopup")
88 ConsolePopup.handle_leave = vim.schedule_wrap(function(self)
99 local curr_bufnr = vim.api.nvim_get_current_buf()
1010 for _, p in pairs(self.console.popups) do
11- if p.bufnr == curr_bufnr then return end
11+ if p.bufnr == curr_bufnr then
12+ return
13+ end
1214 end
1315 self.console:hide()
1416 end)
+6-2lua/leetcode-ui/popup/console/result.lua
@@ -16,12 +16,16 @@ function ResultPopup:handle(item)
1616 self.border:set_highlight(item._.hl)
1717 self.renderer:handle_res(item)
1818
19- if item.last_testcase then self.last_testcase = item.last_testcase end
19+ if item.last_testcase then
20+ self.last_testcase = item.last_testcase
21+ end
2022
2123 if item._.submission then
2224 local status = item.status_code == 10 and "ac" or "notac"
2325 problemlist.change_status(self.console.question.q.title_slug, status)
24- if status == "ac" then config.stats.update_streak() end
26+ if status == "ac" then
27+ config.stats.update_streak()
28+ end
2529 end
2630
2731 self:draw()
+30-13lua/leetcode-ui/popup/console/testcase.lua
@@ -12,12 +12,16 @@ local Testcase = ConsolePopup:extend("LeetTestcasePopup")
1212
1313 function Testcase:content()
1414 local lines = vim.api.nvim_buf_get_lines(self.bufnr, 0, -1, false)
15- lines = vim.tbl_filter(function(line) return line ~= "" end, lines)
15+ lines = vim.tbl_filter(function(line)
16+ return line ~= ""
17+ end, lines)
1618 return table.concat(lines, "\n")
1719 end
1820
1921 function Testcase:snapshot(id, data) --
20- if not data.test_case then return end
22+ if not data.test_case then
23+ return
24+ end
2125 self.testcases[id] = data.test_case
2226 end
2327
@@ -29,7 +33,9 @@ function Testcase:by_id(id) --
2933 for case in vim.gsplit(self.testcases[id] or "", "\n") do
3034 local j = math.floor(i / n) + 1
3135
32- if not testcases[j] then testcases[j] = {} end
36+ if not testcases[j] then
37+ testcases[j] = {}
38+ end
3339 table.insert(testcases[j], case)
3440
3541 i = i + 1
@@ -45,7 +51,9 @@ function Testcase:populate()
4551 self.testcase_len = #vim.split(t_list[1] or "", "\n")
4652
4753 for i, case in ipairs(t_list) do
48- if i ~= 1 then table.insert(lines, "") end
54+ if i ~= 1 then
55+ table.insert(lines, "")
56+ end
4957 for s in vim.gsplit(case, "\n", { trimempty = true }) do
5058 table.insert(lines, s)
5159 end
@@ -56,13 +64,14 @@ function Testcase:populate()
5664 end
5765
5866 function Testcase:clear_extmarks()
59- if not config.user.console.testcase.virt_text then return end
67+ if not config.user.console.testcase.virt_text then
68+ return
69+ end
6070 local ns = vim.api.nvim_create_namespace("leetcode_extmarks")
6171
62- self.extmarks = vim.tbl_filter(
63- function(extmark) return not vim.api.nvim_buf_del_extmark(self.bufnr, ns, extmark) end,
64- self.extmarks
65- )
72+ self.extmarks = vim.tbl_filter(function(extmark)
73+ return not vim.api.nvim_buf_del_extmark(self.bufnr, ns, extmark)
74+ end, self.extmarks)
6675 end
6776
6877 ---@param line integer
@@ -75,7 +84,9 @@ function Testcase:add_extmark(line, col, opts)
7584 end
7685
7786 function Testcase:draw_extmarks()
78- if not config.user.console.testcase.virt_text then return end
87+ if not config.user.console.testcase.virt_text then
88+ return
89+ end
7990
8091 self:clear_extmarks()
8192 local bufnr = self.bufnr
@@ -83,7 +94,9 @@ function Testcase:draw_extmarks()
8394 local md = self.console.question.q.meta_data
8495 local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
8596
86- if not md.params then return end
97+ if not md.params then
98+ return
99+ end
87100
88101 local j = 1
89102 local pad = (" "):rep(2)
@@ -102,7 +115,9 @@ function Testcase:draw_extmarks()
102115
103116 for i, line in ipairs(lines) do
104117 pcall(function()
105- if lines[i - 1] == "" and lines[i] == "" then invalid = true end
118+ if lines[i - 1] == "" and lines[i] == "" then
119+ invalid = true
120+ end
106121 end)
107122
108123 if line ~= "" then
@@ -147,7 +162,9 @@ function Testcase:autocmds()
147162 "TextChangedI",
148163 "TextChangedP",
149164 "InsertLeave",
150- }, function() self:draw_extmarks() end)
165+ }, function()
166+ self:draw_extmarks()
167+ end)
151168 end
152169
153170 function Testcase:mount()
+9-3lua/leetcode-ui/popup/info.lua
@@ -92,7 +92,9 @@ function Info:populate()
9292 if type(node.text) == "string" then
9393 line:append(" ")
9494 local txt = Parser:parse(node.text)
95- if txt:lines()[1] then line:append(txt:lines()[1]) end
95+ if txt:lines()[1] then
96+ line:append(txt:lines()[1])
97+ end
9698 else
9799 line:append(node.text)
98100 end
@@ -106,9 +108,13 @@ function Info:populate()
106108
107109 self:map("n", keys.confirm, function()
108110 local node = tree:get_node()
109- if not node then return end
111+ if not node then
112+ return
113+ end
110114
111- if node.text and node.text.press then node.text:press() end
115+ if node.text and node.text.press then
116+ node.text:press()
117+ end
112118
113119 if not node:is_expanded() then
114120 node:expand()
+21-7lua/leetcode-ui/popup/init.lua
@@ -31,7 +31,9 @@ function Popup:_buf_destory()
3131 end
3232
3333 function Popup:focus()
34- if not vim.api.nvim_win_is_valid(self.winid) then return end
34+ if not vim.api.nvim_win_is_valid(self.winid) then
35+ return
36+ end
3537 vim.api.nvim_set_current_win(self.winid)
3638 end
3739
@@ -56,19 +58,27 @@ function Popup:unmount()
5658 self.visible = false
5759 end
5860
59-function Popup:map(...) self.renderer:map(...) end
61+function Popup:map(...)
62+ self.renderer:map(...)
63+end
6064
6165 function Popup:mount()
6266 Popup.super.mount(self)
6367
6468 self.visible = true
6569
66- self:on({ "BufLeave", "WinLeave" }, function() self:handle_leave() end)
67- self:map("n", keys.toggle, function() self:hide() end)
70+ self:on({ "BufLeave", "WinLeave" }, function()
71+ self:handle_leave()
72+ end)
73+ self:map("n", keys.toggle, function()
74+ self:hide()
75+ end)
6876 end
6977
7078 function Popup:hide()
71- if not self.visible then return end
79+ if not self.visible then
80+ return
81+ end
7282 Popup.super.hide(self)
7383
7484 self.visible = false
@@ -82,9 +92,13 @@ function Popup:toggle()
8292 end
8393 end
8494
85-function Popup:handle_leave() self:hide() end
95+function Popup:handle_leave()
96+ self:hide()
97+end
8698
87-function Popup:draw() self.renderer:draw(self) end
99+function Popup:draw()
100+ self.renderer:draw(self)
101+end
88102
89103 function Popup:update_renderer()
90104 self.renderer.bufnr = self.bufnr
+6-2lua/leetcode-ui/popup/languages.lua
@@ -42,9 +42,13 @@ end
4242 ---@param res lc.Languages.Res
4343 function Languages:populate(res)
4444 local group = Group({}, { spacing = 1 })
45- if res == vim.NIL then return end
45+ if res == vim.NIL then
46+ return
47+ end
4648
47- table.sort(res, function(a, b) return a.problems_solved > b.problems_solved end)
49+ table.sort(res, function(a, b)
50+ return a.problems_solved > b.problems_solved
51+ end)
4852 for _, lang in ipairs(res) do
4953 group:insert(self:handle(lang))
5054 end
+3-1lua/leetcode-ui/popup/skills.lua
@@ -16,7 +16,9 @@ local Skills = Popup:extend("LeetSkills")
1616 function Skills:handle(name, skills)
1717 local lines = Lines()
1818
19- table.sort(skills, function(a, b) return a.problems_solved > b.problems_solved end)
19+ table.sort(skills, function(a, b)
20+ return a.problems_solved > b.problems_solved
21+ end)
2022 lines:append(config.icons.square, utils.diff_to_hl(name))
2123 lines:append(" " .. name)
2224
+45-22lua/leetcode-ui/question.lua
@@ -22,8 +22,12 @@ local Question = Object("LeetQuestion")
2222 ---@param raw? boolean
2323 function Question:snippet(raw)
2424 local snippets = self.q.code_snippets ~= vim.NIL and self.q.code_snippets or {}
25- local snip = vim.tbl_filter(function(snip) return snip.lang_slug == self.lang end, snippets)[1]
26- if not snip then return end
25+ local snip = vim.tbl_filter(function(snip)
26+ return snip.lang_slug == self.lang
27+ end, snippets)[1]
28+ if not snip then
29+ return
30+ end
2731
2832 local code = snip.code:gsub("\r\n", "\n")
2933 return raw and code or self:injector(code)
@@ -31,7 +35,9 @@ end
3135
3236 ---@param code? string
3337 function Question:set_lines(code)
34- if not vim.api.nvim_buf_is_valid(self.bufnr) then return end
38+ if not vim.api.nvim_buf_is_valid(self.bufnr) then
39+ return
40+ end
3541
3642 pcall(vim.cmd.undojoin)
3743 local s_i, e_i, lines = self:range()
@@ -42,7 +48,9 @@ function Question:set_lines(code)
4248 end
4349
4450 function Question:reset_lines()
45- if not self.reset then return end
51+ if not self.reset then
52+ return
53+ end
4654
4755 local new_lines = self:snippet(true) or ""
4856
@@ -63,7 +71,7 @@ function Question:path()
6371 ("%s.%s-%s.%s"):format(self.q.frontend_id, self.q.title_slug, lang.slug, lang.ft)
6472 self.file = config.storage.home:joinpath(fn_legacy)
6573
66- if self.file:exists() then --
74+ if self.file:exists() then
6775 return self.file:absolute(), true
6876 end
6977
@@ -71,7 +79,7 @@ function Question:path()
7179 self.file = config.storage.home:joinpath(fn)
7280 local existed = self.file:exists()
7381
74- if not existed then --
82+ if not existed then
7583 self.file:write(self:snippet(), "w")
7684 end
7785
@@ -94,11 +102,11 @@ function Question:open_buffer(existed)
94102 vim.api.nvim_set_option_value("buflisted", true, { buf = self.bufnr })
95103
96104 local i = self:fold_range()
97- if i then --
105+ if i then
98106 pcall(vim.cmd, ("%d,%dfold"):format(1, i))
99107 end
100108
101- if existed then --
109+ if existed then
102110 self:reset_lines()
103111 end
104112 end
@@ -110,7 +118,7 @@ function Question:inject(before)
110118
111119 local res
112120
113- if type(inj) == "boolean" and inj == true and before then --
121+ if type(inj) == "boolean" and inj == true and before then
114122 inj = config.imports[self.lang]
115123 end
116124
@@ -138,16 +146,20 @@ function Question:injector(code)
138146 }
139147
140148 local before = self:inject(true)
141- if before then table.insert(parts, 1, before) end
149+ if before then
150+ table.insert(parts, 1, before)
151+ end
142152
143153 local after = self:inject(false)
144- if after then table.insert(parts, after) end
154+ if after then
155+ table.insert(parts, after)
156+ end
145157
146158 return table.concat(parts, "\n")
147159 end
148160
149161 function Question:_unmount()
150- if vim.v.dying ~= 0 then --
162+ if vim.v.dying ~= 0 then
151163 return
152164 end
153165
@@ -160,17 +172,18 @@ function Question:_unmount()
160172 vim.api.nvim_buf_delete(self.bufnr, { force = true, unload = false })
161173 end
162174
163- _Lc_state.questions = vim.tbl_filter(
164- function(q) return q.bufnr ~= self.bufnr end,
165- _Lc_state.questions
166- )
175+ _Lc_state.questions = vim.tbl_filter(function(q)
176+ return q.bufnr ~= self.bufnr
177+ end, _Lc_state.questions)
167178
168179 self = nil
169180 end)
170181 end
171182
172183 function Question:unmount()
173- if vim.api.nvim_win_is_valid(self.winid) then vim.api.nvim_win_close(self.winid, true) end
184+ if vim.api.nvim_win_is_valid(self.winid) then
185+ vim.api.nvim_win_close(self.winid, true)
186+ end
174187 end
175188
176189 local group = vim.api.nvim_create_augroup("leetcode_questions", { clear = true })
@@ -178,7 +191,9 @@ function Question:autocmds()
178191 vim.api.nvim_create_autocmd("WinClosed", {
179192 group = group,
180193 pattern = tostring(self.winid),
181- callback = function() self:_unmount() end,
194+ callback = function()
195+ self:_unmount()
196+ end,
182197 })
183198 end
184199
@@ -199,7 +214,9 @@ end
199214
200215 function Question:mount()
201216 local tabp = utils.detect_duplicate_question(self.cache.title_slug, config.lang)
202- if tabp then return pcall(vim.api.nvim_set_current_tabpage, tabp) end
217+ if tabp then
218+ return pcall(vim.api.nvim_set_current_tabpage, tabp)
219+ end
203220
204221 local q = api_question.by_title_slug(self.cache.title_slug)
205222 if not q or q.is_paid_only and not config.auth.is_premium then
@@ -241,14 +258,18 @@ end
241258
242259 function Question:fold_range()
243260 local start_i, _, lines = self:range(true)
244- if start_i == nil or start_i <= 1 then return end
261+ if start_i == nil or start_i <= 1 then
262+ return
263+ end
245264
246265 local i = start_i - 1
247266 while lines[i] == "" do
248267 i = i - 1
249268 end
250269
251- if 1 < i then return i end
270+ if 1 < i then
271+ return i
272+ end
252273 end
253274
254275 ---@param submit boolean
@@ -281,7 +302,9 @@ Question.change_lang = vim.schedule_wrap(function(self, lang)
281302 vim.api.nvim_set_option_value("buflisted", false, { buf = old_bufnr })
282303 self:open_buffer(existed)
283304
284- if not loaded then utils.exec_hooks("question_enter", self) end
305+ if not loaded then
306+ utils.exec_hooks("question_enter", self)
307+ end
285308 end)
286309
287310 if not ok then
+48-16lua/leetcode-ui/renderer/init.lua
@@ -24,9 +24,13 @@ function Renderer:draw(component)
2424 self.bufnr = component.bufnr
2525 self.winid = component.winid
2626
27- if not vim.api.nvim_buf_is_valid(self.bufnr) then return end
27+ if not vim.api.nvim_buf_is_valid(self.bufnr) then
28+ return
29+ end
2830
29- self:map("n", keys.confirm, function() self:handle_press() end)
31+ self:map("n", keys.confirm, function()
32+ self:handle_press()
33+ end)
3034
3135 self:clear_keymaps()
3236 self._.buttons = {}
@@ -39,7 +43,9 @@ function Renderer:draw(component)
3943
4044 Renderer.super.draw(self, self, self._.opts)
4145 end)
42- if c_ok then pcall(vim.api.nvim_win_set_cursor, self.winid, c) end
46+ if c_ok then
47+ pcall(vim.api.nvim_win_set_cursor, self.winid, c)
48+ end
4349 end
4450
4551 ---@private
@@ -47,17 +53,27 @@ end
4753 ---@param fn function
4854 function Renderer:modifiable(fn)
4955 local bufnr = self.bufnr
50- if not (bufnr and vim.api.nvim_buf_is_valid(bufnr)) then return end
56+ if not (bufnr and vim.api.nvim_buf_is_valid(bufnr)) then
57+ return
58+ end
5159
5260 local modi = vim.api.nvim_buf_get_option(bufnr, "modifiable")
53- if not modi then vim.api.nvim_buf_set_option(bufnr, "modifiable", true) end
61+ if not modi then
62+ vim.api.nvim_buf_set_option(bufnr, "modifiable", true)
63+ end
5464 fn()
55- if not modi then vim.api.nvim_buf_set_option(bufnr, "modifiable", false) end
65+ if not modi then
66+ vim.api.nvim_buf_set_option(bufnr, "modifiable", false)
67+ end
5668 end
5769
5870 function Renderer:map(mode, key, handler, opts) --
59- if not self.bufnr then return end
60- if type(key) == "number" then key = tostring(key) end
71+ if not self.bufnr then
72+ return
73+ end
74+ if type(key) == "number" then
75+ key = tostring(key)
76+ end
6177
6278 if type(key) == "table" then
6379 for _, k in ipairs(key) do
@@ -70,7 +86,9 @@ function Renderer:map(mode, key, handler, opts) --
7086 local clearable = options.clearable
7187 options.clearable = nil
7288
73- if clearable then self._.keymaps[key] = mode end
89+ if clearable then
90+ self._.keymaps[key] = mode
91+ end
7492 vim.keymap.set(mode, key, handler, options)
7593 vim.keymap.set(mode, key, handler, options)
7694 end
@@ -94,7 +112,9 @@ function Renderer:clear()
94112 self._.line_idx = 1
95113 self._.buttons = {}
96114 self:clear_keymaps()
97- self:modifiable(function() vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, {}) end)
115+ self:modifiable(function()
116+ vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, {})
117+ end)
98118 end
99119
100120 ---@param val? integer Optional value to increment line index by
@@ -110,15 +130,25 @@ function Renderer:handle_press(line_idx)
110130 vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<cr>", true, false, true), "n", true)
111131 end
112132
113- if not self.bufnr or not self.winid then feedenter() end
114- if not line_idx and not vim.api.nvim_win_is_valid(self.winid) then return feedenter() end
133+ if not self.bufnr or not self.winid then
134+ feedenter()
135+ end
136+ if not line_idx and not vim.api.nvim_win_is_valid(self.winid) then
137+ return feedenter()
138+ end
115139
116140 line_idx = line_idx or vim.api.nvim_win_get_cursor(self.winid)[1]
117141
118- if not self._.buttons[line_idx] then return feedenter() end
142+ if not self._.buttons[line_idx] then
143+ return feedenter()
144+ end
119145
120- local ok, err = pcall(function() self._.buttons[line_idx]:press() end)
121- if not ok then log.error(err) end
146+ local ok, err = pcall(function()
147+ self._.buttons[line_idx]:press()
148+ end)
149+ if not ok then
150+ log.error(err)
151+ end
122152 end
123153
124154 ---@param button lc.ui.Button
@@ -131,7 +161,9 @@ function Renderer:apply_button(button) --
131161 end
132162
133163 ---@param layout lc.ui.Renderer
134-function Renderer:set(layout) self._.items = layout._.items end
164+function Renderer:set(layout)
165+ self._.items = layout._.items
166+end
135167
136168 ---@param components lc.ui.Lines[]
137169 ---@param opts? lc.ui.opts
+18-8lua/leetcode-ui/renderer/menu.lua
@@ -12,7 +12,9 @@ local Menu = Renderer:extend("LeetMenu")
1212
1313 local function tbl_keys(t)
1414 local keys = vim.tbl_keys(t)
15- if vim.tbl_isempty(keys) then return end
15+ if vim.tbl_isempty(keys) then
16+ return
17+ end
1618 table.sort(keys)
1719 return keys
1820 end
@@ -29,13 +31,17 @@ function Menu:autocmds()
2931 api.nvim_create_autocmd("WinResized", {
3032 group = group_id,
3133 buffer = self.bufnr,
32- callback = function() self:draw() end,
34+ callback = function()
35+ self:draw()
36+ end,
3337 })
3438
3539 api.nvim_create_autocmd("CursorMoved", {
3640 group = group_id,
3741 buffer = self.bufnr,
38- callback = function() self:cursor_move() end,
42+ callback = function()
43+ self:cursor_move()
44+ end,
3945 })
4046
4147 api.nvim_create_autocmd("QuitPre", {
@@ -50,13 +56,17 @@ function Menu:autocmds()
5056 end
5157
5258 function Menu:cursor_move()
53- if not self.winid or not api.nvim_win_is_valid(self.winid) then return end
59+ if not self.winid or not api.nvim_win_is_valid(self.winid) then
60+ return
61+ end
5462
5563 local curr = api.nvim_win_get_cursor(self.winid)
5664 local prev = self.cursor.prev
5765
5866 local keys = tbl_keys(self._.buttons)
59- if not keys then return end
67+ if not keys then
68+ return
69+ end
6070
6171 local function find_nearest(l, r)
6272 while l < r do
@@ -138,7 +148,7 @@ function Menu:apply_options()
138148 end
139149
140150 function Menu:unmount()
141- if vim.v.dying ~= 0 then --
151+ if vim.v.dying ~= 0 then
142152 return
143153 end
144154
@@ -156,10 +166,10 @@ function Menu:unmount()
156166 end
157167
158168 function Menu:remount()
159- if self.winid and api.nvim_win_is_valid(self.winid) then --
169+ if self.winid and api.nvim_win_is_valid(self.winid) then
160170 api.nvim_win_close(self.winid, true)
161171 end
162- if self.bufnr and api.nvim_buf_is_valid(self.bufnr) then --
172+ if self.bufnr and api.nvim_buf_is_valid(self.bufnr) then
163173 api.nvim_buf_delete(self.bufnr, { force = true })
164174 end
165175
+9-3lua/leetcode-ui/renderer/result.lua
@@ -54,7 +54,9 @@ function ResultLayout:handle_accepted(item)
5454
5555 local lang = utils.get_lang_by_name(item.pretty_lang)
5656 local lang_text = { item.pretty_lang, "Structure" }
57- if lang then lang_text = { lang.icon .. " " .. lang.lang, lang.hl or "Structure" } end
57+ if lang then
58+ lang_text = { lang.icon .. " " .. lang.lang, lang.hl or "Structure" }
59+ end
5860
5961 if config.translator then
6062 runtime
@@ -108,7 +110,9 @@ end
108110 ---
109111 ---@param item lc.runtime
110112 function ResultLayout:handle_runtime(item) -- status code = 10
111- if item._.submission then return self:handle_accepted(item) end
113+ if item._.submission then
114+ return self:handle_accepted(item)
115+ end
112116
113117 local header = Header(item)
114118 self:insert(header)
@@ -249,7 +253,9 @@ function ResultLayout:handle_res(item)
249253 end,
250254
251255 -- unknown
252- ["unknown"] = function() log.error("unknown runner status code: " .. item.status_code) end,
256+ ["unknown"] = function()
257+ log.error("unknown runner status code: " .. item.status_code)
258+ end,
253259 }
254260
255261 local handler = handlers[item.status_code]
+15-5lua/leetcode-ui/split/description.lua
@@ -23,7 +23,9 @@ function Description:autocmds()
2323 vim.api.nvim_create_autocmd("WinResized", {
2424 group = group_id,
2525 buffer = self.bufnr,
26- callback = function() self:draw() end,
26+ callback = function()
27+ self:draw()
28+ end,
2729 })
2830 end
2931
@@ -71,7 +73,9 @@ function Description:draw()
7173 end
7274
7375 function Description:draw_imgs()
74- if not img_sup then return end
76+ if not img_sup then
77+ return
78+ end
7579
7680 local lines = vim.api.nvim_buf_get_lines(self.bufnr, 1, -1, false)
7781 for i, line in ipairs(lines) do
@@ -86,7 +90,9 @@ function Description:draw_imgs()
8690 window = self.winid,
8791 with_virtual_padding = true,
8892 }, function(image)
89- if not image then return end
93+ if not image then
94+ return
95+ end
9096
9197 self.images[link] = image
9298 image:render({ y = i + 1 })
@@ -119,7 +125,9 @@ function Description:populate()
119125
120126 header:append(q.frontend_id .. ". ", "leetcode_normal")
121127 header:append(utils.translate(q.title, q.translated_title))
122- if q.is_paid_only then header:append(" " .. t("Premium"), "leetcode_medium") end
128+ if q.is_paid_only then
129+ header:append(" " .. t("Premium"), "leetcode_medium")
130+ end
123131 header:endgrp()
124132
125133 local show_stats = self.show_stats
@@ -141,7 +149,9 @@ function Description:populate()
141149 header:append(likes .. " ", "leetcode_alt")
142150
143151 local dislikes = show_stats and q.dislikes or "___"
144- if not config.is_cn then header:append((" %s "):format(dislikes), "leetcode_alt") end
152+ if not config.is_cn then
153+ header:append((" %s "):format(dislikes), "leetcode_alt")
154+ end
145155
146156 header:append((" %s "):format(config.icons.bar))
147157
+15-5lua/leetcode-ui/split/init.lua
@@ -49,7 +49,9 @@ function Split:show()
4949 end
5050
5151 function Split:hide()
52- if not self.visible then return end
52+ if not self.visible then
53+ return
54+ end
5355 Split.super.hide(self)
5456
5557 self.visible = false
@@ -60,10 +62,14 @@ function Split:mount()
6062
6163 self.visible = true
6264
63- self:map("n", keys.toggle, function() self:toggle() end)
65+ self:map("n", keys.toggle, function()
66+ self:toggle()
67+ end)
6468 end
6569
66-function Split:map(...) self.renderer:map(...) end
70+function Split:map(...)
71+ self.renderer:map(...)
72+end
6773
6874 function Split:unmount()
6975 Split.super.unmount(self)
@@ -71,9 +77,13 @@ function Split:unmount()
7177 self.visible = false
7278 end
7379
74-function Split:draw() self.renderer:draw(self) end
80+function Split:draw()
81+ self.renderer:draw(self)
82+end
7583
76-function Split:clear() self.renderer:clear() end
84+function Split:clear()
85+ self.renderer:clear()
86+end
7787
7888 function Split:update_renderer()
7989 self.renderer.bufnr = self.bufnr
+21-7lua/leetcode-ui/utils.lua
@@ -17,7 +17,9 @@ end
1717
1818 ---@param item lc.ui.Lines
1919 function utils.longest_line(item)
20- if item.class.name == "LeetLine" then return vim.api.nvim_strwidth(item:content()) end
20+ if item.class.name == "LeetLine" then
21+ return vim.api.nvim_strwidth(item:content())
22+ end
2123
2224 local max_len = 0
2325 for _, line in pairs(item:contents()) do
@@ -47,14 +49,18 @@ end
4749
4850 ---@param status string
4951 function utils.status_to_hl(status)
50- if not status then return end
52+ if not status then
53+ return
54+ end
5155
5256 return table.unpack(config.icons.hl.status[status])
5357 end
5458
5559 ---@param layout lc.ui.Renderer
5660 function utils.win_width(layout)
57- if not vim.api.nvim_win_is_valid(layout.winid) then return 0 end
61+ if not vim.api.nvim_win_is_valid(layout.winid) then
62+ return 0
63+ end
5864 return vim.api.nvim_win_get_width(layout.winid)
5965 end
6066
@@ -98,21 +104,29 @@ function utils.get_padding(lines, layout)
98104 end
99105
100106 function utils.set_buf_opts(bufnr, options)
101- if not vim.api.nvim_buf_is_valid(bufnr) then return end
107+ if not vim.api.nvim_buf_is_valid(bufnr) then
108+ return
109+ end
102110
103111 for opt, value in pairs(options) do
104112 local ok, err = pcall(vim.api.nvim_set_option_value, opt, value, { buf = bufnr })
105- if not ok then log.error(err) end
113+ if not ok then
114+ log.error(err)
115+ end
106116 end
107117 end
108118
109119 function utils.set_win_opts(winid, options)
110- if not vim.api.nvim_win_is_valid(winid) then return end
120+ if not vim.api.nvim_win_is_valid(winid) then
121+ return
122+ end
111123
112124 for opt, value in pairs(options) do
113125 local ok, err =
114126 pcall(vim.api.nvim_set_option_value, opt, value, { win = winid, scope = "local" })
115- if not ok then log.error(err) end
127+ if not ok then
128+ log.error(err)
129+ end
116130 end
117131 end
118132
+19-7lua/leetcode.lua
@@ -8,10 +8,14 @@ local leetcode = {}
88 ---@return boolean
99 function leetcode.should_skip(on_vimenter)
1010 if on_vimenter then
11- if vim.fn.argc() ~= 1 then return true end
11+ if vim.fn.argc() ~= 1 then
12+ return true
13+ end
1214
1315 local usr_arg, arg = config.user.arg, vim.fn.argv()[1]
14- if usr_arg ~= arg then return true end
16+ if usr_arg ~= arg then
17+ return true
18+ end
1519
1620 local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
1721 if #lines > 1 or (#lines == 1 and lines[1]:len() > 0) then
@@ -33,11 +37,15 @@ function leetcode.should_skip(on_vimenter)
3337 return false
3438 end
3539
36-function leetcode.setup_cmds() require("leetcode.command").setup() end
40+function leetcode.setup_cmds()
41+ require("leetcode.command").setup()
42+end
3743
3844 ---@param on_vimenter boolean
3945 function leetcode.start(on_vimenter)
40- if leetcode.should_skip(on_vimenter) then return false end
46+ if leetcode.should_skip(on_vimenter) then
47+ return false
48+ end
4149
4250 config.setup()
4351
@@ -48,7 +56,7 @@ function leetcode.start(on_vimenter)
4856 local theme = require("leetcode.theme")
4957 theme.setup()
5058
51- if not on_vimenter then --
59+ if not on_vimenter then
5260 vim.cmd.enew()
5361 end
5462
@@ -61,7 +69,9 @@ function leetcode.start(on_vimenter)
6169 return true
6270 end
6371
64-function leetcode.stop() vim.cmd("qa!") end
72+function leetcode.stop()
73+ vim.cmd("qa!")
74+end
6575
6676 ---@param cfg? lc.UserConfig
6777 function leetcode.setup(cfg)
@@ -78,7 +88,9 @@ function leetcode.setup(cfg)
7888 group = group_id,
7989 pattern = "*",
8090 nested = true,
81- callback = function() leetcode.start(true) end,
91+ callback = function()
92+ leetcode.start(true)
93+ end,
8294 })
8395 end
8496
+6-2lua/leetcode/api/auth.lua
@@ -13,7 +13,9 @@ function Auth.user(cb)
1313
1414 if cb then
1515 utils.query(query, {}, {
16- callback = function(res, err) cb(Auth.handle(res, err)) end,
16+ callback = function(res, err)
17+ cb(Auth.handle(res, err))
18+ end,
1719 endpoint = urls.auth,
1820 })
1921 else
@@ -26,7 +28,9 @@ end
2628 ---@private
2729 ---@return lc.UserStatus, lc.err
2830 function Auth.handle(res, err)
29- if err then return res, err end
31+ if err then
32+ return res, err
33+ end
3034
3135 local auth = res.data.userStatus
3236 err = {}
+39-13lua/leetcode/api/problems.lua
@@ -17,33 +17,45 @@ function Problems.all(cb, noti)
1717 local endpoint = urls.problems:format("algorithms")
1818
1919 local spinner
20- if noti then spinner = Spinner:init("updating problemlist cache...", "points") end
20+ if noti then
21+ spinner = Spinner:init("updating problemlist cache...", "points")
22+ end
2123
2224 if cb then
2325 utils.get(endpoint, {
2426 callback = function(res, err)
2527 if err then
26- if spinner then spinner:stop(err.msg, false) end
28+ if spinner then
29+ spinner:stop(err.msg, false)
30+ end
2731 return cb(nil, err)
2832 end
2933
3034 local problems = utils.normalize_problems(res.stat_status_pairs)
3135
3236 if config.is_cn then
33- if spinner then spinner:update("fetching title translations") end
37+ if spinner then
38+ spinner:update("fetching title translations")
39+ end
3440 Problems.translated_titles(function(titles, terr)
3541 if terr then
36- if spinner then spinner:stop(terr.msg, false) end
42+ if spinner then
43+ spinner:stop(terr.msg, false)
44+ end
3745 return cb(nil, terr)
3846 end
3947
4048 problems = utils.translate_titles(problems, titles)
41- if spinner then spinner:stop("cache updated") end
49+ if spinner then
50+ spinner:stop("cache updated")
51+ end
4252
4353 cb(problems)
4454 end)
4555 else
46- if spinner then spinner:stop("cache updated") end
56+ if spinner then
57+ spinner:stop("cache updated")
58+ end
4759
4860 cb(problems)
4961 end
@@ -52,7 +64,9 @@ function Problems.all(cb, noti)
5264 else
5365 local res, err = utils.get(endpoint)
5466 if err then
55- if spinner then spinner:stop(err.msg, false) end
67+ if spinner then
68+ spinner:stop(err.msg, false)
69+ end
5670 return nil, err
5771 end
5872
@@ -61,14 +75,20 @@ function Problems.all(cb, noti)
6175 if config.is_cn then
6276 local titles, terr = Problems.translated_titles()
6377 if terr then
64- if spinner then spinner:stop(terr.msg, false) end
78+ if spinner then
79+ spinner:stop(terr.msg, false)
80+ end
6581 return nil, terr
6682 end
6783
68- if spinner then spinner:stop("problems cache updated") end
84+ if spinner then
85+ spinner:stop("problems cache updated")
86+ end
6987 return utils.translate_titles(problems, titles)
7088 else
71- if spinner then spinner:stop("problems cache updated") end
89+ if spinner then
90+ spinner:stop("problems cache updated")
91+ end
7292 return problems
7393 end
7494 end
@@ -79,7 +99,9 @@ function Problems.question_of_today(cb)
7999
80100 utils.query(query, {}, {
81101 callback = function(res, err)
82- if err then return cb(nil, err) end
102+ if err then
103+ return cb(nil, err)
104+ end
83105
84106 local tday_record = res.data["todayRecord"]
85107 local question = config.is_cn and tday_record[1].question or tday_record.question
@@ -94,13 +116,17 @@ function Problems.translated_titles(cb)
94116 if cb then
95117 utils.query(query, {}, {
96118 callback = function(res, err)
97- if err then return cb(nil, err) end
119+ if err then
120+ return cb(nil, err)
121+ end
98122 cb(res.data.translations)
99123 end,
100124 })
101125 else
102126 local res, err = utils.query(query, {})
103- if err then return nil, err end
127+ if err then
128+ return nil, err
129+ end
104130 return res.data.translations
105131 end
106132 end
+12-4lua/leetcode/api/question.lua
@@ -20,12 +20,16 @@ function question.by_title_slug(title_slug)
2020 local query = queries.question
2121
2222 local res, err = utils.query(query, variables)
23- if not res or err then return log.err(err) end
23+ if not res or err then
24+ return log.err(err)
25+ end
2426
2527 local q = res.data.question
2628 q.meta_data = select(2, pcall(utils.decode, q.meta_data))
2729 q.stats = select(2, pcall(utils.decode, q.stats))
28- if type(q.similar) == "string" then q.similar = utils.normalize_similar_cn(q.similar) end
30+ if type(q.similar) == "string" then
31+ q.similar = utils.normalize_similar_cn(q.similar)
32+ end
2933
3034 return q
3135 end
@@ -41,14 +45,18 @@ function question.random(filters)
4145
4246 local config = require("leetcode.config")
4347 local res, err = utils.query(query, variables)
44- if err then return nil, err end
48+ if err then
49+ return nil, err
50+ end
4551
4652 local q = res.data.randomQuestion
4753
4854 if q == vim.NIL then
4955 local msg = "Random question fetch responded with `null`"
5056
51- if filters then msg = msg .. ".\n\nMaybe invalid filters?\n" .. vim.inspect(filters) end
57+ if filters then
58+ msg = msg .. ".\n\nMaybe invalid filters?\n" .. vim.inspect(filters)
59+ end
5260
5361 return nil, { msg = msg, lvl = vim.log.levels.ERROR }
5462 end
+27-9lua/leetcode/api/statistics.lua
@@ -17,7 +17,9 @@ function statistics.calendar(cb)
1717 utils.query(query, variables, {
1818 endpoint = urls.calendar,
1919 callback = function(res, err)
20- if err then return cb(nil, err) end
20+ if err then
21+ return cb(nil, err)
22+ end
2123
2224 local data = res.data
2325 local calendar = data["matchedUser"]["calendar"]
@@ -42,7 +44,9 @@ function statistics.session_progress(cb)
4244
4345 utils.query(query, variables, {
4446 callback = function(res, err)
45- if err then return cb(nil, err) end
47+ if err then
48+ return cb(nil, err)
49+ end
4650
4751 local data = res.data
4852 local session_progress = data["matchedUser"]["submitStats"]["acSubmissionNum"]
@@ -62,7 +66,9 @@ function statistics.solved(cb)
6266 utils.query(query, variables, {
6367 endpoint = urls.solved,
6468 callback = function(res, err)
65- if err then return cb(nil, err) end
69+ if err then
70+ return cb(nil, err)
71+ end
6672
6773 local data = res.data
6874 local questions_count = data["allQuestionsCount"]
@@ -87,7 +93,9 @@ function statistics.skills(cb)
8793 utils.query(query, variables, {
8894 endpoint = urls.skills,
8995 callback = function(res, err)
90- if err then return cb(nil, err) end
96+ if err then
97+ return cb(nil, err)
98+ end
9199 local data = res.data
92100 local tag_problems_counts = data["matchedUser"]["tag_problems_counts"]
93101 cb(tag_problems_counts)
@@ -106,7 +114,9 @@ function statistics.languages(cb)
106114 utils.query(query, variables, {
107115 endpoint = urls.languages,
108116 callback = function(res, err)
109- if err then return cb(nil, err) end
117+ if err then
118+ return cb(nil, err)
119+ end
110120 local data = res.data
111121 local lang_prob_count = data["matchedUser"]["languageProblemCount"]
112122 cb(lang_prob_count)
@@ -122,7 +132,9 @@ function statistics.streak(cb)
122132 utils.query(query, variables, {
123133 endpoint = urls.streak_counter,
124134 callback = function(res, err)
125- if err then return cb(nil, err) end
135+ if err then
136+ return cb(nil, err)
137+ end
126138 local data = res.data
127139 local streak = data["streakCounter"]
128140 cb(streak)
@@ -137,7 +149,9 @@ function statistics.sessions(cb)
137149 utils.post(url, {
138150 body = vim.empty_dict(),
139151 callback = function(res, err)
140- if err then return cb(nil, err) end
152+ if err then
153+ return cb(nil, err)
154+ end
141155 config.sessions.update(res.sessions)
142156 cb(res.sessions)
143157 end,
@@ -155,7 +169,9 @@ function statistics.change_session(id, cb)
155169 utils.put(url, {
156170 body = body,
157171 callback = function(res, err)
158- if err then return cb(nil, err) end
172+ if err then
173+ return cb(nil, err)
174+ end
159175 config.sessions.update(res.sessions)
160176 cb(res.sessions)
161177 end,
@@ -173,7 +189,9 @@ function statistics.create_session(name, cb)
173189 utils.put(url, {
174190 body = body,
175191 callback = function(res, err)
176- if err then return cb(nil, err) end
192+ if err then
193+ return cb(nil, err)
194+ end
177195 config.sessions.update(res.sessions)
178196 cb(res.sessions)
179197 end,
+49-41lua/leetcode/api/utils.lua
@@ -63,10 +63,14 @@ function utils.curl(method, params)
6363 }, params or {})
6464 local url = ("https://leetcode.%s%s"):format(config.domain, params.endpoint)
6565
66- if type(params.body) == "table" then params.body = vim.json.encode(params.body) end
66+ if type(params.body) == "table" then
67+ params.body = vim.json.encode(params.body)
68+ end
6769
6870 local tries = params.retry
69- local function should_retry(err) return err and err.status >= 500 and tries > 0 end
71+ local function should_retry(err)
72+ return err and err.status >= 500 and tries > 0
73+ end
7074
7175 if params.callback then
7276 local cb = vim.schedule_wrap(params.callback)
@@ -112,7 +116,9 @@ function utils.handle_res(out)
112116 local ok, msg = pcall(function()
113117 local dec = utils.decode(out.body)
114118
115- if dec.error then return dec.error end
119+ if dec.error then
120+ return dec.error
121+ end
116122
117123 local tbl = {}
118124 for _, e in ipairs(dec.errors) do
@@ -139,7 +145,9 @@ end
139145
140146 ---@param err lc.err
141147 function utils.check_err(err)
142- if not err then return end
148+ if not err then
149+ return
150+ end
143151
144152 if err.status then
145153 if err.status == 401 or err.status == 403 then
@@ -161,25 +169,26 @@ end
161169 function utils.normalize_similar_cn(s)
162170 s = select(2, pcall(utils.decode, s))
163171
164- return vim.tbl_map(
165- function(sq)
166- return {
167- title = sq.title,
168- translated_title = sq.translatedTitle,
169- paid_only = sq.isPaidOnly,
170- title_slug = sq.titleSlug,
171- difficulty = sq.difficulty,
172- }
173- end,
174- s
175- )
172+ return vim.tbl_map(function(sq)
173+ return {
174+ title = sq.title,
175+ translated_title = sq.translatedTitle,
176+ paid_only = sq.isPaidOnly,
177+ title_slug = sq.titleSlug,
178+ difficulty = sq.difficulty,
179+ }
180+ end, s)
176181 end
177182
178-function utils.lvl_to_name(lvl) return ({ "Easy", "Medium", "Hard" })[lvl] end
183+function utils.lvl_to_name(lvl)
184+ return ({ "Easy", "Medium", "Hard" })[lvl]
185+end
179186
180187 ---@return lc.cache.Question[]
181188 function utils.normalize_problems(problems)
182- problems = vim.tbl_filter(function(p) return not p.stat.question__hide end, problems)
189+ problems = vim.tbl_filter(function(p)
190+ return not p.stat.question__hide
191+ end, problems)
183192
184193 local comp = function(a, b)
185194 local a_fid = a.stat.frontend_question_id
@@ -200,28 +209,25 @@ function utils.normalize_problems(problems)
200209 end
201210 table.sort(problems, comp)
202211
203- return vim.tbl_map(
204- function(p)
205- return {
206- status = p.status,
207- id = p.stat.question_id,
208- frontend_id = p.stat.frontend_question_id,
209- title = p.stat.question__title,
210- title_cn = "",
211- title_slug = p.stat.question__title_slug,
212- link = ("https://leetcode.%s/problems/%s/"):format(
213- config.domain,
214- p.stat.question__title_slug
215- ),
216- paid_only = p.paid_only,
217- ac_rate = p.stat.total_acs * 100 / math.max(p.stat.total_submitted, 1),
218- difficulty = utils.lvl_to_name(p.difficulty.level),
219- starred = p.is_favor,
220- topic_tags = {},
221- }
222- end,
223- problems
224- )
212+ return vim.tbl_map(function(p)
213+ return {
214+ status = p.status,
215+ id = p.stat.question_id,
216+ frontend_id = p.stat.frontend_question_id,
217+ title = p.stat.question__title,
218+ title_cn = "",
219+ title_slug = p.stat.question__title_slug,
220+ link = ("https://leetcode.%s/problems/%s/"):format(
221+ config.domain,
222+ p.stat.question__title_slug
223+ ),
224+ paid_only = p.paid_only,
225+ ac_rate = p.stat.total_acs * 100 / math.max(p.stat.total_submitted, 1),
226+ difficulty = utils.lvl_to_name(p.difficulty.level),
227+ starred = p.is_favor,
228+ topic_tags = {},
229+ }
230+ end, problems)
225231 end
226232
227233 ---@param problems lc.cache.Question[]
@@ -234,7 +240,9 @@ function utils.translate_titles(problems, titles)
234240
235241 return vim.tbl_map(function(p)
236242 local title = map[tostring(p.id)]
237- if title then p.title_cn = title end
243+ if title then
244+ p.title_cn = title
245+ end
238246 return p
239247 end, problems)
240248 end
+21-7lua/leetcode/cache/cookie.lua
@@ -20,30 +20,40 @@ local Cookie = {}
2020 ---@return string|nil
2121 function Cookie.set(str)
2222 local _, cerr = Cookie.parse(str)
23- if cerr then return cerr end
23+ if cerr then
24+ return cerr
25+ end
2426
2527 file:write(str, "w")
2628 local auth_api = require("leetcode.api.auth")
2729 local _, aerr = auth_api.user()
2830
29- if aerr then return aerr.msg end
31+ if aerr then
32+ return aerr.msg
33+ end
3034 end
3135
3236 ---@return boolean
3337 function Cookie.delete()
34- if not file:exists() then return false end
38+ if not file:exists() then
39+ return false
40+ end
3541 return pcall(path.rm, file)
3642 end
3743
3844 ---@return lc.cache.Cookie | nil
3945 function Cookie.get()
40- if not file:exists() then return end
46+ if not file:exists() then
47+ return
48+ end
4149
4250 local fstats = file:_stat()
4351 local ftime = fstats.mtime.sec
4452
4553 local hcookie = hist[ftime]
46- if hcookie then return hcookie end
54+ if hcookie then
55+ return hcookie
56+ end
4757
4858 local contents = file:read()
4959 if not contents or type(contents) ~= "string" then
@@ -66,10 +76,14 @@ end
6676 ---@return lc.cache.Cookie|nil, string|nil
6777 function Cookie.parse(str)
6878 local csrf = str:match("csrftoken=([^;]+)")
69- if not csrf or csrf == "" then return nil, "Bad csrf token format" end
79+ if not csrf or csrf == "" then
80+ return nil, "Bad csrf token format"
81+ end
7082
7183 local ls = str:match("LEETCODE_SESSION=([^;]+)")
72- if not ls or ls == "" then return nil, "Bad leetcode session token format" end
84+ if not ls or ls == "" then
85+ return nil, "Bad leetcode session token format"
86+ end
7387
7488 return { csrftoken = csrf, leetcode_session = ls, str = str }
7589 end
+3-1lua/leetcode/cache/init.lua
@@ -3,6 +3,8 @@ local Problemlist = require("leetcode.cache.problemlist")
33 ---@class lc.Cache
44 local cache = {}
55
6-function cache.update() Problemlist.update() end
6+function cache.update()
7+ Problemlist.update()
8+end
79
810 return cache
+33-11lua/leetcode/cache/problemlist.lua
@@ -28,17 +28,25 @@ local hist = nil
2828 local Problemlist = {}
2929
3030 ---@return lc.cache.Question[]
31-function Problemlist.get() return Problemlist.read().data end
31+function Problemlist.get()
32+ return Problemlist.read().data
33+end
3234
3335 ---@return lc.cache.payload
3436 function Problemlist.read()
35- if not file:exists() then return Problemlist.populate() end
37+ if not file:exists() then
38+ return Problemlist.populate()
39+ end
3640
3741 local time = os.time()
38- if hist and (time - hist.at) <= math.min(60, interval) then return hist.payload end
42+ if hist and (time - hist.at) <= math.min(60, interval) then
43+ return hist.payload
44+ end
3945
4046 local contents = file:read()
41- if not contents or type(contents) ~= "string" then return Problemlist.populate() end
47+ if not contents or type(contents) ~= "string" then
48+ return Problemlist.populate()
49+ end
4250
4351 local cached = Problemlist.parse(contents)
4452
@@ -47,7 +55,9 @@ function Problemlist.read()
4755 end
4856
4957 hist = { at = time, payload = cached }
50- if (time - cached.updated_at) > interval then Problemlist.update() end
58+ if (time - cached.updated_at) > interval then
59+ Problemlist.update()
60+ end
5161
5262 return cached
5363 end
@@ -67,7 +77,9 @@ end
6777
6878 function Problemlist.update()
6979 problems_api.all(function(res, err)
70- if not err then Problemlist.write({ data = res }) end
80+ if not err then
81+ Problemlist.write({ data = res })
82+ end
7183 end, true)
7284 end
7385
@@ -75,7 +87,9 @@ end
7587 function Problemlist.get_by_title_slug(title_slug)
7688 local problems = Problemlist.get()
7789
78- local problem = vim.tbl_filter(function(e) return e.title_slug == title_slug end, problems)[1]
90+ local problem = vim.tbl_filter(function(e)
91+ return e.title_slug == title_slug
92+ end, problems)[1]
7993
8094 assert(problem, ("Problem `%s` not found. Try updating cache?"):format(title_slug))
8195 return problem
@@ -89,7 +103,9 @@ function Problemlist.write(payload)
89103 username = config.auth.name,
90104 }, payload)
91105
92- if not payload.data then payload.data = Problemlist.get() end
106+ if not payload.data then
107+ payload.data = Problemlist.get()
108+ end
93109
94110 file:write(vim.json.encode(payload), "w")
95111 hist = { at = os.time(), payload = payload }
@@ -100,7 +116,9 @@ end
100116 ---@param str string
101117 ---
102118 ---@return lc.cache.payload
103-function Problemlist.parse(str) return vim.json.decode(str) end
119+function Problemlist.parse(str)
120+ return vim.json.decode(str)
121+end
104122
105123 ---@param title_slug string
106124 ---@param status "ac" | "notac"
@@ -108,7 +126,9 @@ Problemlist.change_status = vim.schedule_wrap(function(title_slug, status)
108126 local cached = Problemlist.read()
109127
110128 cached.data = vim.tbl_map(function(p)
111- if p.title_slug == title_slug then p.status = status end
129+ if p.title_slug == title_slug then
130+ p.status = status
131+ end
112132 return p
113133 end, cached.data)
114134
@@ -116,7 +136,9 @@ Problemlist.change_status = vim.schedule_wrap(function(title_slug, status)
116136 end)
117137
118138 function Problemlist.delete()
119- if not file:exists() then return false end
139+ if not file:exists() then
140+ return false
141+ end
120142 return pcall(path.rm, file)
121143 end
122144
+120-51lua/leetcode/command/init.lua
@@ -72,8 +72,12 @@ function cmd.cookie_prompt(cb)
7272 input:mount()
7373
7474 local keys = config.user.keys
75- input:map("n", keys.toggle, function() input:unmount() end)
76- input:on(event.BufLeave, function() input:unmount() end)
75+ input:map("n", keys.toggle, function()
76+ input:unmount()
77+ end)
78+ input:on(event.BufLeave, function()
79+ input:unmount()
80+ end)
7781 end
7882
7983 function cmd.sign_out()
@@ -110,7 +114,9 @@ cmd.expire = vim.schedule_wrap(function()
110114
111115 cmd.cookie_prompt(function(success)
112116 if success then
113- if api.nvim_tabpage_is_valid(tabp) then api.nvim_set_current_tabpage(tabp) end
117+ if api.nvim_tabpage_is_valid(tabp) then
118+ api.nvim_set_current_tabpage(tabp)
119+ end
114120 log.info("Successful re-login")
115121 else
116122 cmd.delete_cookie()
@@ -130,7 +136,9 @@ function cmd.qot()
130136 local Question = require("leetcode-ui.question")
131137
132138 problems.question_of_today(function(qot, err)
133- if err then return log.err(err) end
139+ if err then
140+ return log.err(err)
141+ end
134142 local problemlist = require("leetcode.cache.problemlist")
135143 Question(problemlist.get_by_title_slug(qot.title_slug), true):mount()
136144 end)
@@ -142,7 +150,9 @@ function cmd.random_question(opts)
142150 local problems = require("leetcode.cache.problemlist")
143151 local question = require("leetcode.api.question")
144152
145- if opts and opts.difficulty then opts.difficulty = opts.difficulty[1]:upper() end
153+ if opts and opts.difficulty then
154+ opts.difficulty = opts.difficulty[1]:upper()
155+ end
146156 if opts and opts.status then
147157 opts.status = ({
148158 ac = "AC",
@@ -152,7 +162,9 @@ function cmd.random_question(opts)
152162 end
153163
154164 local q, err = question.random(opts)
155- if err then return log.err(err) end
165+ if err then
166+ return log.err(err)
167+ end
156168
157169 local item = problems.get_by_title_slug(q.title_slug) or {}
158170 local Question = require("leetcode-ui.question")
@@ -161,7 +173,9 @@ end
161173
162174 function cmd.start_with_cmd()
163175 local leetcode = require("leetcode")
164- if leetcode.start(false) then cmd.menu() end
176+ if leetcode.start(false) then
177+ cmd.menu()
178+ end
165179 end
166180
167181 function cmd.menu()
@@ -179,7 +193,9 @@ end
179193 function cmd.yank()
180194 local utils = require("leetcode.utils")
181195 local q = utils.curr_question()
182- if not q then return end
196+ if not q then
197+ return
198+ end
183199
184200 if api.nvim_buf_is_valid(q.bufnr) and api.nvim_win_is_valid(q.winid) then
185201 api.nvim_set_current_win(q.winid)
@@ -191,43 +207,57 @@ function cmd.yank()
191207 end
192208
193209 ---@param page lc-menu.page
194-function cmd.set_menu_page(page) _Lc_state.menu:set_page(page) end
210+function cmd.set_menu_page(page)
211+ _Lc_state.menu:set_page(page)
212+end
195213
196214 function cmd.start_user_session() --
197215 cmd.set_menu_page("menu")
198216 config.stats.update()
199217 end
200218
201-function cmd.question_tabs() require("leetcode.pickers.question-tabs").pick() end
219+function cmd.question_tabs()
220+ require("leetcode.pickers.question-tabs").pick()
221+end
202222
203223 function cmd.change_lang()
204224 local utils = require("leetcode.utils")
205225 local q = utils.curr_question()
206- if q then require("leetcode.pickers.language").pick(q) end
226+ if q then
227+ require("leetcode.pickers.language").pick(q)
228+ end
207229 end
208230
209231 function cmd.desc_toggle()
210232 local utils = require("leetcode.utils")
211233 local q = utils.curr_question()
212- if q then q.description:toggle() end
234+ if q then
235+ q.description:toggle()
236+ end
213237 end
214238
215239 function cmd.desc_toggle_stats()
216240 local utils = require("leetcode.utils")
217241 local q = utils.curr_question()
218- if q then q.description:toggle_stats() end
242+ if q then
243+ q.description:toggle_stats()
244+ end
219245 end
220246
221247 function cmd.console()
222248 local utils = require("leetcode.utils")
223249 local q = utils.curr_question()
224- if q then q.console:toggle() end
250+ if q then
251+ q.console:toggle()
252+ end
225253 end
226254
227255 function cmd.info()
228256 local utils = require("leetcode.utils")
229257 local q = utils.curr_question()
230- if q then q.info:toggle() end
258+ if q then
259+ q.info:toggle()
260+ end
231261 end
232262
233263 function cmd.hints()
@@ -239,18 +269,24 @@ function cmd.q_run()
239269 local utils = require("leetcode.utils")
240270 utils.auth_guard()
241271 local q = utils.curr_question()
242- if q then q.console:run() end
272+ if q then
273+ q.console:run()
274+ end
243275 end
244276
245277 function cmd.q_submit()
246278 local utils = require("leetcode.utils")
247279 utils.auth_guard()
248280 local q = utils.curr_question()
249- if q then q.console:run(true) end
281+ if q then
282+ q.console:run(true)
283+ end
250284 end
251285
252286 function cmd.ui_skills()
253- if config.is_cn then return end
287+ if config.is_cn then
288+ return
289+ end
254290 local skills = require("leetcode-ui.popup.skills")
255291 skills:show()
256292 end
@@ -286,7 +322,9 @@ function cmd.reset()
286322 local utils = require("leetcode.utils")
287323 utils.auth_guard()
288324 local q = utils.curr_question()
289- if not q then return end
325+ if not q then
326+ return
327+ end
290328
291329 q:set_lines()
292330 end
@@ -295,7 +333,9 @@ function cmd.last_submit()
295333 local utils = require("leetcode.utils")
296334 utils.auth_guard()
297335 local q = utils.curr_question()
298- if not q then return end
336+ if not q then
337+ return
338+ end
299339
300340 local question_api = require("leetcode.api.question")
301341 question_api.latest_submission(q.q.id, q.lang, function(res, err) --
@@ -321,7 +361,9 @@ function cmd.restore()
321361 local utils = require("leetcode.utils")
322362 utils.auth_guard()
323363 local q = utils.curr_question()
324- if not q then return end
364+ if not q then
365+ return
366+ end
325367
326368 if
327369 (q.winid and api.nvim_win_is_valid(q.winid))
@@ -345,7 +387,9 @@ function cmd.inject()
345387 local utils = require("leetcode.utils")
346388 utils.auth_guard()
347389 local q = utils.curr_question()
348- if not q then return end
390+ if not q then
391+ return
392+ end
349393
350394 if api.nvim_buf_is_valid(q.bufnr) then
351395 local start_i, end_i = q:range(true)
@@ -377,26 +421,36 @@ end
377421
378422 function cmd.get_active_session()
379423 local sessions = config.sessions.all
380- return vim.tbl_filter(function(s) return s.is_active end, sessions)[1]
424+ return vim.tbl_filter(function(s)
425+ return s.is_active
426+ end, sessions)[1]
381427 end
382428
383429 function cmd.get_session_by_name(name)
384430 local sessions = config.sessions.all
385431
386432 name = name:lower()
387- if name == config.sessions.default then name = "" end
388- return vim.tbl_filter(function(s) return s.name:lower() == name end, sessions)[1]
433+ if name == config.sessions.default then
434+ name = ""
435+ end
436+ return vim.tbl_filter(function(s)
437+ return s.name:lower() == name
438+ end, sessions)[1]
389439 end
390440
391441 function cmd.change_session(opts)
392442 local name = opts.name[1] or config.sessions.default
393443
394444 local session = cmd.get_session_by_name(name)
395- if not session then return log.error("Session not found") end
445+ if not session then
446+ return log.error("Session not found")
447+ end
396448
397449 local stats_api = require("leetcode.api.statistics")
398450 stats_api.change_session(session.id, function(_, err)
399- if err then return log.err(err) end
451+ if err then
452+ return log.err(err)
453+ end
400454 log.info(("Session changed to `%s`"):format(name))
401455 config.stats.update()
402456 end)
@@ -404,16 +458,22 @@ end
404458
405459 function cmd.create_session(opts)
406460 local name = opts.name[1]
407- if not name then return log.error("Session name not provided") end
461+ if not name then
462+ return log.error("Session name not provided")
463+ end
408464
409465 local stats_api = require("leetcode.api.statistics")
410466 stats_api.create_session(name, function(_, err)
411- if err then return log.err(err) end
467+ if err then
468+ return log.err(err)
469+ end
412470 log.info(("session `%s` created"):format(name))
413471 end)
414472 end
415473
416-function cmd.update_sessions() config.stats.update_sessions() end
474+function cmd.update_sessions()
475+ config.stats.update_sessions()
476+end
417477
418478 function cmd.fix()
419479 require("leetcode.cache.cookie").delete()
@@ -424,12 +484,16 @@ end
424484 ---@return string[], string[]
425485 function cmd.parse(args)
426486 local parts = vim.split(vim.trim(args), "%s+")
427- if args:sub(-1) == " " then parts[#parts + 1] = "" end
487+ if args:sub(-1) == " " then
488+ parts[#parts + 1] = ""
489+ end
428490
429491 local options = {}
430492 for _, part in ipairs(parts) do
431493 local opt = part:match("(.-)=.-")
432- if opt then table.insert(options, opt) end
494+ if opt then
495+ table.insert(options, opt)
496+ end
433497 end
434498
435499 return parts, options
@@ -438,9 +502,15 @@ end
438502 ---@param tbl table
439503 local function cmds_keys(tbl)
440504 return vim.tbl_filter(function(key)
441- if type(key) ~= "string" then return false end
442- if key:sub(1, 1) == "_" then return false end
443- if tbl[key]._private then return false end
505+ if type(key) ~= "string" then
506+ return false
507+ end
508+ if key:sub(1, 1) == "_" then
509+ return false
510+ end
511+ if tbl[key]._private then
512+ return false
513+ end
444514
445515 return true
446516 end, vim.tbl_keys(tbl))
@@ -461,7 +531,9 @@ end
461531 ---
462532 ---@return string[]
463533 function cmd.rec_complete(args, options, cmds)
464- if not cmds or vim.tbl_isempty(args) then return {} end
534+ if not cmds or vim.tbl_isempty(args) then
535+ return {}
536+ end
465537
466538 if not cmds._args and cmds[args[1]] then
467539 return cmd.rec_complete(args, options, cmds[table.remove(args, 1)])
@@ -470,29 +542,26 @@ function cmd.rec_complete(args, options, cmds)
470542 local txt, keys = args[#args], cmds_keys(cmds)
471543 if cmds._args then
472544 local option_keys = cmds_keys(cmds._args)
473- option_keys = vim.tbl_filter(
474- function(key) return not vim.tbl_contains(options, key) end,
475- option_keys
476- )
477- option_keys = vim.tbl_map(function(key) return ("%s="):format(key) end, option_keys)
545+ option_keys = vim.tbl_filter(function(key)
546+ return not vim.tbl_contains(options, key)
547+ end, option_keys)
548+ option_keys = vim.tbl_map(function(key)
549+ return ("%s="):format(key)
550+ end, option_keys)
478551 keys = vim.tbl_extend("force", keys, option_keys)
479552
480553 local s = vim.split(txt, "=")
481554 if s[2] and cmds._args[s[1]] then
482555 local vals = vim.split(s[2], ",")
483- return vim.tbl_filter(
484- function(key)
485- return not vim.tbl_contains(vals, key) and key:find(vals[#vals], 1, true) == 1
486- end,
487- cmds._args[s[1]]
488- )
556+ return vim.tbl_filter(function(key)
557+ return not vim.tbl_contains(vals, key) and key:find(vals[#vals], 1, true) == 1
558+ end, cmds._args[s[1]])
489559 end
490560 end
491561
492- return vim.tbl_filter(
493- function(key) return not vim.tbl_contains(args, key) and key:find(txt, 1, true) == 1 end,
494- keys
495- )
562+ return vim.tbl_filter(function(key)
563+ return not vim.tbl_contains(args, key) and key:find(txt, 1, true) == 1
564+ end, keys)
496565 end
497566
498567 function cmd.exec(args)
+6-2lua/leetcode/config/hooks.lua
@@ -4,8 +4,12 @@ local hooks = {}
44 hooks["question_enter"] = {
55 vim.schedule_wrap(function(q)
66 -- https://github.com/kawre/leetcode.nvim/issues/14
7- if q.lang ~= "rust" then return end
8- pcall(function() require("rust-tools.standalone").start_standalone_client() end)
7+ if q.lang ~= "rust" then
8+ return
9+ end
10+ pcall(function()
11+ require("rust-tools.standalone").start_standalone_client()
12+ end)
913 end),
1014 }
1115
+13-5lua/leetcode/config/init.lua
@@ -73,14 +73,18 @@ function config.validate()
7373
7474 assert(vim.fn.has("nvim-0.9.0") == 1, "Neovim >= 0.9.0 required")
7575
76- if not utils.get_lang(config.lang) then --
76+ if not utils.get_lang(config.lang) then
7777 ---@type lc.lang[]
78- local lang_slugs = vim.tbl_map(function(lang) return lang.slug end, config.langs)
78+ local lang_slugs = vim.tbl_map(function(lang)
79+ return lang.slug
80+ end, config.langs)
7981
8082 local matches = {}
8183 for _, slug in ipairs(lang_slugs) do
8284 local percent = slug:match(config.lang) or config.lang:match(slug)
83- if percent then table.insert(matches, slug) end
85+ if percent then
86+ table.insert(matches, slug)
87+ end
8488 end
8589
8690 if not vim.tbl_isempty(matches) then
@@ -95,10 +99,14 @@ end
9599 function config.load_plugins()
96100 local plugins = {}
97101
98- if config.user.cn.enabled then table.insert(plugins, "cn") end
102+ if config.user.cn.enabled then
103+ table.insert(plugins, "cn")
104+ end
99105
100106 for plugin, enabled in pairs(config.user.plugins) do
101- if enabled then table.insert(plugins, plugin) end
107+ if enabled then
108+ table.insert(plugins, plugin)
109+ end
102110 end
103111
104112 for _, plugin in ipairs(plugins) do
+9-3lua/leetcode/config/stats.lua
@@ -9,7 +9,9 @@ function Stats.update_streak()
99 local log = require("leetcode.logger")
1010
1111 stats_api.streak(function(res, err)
12- if err then return log.err(err) end
12+ if err then
13+ return log.err(err)
14+ end
1315
1416 Stats.daily.streak = res.streakCount
1517 Stats.daily.today_completed = res.todayCompleted
@@ -25,13 +27,17 @@ function Stats.update_sessions()
2527 Stats.progress = {}
2628
2729 stats_api.sessions(function(_, err)
28- if err then return log.err(err) end
30+ if err then
31+ return log.err(err)
32+ end
2933
3034 _Lc_state.menu:draw()
3135 end)
3236
3337 stats_api.session_progress(function(res, err)
34- if err then return log.err(err) end
38+ if err then
39+ return log.err(err)
40+ end
3541
3642 Stats.progress = {}
3743
+24-8lua/leetcode/logger/init.lua
@@ -1,5 +1,7 @@
11 local n_ok, notify = pcall(require, "notify")
2-if n_ok then vim.notify = notify end
2+if n_ok then
3+ vim.notify = notify
4+end
35
46 local config = require("leetcode.config")
57 local t = require("leetcode.translator")
@@ -8,7 +10,9 @@ local lvls = vim.log.levels
810 ---@class lc.Logger
911 local logger = {}
1012
11-local function normalize(msg) return type(msg) == "string" and t(msg) or vim.inspect(msg) end
13+local function normalize(msg)
14+ return type(msg) == "string" and t(msg) or vim.inspect(msg)
15+end
1216
1317 -- ---@private
1418 -- ---@param msg any
@@ -18,22 +22,30 @@ local function normalize(msg) return type(msg) == "string" and t(msg) or vim.ins
1822 -- end)
1923
2024 function logger.log(msg, lvl)
21- if not config.user.logging then return end
25+ if not config.user.logging then
26+ return
27+ end
2228
2329 local title = config.name
2430 lvl = lvl or lvls.INFO
2531 msg = normalize(msg)
2632
27- if lvl == lvls.DEBUG then msg = debug.traceback(msg .. "\n") end
33+ if lvl == lvls.DEBUG then
34+ msg = debug.traceback(msg .. "\n")
35+ end
2836
2937 vim.notify(msg, lvl, { title = title })
3038 end
3139
3240 ---@param msg any
33-logger.info = function(msg) logger.log(msg) end
41+logger.info = function(msg)
42+ logger.log(msg)
43+end
3444
3545 ---@param msg any
36-logger.warn = function(msg) logger.log(msg, lvls.WARN) end
46+logger.warn = function(msg)
47+ logger.log(msg, lvls.WARN)
48+end
3749
3850 ---@param msg any
3951 logger.error = function(msg)
@@ -43,7 +55,9 @@ end
4355
4456 ---@param err lc.err
4557 logger.err = function(err)
46- if not err then return logger.error("error") end
58+ if not err then
59+ return logger.error("error")
60+ end
4761
4862 local msg = err.msg or ""
4963 local lvl = err.lvl or lvls.ERROR
@@ -55,7 +69,9 @@ end
5569 ---@param show? boolean
5670 ---@return any
5771 logger.debug = function(msg, show)
58- if not config.debug then return msg end
72+ if not config.debug then
73+ return msg
74+ end
5975
6076 local lvl = (show == nil or not show) and lvls.DEBUG or lvls.ERROR
6177 logger.log(msg, lvl)
+18-6lua/leetcode/logger/spinner/init.lua
@@ -42,7 +42,9 @@ local spinners = {
4242 ---@private
4343 function spinner:spin()
4444 local stype = self.spinner
45- if not stype then return end
45+ if not stype then
46+ return
47+ end
4648
4749 self:set(nil, nil, {
4850 icon = stype.frames[self.index + 1],
@@ -51,7 +53,9 @@ function spinner:spin()
5153 self.index = (self.index + 1) % #stype.frames
5254
5355 local fps = math.floor(1000 / stype.fps)
54- vim.defer_fn(function() self:spin() end, fps)
56+ vim.defer_fn(function()
57+ self:spin()
58+ end, fps)
5559 end
5660
5761 ---@private
@@ -60,9 +64,13 @@ end
6064 ---@param lvl? integer
6165 ---@param opts? table
6266 function spinner:set(msg, lvl, opts)
63- if not self.spinner then return end
67+ if not self.spinner then
68+ return
69+ end
6470
65- if msg then self:update(msg) end
71+ if msg then
72+ self:update(msg)
73+ end
6674 lvl = lvl or vim.log.levels.INFO
6775
6876 opts = vim.tbl_deep_extend("force", {
@@ -76,10 +84,14 @@ function spinner:set(msg, lvl, opts)
7684 end
7785
7886 ---@param spinner_type lc.spinner_types
79-function spinner:change(spinner_type) self.spinner = spinners[spinner_type] end
87+function spinner:change(spinner_type)
88+ self.spinner = spinners[spinner_type]
89+end
8090
8191 ---@param msg any
82-function spinner:update(msg) self.msg = t(tostring(msg)) end
92+function spinner:update(msg)
93+ self.msg = t(tostring(msg))
94+end
8395
8496 function spinner:start()
8597 self:spin()
+6-2lua/leetcode/parser/normalizer.lua
@@ -64,7 +64,9 @@ function Normalizer:entities()
6464 :gsub("\n", "&lcnl;")
6565 :gsub("\t", "&lctab;")
6666 :gsub("%s", "&nbsp;")
67- :gsub("<[^>]+>", function(match) return match:gsub("&nbsp;", " ") end)
67+ :gsub("<[^>]+>", function(match)
68+ return match:gsub("&nbsp;", " ")
69+ end)
6870 end
6971
7072 ---@param text string
@@ -84,6 +86,8 @@ end
8486 local LeetNormalizer = Normalizer
8587
8688 ---@param text string
87-function Normalizer:norm(text) return LeetNormalizer(text).text end
89+function Normalizer:norm(text)
90+ return LeetNormalizer(text).text
91+end
8892
8993 return LeetNormalizer
+6-2lua/leetcode/parser/plain.lua
@@ -7,7 +7,9 @@ local u = require("leetcode.parser.utils")
77 ---@field text string
88 local Plain = Group:extend("LeetParserPlain")
99
10-function Plain.normalize(text) return text:gsub("<[^>]+>", "") end
10+function Plain.normalize(text)
11+ return text:gsub("<[^>]+>", "")
12+end
1113
1214 ---@param text string
1315 function Plain:init(text)
@@ -24,6 +26,8 @@ end
2426 local LeetParserPlain = Plain
2527
2628 ---@param text string
27-function Plain.static:parse(text) return LeetParserPlain(text) end
29+function Plain.static:parse(text)
30+ return LeetParserPlain(text)
31+end
2832
2933 return LeetParserPlain
+6-2lua/leetcode/parser/utils.lua
@@ -99,10 +99,14 @@ function utils.hl(tag) --
9999 local tag_names = {}
100100
101101 for _, v in ipairs(tag.tags) do
102- if v.name then table.insert(tag_names, v.name) end
102+ if v.name then
103+ table.insert(tag_names, v.name)
104+ end
103105 end
104106
105- if tag.name then table.insert(tag_names, tag.name) end
107+ if tag.name then
108+ table.insert(tag_names, tag.name)
109+ end
106110
107111 return theme.get_dynamic(tag_names)
108112 end
+12-4lua/leetcode/pickers/language.lua
@@ -17,7 +17,9 @@ local M = {}
1717 ---@param snippet lc.QuestionCodeSnippet
1818 ---
1919 ---@return string
20-local function lang_formatter(snippet) return string.format("%s %s", snippet.t.lang, snippet.t.slug) end
20+local function lang_formatter(snippet)
21+ return string.format("%s %s", snippet.t.lang, snippet.t.slug)
22+end
2123
2224 ---@param snippet lc.QuestionCodeSnippet
2325 local function dislay_icon(snippet)
@@ -55,7 +57,9 @@ end
5557 local function entry_maker(entry)
5658 ---@type lc.language
5759 entry.t = utils.get_lang(entry.lang_slug)
58- if not entry.t then return end
60+ if not entry.t then
61+ return
62+ end
5963
6064 return {
6165 value = entry,
@@ -79,7 +83,9 @@ M.pick_lang = function(question, callback)
7983 attach_mappings = function(prompt_bufnr, map)
8084 actions.select_default:replace(function()
8185 local selection = action_state.get_selected_entry()
82- if not selection then return end
86+ if not selection then
87+ return
88+ end
8389
8490 local snippet = selection.value
8591 if question.lang == snippet.t.slug then
@@ -112,7 +118,9 @@ M.pick = function(question)
112118 attach_mappings = function(prompt_bufnr, map)
113119 actions.select_default:replace(function()
114120 local selection = action_state.get_selected_entry()
115- if not selection then return end
121+ if not selection then
122+ return
123+ end
116124
117125 local snippet = selection.value
118126 if question.lang == snippet.t.slug then
+13-5lua/leetcode/pickers/question-tabs.lua
@@ -22,14 +22,18 @@ end
2222
2323 local function display_current(entry)
2424 local tabp = vim.api.nvim_get_current_tabpage()
25- if tabp ~= entry.tabpage then return unpack({ "", "" }) end
25+ if tabp ~= entry.tabpage then
26+ return unpack({ "", "" })
27+ end
2628
2729 return { icons.caret.right, "leetcode_ref" }
2830 end
2931
3032 local function display_difficulty(q)
3133 local lang = utils.get_lang(q.lang)
32- if not lang then return {} end
34+ if not lang then
35+ return {}
36+ end
3337 return { lang.icon, "leetcode_lang_" .. lang.slug }
3438 end
3539
@@ -78,7 +82,7 @@ return {
7882 pick = function()
7983 local tabs = utils.question_tabs()
8084
81- if vim.tbl_isempty(tabs) then --
85+ if vim.tbl_isempty(tabs) then
8286 return log.warn("No questions opened")
8387 end
8488
@@ -101,10 +105,14 @@ return {
101105 actions.close(prompt_bufnr)
102106 local selection = action_state.get_selected_entry()
103107
104- if not selection then return end
108+ if not selection then
109+ return
110+ end
105111 local ok, err =
106112 pcall(vim.api.nvim_set_current_tabpage, selection.value.tabpage)
107- if not ok then log.error(err) end
113+ if not ok then
114+ log.error(err)
115+ end
108116 end)
109117 return true
110118 end,
+16-6lua/leetcode/pickers/question.lua
@@ -38,7 +38,9 @@ local function display_user_status(question)
3838 return config.auth.is_premium and config.icons.hl.unlock or config.icons.hl.lock
3939 end
4040
41- if question.status == vim.NIL then return { "" } end
41+ if question.status == vim.NIL then
42+ return { "" }
43+ end
4244 return config.icons.hl.status[question.status] or { "" }
4345 end
4446
@@ -94,7 +96,9 @@ local theme = require("telescope.themes").get_dropdown({
9496 ---
9597 ---@return lc.cache.Question[]
9698 local function filter_questions(questions, opts)
97- if vim.tbl_isempty(opts or {}) then return questions end
99+ if vim.tbl_isempty(opts or {}) then
100+ return questions
101+ end
98102
99103 ---@param q lc.cache.Question
100104 return vim.tbl_filter(function(q)
@@ -104,7 +108,7 @@ local function filter_questions(questions, opts)
104108 end
105109
106110 local status_flag = true
107- if opts.status and not vim.tbl_contains(opts.status, q.status) then --
111+ if opts.status and not vim.tbl_contains(opts.status, q.status) then
108112 status_flag = false
109113 end
110114
@@ -126,7 +130,9 @@ return {
126130 attach_mappings = function(prompt_bufnr, map)
127131 local function mount_question(reset)
128132 local selection = action_state.get_selected_entry()
129- if not selection then return end
133+ if not selection then
134+ return
135+ end
130136
131137 local q = selection.value
132138 if q.paid_only and not config.auth.is_premium then
@@ -137,8 +143,12 @@ return {
137143 Question(q, reset):mount()
138144 end
139145
140- actions.select_default:replace(function() mount_question() end)
141- map({ "n", "i" }, "<C-Enter>", function() mount_question(true) end)
146+ actions.select_default:replace(function()
147+ mount_question()
148+ end)
149+ map({ "n", "i" }, "<C-Enter>", function()
150+ mount_question(true)
151+ end)
142152
143153 return true
144154 end,
+15-5lua/leetcode/runner/init.lua
@@ -17,7 +17,9 @@ Runner.running = false
1717 ---@param self lc.Runner
1818 ---@param submit boolean
1919 Runner.run = vim.schedule_wrap(function(self, submit)
20- if Runner.running then return log.warn("Runner is busy") end
20+ if Runner.running then
21+ return log.warn("Runner is busy")
22+ end
2123
2224 local ok, err = pcall(Runner.handle, self, submit)
2325 if not ok then
@@ -26,7 +28,9 @@ Runner.run = vim.schedule_wrap(function(self, submit)
2628 end
2729 end)
2830
29-Runner.stop = function() Runner.running = false end
31+Runner.stop = function()
32+ Runner.running = false
33+end
3034
3135 function Runner:handle(submit)
3236 Runner.running = true
@@ -41,7 +45,9 @@ function Runner:handle(submit)
4145
4246 local judge = Judge:init()
4347 local function callback(item, state, err)
44- if err or item then self:stop() end
48+ if err or item then
49+ self:stop()
50+ end
4551
4652 if item then
4753 judge:stop(item.status_msg, item._.success)
@@ -51,7 +57,9 @@ function Runner:handle(submit)
5157 judge:stop(err.msg or "Something went wrong", false)
5258 end
5359
54- if item then question.console.result:handle(item) end
60+ if item then
61+ question.console.result:handle(item)
62+ end
5563 end
5664
5765 leetbody:write(vim.json.encode(body), "w")
@@ -59,6 +67,8 @@ function Runner:handle(submit)
5967 end
6068
6169 ---@param question lc.ui.Question
62-function Runner:init(question) return setmetatable({ question = question }, self) end
70+function Runner:init(question)
71+ return setmetatable({ question = question }, self)
72+end
6373
6474 return Runner
+3-1lua/leetcode/runner/utils.lua
@@ -1,6 +1,8 @@
11 local utils = {}
22
33 ---@param lines string[]
4-function utils.to_typed_code(lines) return table.concat(lines, "\n") end
4+function utils.to_typed_code(lines)
5+ return table.concat(lines, "\n")
6+end
57
68 return utils
+6-2lua/leetcode/theme/default.lua
@@ -8,8 +8,12 @@ local function hl(name)
88 local highlight = vim.api.nvim_get_hl(0, { name = name, link = false })
99 setmetatable(highlight, {
1010 __index = function(self, key)
11- if key == "bg" then return self.background end
12- if key == "fg" then return self.foreground end
11+ if key == "bg" then
12+ return self.background
13+ end
14+ if key == "fg" then
15+ return self.foreground
16+ end
1317
1418 return nil
1519 end,
+21-7lua/leetcode/theme/init.lua
@@ -45,8 +45,12 @@ function theme.load_devicons()
4545 vim.tbl_map(function(l)
4646 local icon, color = devicons.get_icon_color(l.ft)
4747
48- if icon then l.icon = icon end
49- if color then l.color = color end
48+ if icon then
49+ l.icon = icon
50+ end
51+ if color then
52+ l.color = color
53+ end
5054
5155 return l
5256 end, config.langs)
@@ -60,7 +64,9 @@ function theme.load()
6064 vim.api.nvim_set_hl(0, key, t)
6165 end
6266
63- if devicons_ok then theme.load_devicons() end
67+ if devicons_ok then
68+ theme.load_devicons()
69+ end
6470
6571 ---@param lang lc.language
6672 vim.tbl_map(function(lang)
@@ -82,10 +88,14 @@ end
8288
8389 ---@param tags string[]
8490 function theme.get_dynamic(tags)
85- if vim.tbl_isempty(tags) then return "leetcode_normal" end
91+ if vim.tbl_isempty(tags) then
92+ return "leetcode_normal"
93+ end
8694
8795 local name = "leetcode_dyn_" .. table.concat(tags, "_")
88- if dynamic_hls[name] then return name end
96+ if dynamic_hls[name] then
97+ return name
98+ end
8999
90100 return theme.create_dynamic(name, tags)
91101 end
@@ -99,11 +109,15 @@ function theme.create_dynamic(name, tags, defaults)
99109 local tbl = defaults["normal"]
100110 for _, tag in ipairs(tags) do
101111 local hl = highlights[tag]
102- if hl then tbl = vim.tbl_extend("force", tbl, defaults[hl]) end
112+ if hl then
113+ tbl = vim.tbl_extend("force", tbl, defaults[hl])
114+ end
103115 end
104116
105117 if tbl.italic or tbl.bold then
106- if tbl.fg == defaults["normal"].fg then tbl.fg = defaults[""].fg end
118+ if tbl.fg == defaults["normal"].fg then
119+ tbl.fg = defaults[""].fg
120+ end
107121 end
108122
109123 if pcall(vim.api.nvim_set_hl, 0, name, tbl) then
+6-2lua/leetcode/translator.lua
@@ -94,9 +94,13 @@ local translate = {
9494
9595 ---@param text string
9696 local function t(text)
97- local keys = vim.tbl_map(function(key) return key:lower() end, vim.tbl_keys(translate))
97+ local keys = vim.tbl_map(function(key)
98+ return key:lower()
99+ end, vim.tbl_keys(translate))
98100
99- if not vim.tbl_contains(keys, text:lower()) then return text end
101+ if not vim.tbl_contains(keys, text:lower()) then
102+ return text
103+ end
100104 return translate[text:lower()]
101105 end
102106
+33-11lua/leetcode/utils.lua
@@ -13,7 +13,9 @@ function utils.deprecate_usr_cmd(name, new)
1313 end
1414
1515 ---@param fn string
16-function utils.cmd(fn) return ("<cmd>lua require('leetcode.command').%s()<cr>"):format(fn) end
16+function utils.cmd(fn)
17+ return ("<cmd>lua require('leetcode.command').%s()<cr>"):format(fn)
18+end
1719
1820 ---@param title_slug string
1921 ---@param lang lc.lang
@@ -33,7 +35,9 @@ function utils.question_tabs()
3335
3436 for _, q in ipairs(_Lc_state.questions) do
3537 local tabp = utils.question_tabp(q)
36- if tabp then table.insert(questions, { tabpage = tabp, question = q }) end
38+ if tabp then
39+ table.insert(questions, { tabpage = tabp, question = q })
40+ end
3741 end
3842
3943 return questions
@@ -43,7 +47,9 @@ end
4347 ---@return integer|nil
4448 function utils.question_tabp(q)
4549 local ok, tabp = pcall(vim.api.nvim_win_get_tabpage, q.winid)
46- if ok then return tabp end
50+ if ok then
51+ return tabp
52+ end
4753 end
4854
4955 ---@return lc.ui.Question
@@ -51,7 +57,9 @@ function utils.curr_question()
5157 local tabp = vim.api.nvim_get_current_tabpage()
5258 local tabs = utils.question_tabs()
5359
54- local tab = vim.tbl_filter(function(tab) return tab.tabpage == tabp end, tabs)[1] or {}
60+ local tab = vim.tbl_filter(function(tab)
61+ return tab.tabpage == tabp
62+ end, tabs)[1] or {}
5563 if tab.question then
5664 return tab.question, tabp
5765 else
@@ -62,22 +70,30 @@ end
6270 ---@return lc.language
6371 function utils.get_lang(slug)
6472 ---@param l lc.language
65- return vim.tbl_filter(function(l) return l.slug == slug end, config.langs)[1]
73+ return vim.tbl_filter(function(l)
74+ return l.slug == slug
75+ end, config.langs)[1]
6676 end
6777
6878 ---@return lc.language
6979 function utils.get_lang_by_name(name)
7080 ---@param l lc.language
71- return vim.tbl_filter(function(l) return l.lang == name end, config.langs)[1]
81+ return vim.tbl_filter(function(l)
82+ return l.lang == name
83+ end, config.langs)[1]
7284 end
7385
7486 ---@param event lc.hook
7587 ---@return fun()[]|nil
7688 function utils.get_hooks(event)
7789 local fns = config.user.hooks[event]
78- if not fns then return end
90+ if not fns then
91+ return
92+ end
7993
80- if type(fns) == "function" then fns = { fns } end
94+ if type(fns) == "function" then
95+ fns = { fns }
96+ end
8197
8298 return vim.list_extend(fns, config.hooks[event] or {})
8399 end
@@ -85,11 +101,15 @@ end
85101 ---@param event lc.hook
86102 function utils.exec_hooks(event, ...)
87103 local fns = utils.get_hooks(event)
88- if not fns then return log.error("unknown hook event: " .. event) end
104+ if not fns then
105+ return log.error("unknown hook event: " .. event)
106+ end
89107
90108 for i, fn in ipairs(fns) do
91109 local ok, msg = pcall(fn, ...)
92- if not ok then log.error(("bad hook #%d in `%s` event: %s"):format(i, event, msg)) end
110+ if not ok then
111+ log.error(("bad hook #%d in `%s` event: %s"):format(i, event, msg))
112+ end
93113 end
94114 end
95115
@@ -107,7 +127,9 @@ function utils.translate(content, translated_content)
107127 end
108128 end
109129
110-function utils.auth_guard() assert(config.auth.is_signed_in, "User not logged-in") end
130+function utils.auth_guard()
131+ assert(config.auth.is_signed_in, "User not logged-in")
132+end
111133
112134 function utils.norm_ins(str)
113135 local ins = vim.inspect(str)