From 4cc235ce4c60afaaf7e729ca500caf2475ecaedf Mon Sep 17 00:00:00 2001 From: lunar Date: Sat, 21 Dec 2024 11:29:05 +0800 Subject: [PATCH 1/2] support function type injector --- lua/leetcode-ui/question.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/leetcode-ui/question.lua b/lua/leetcode-ui/question.lua index e8204746..f427800f 100644 --- a/lua/leetcode-ui/question.lua +++ b/lua/leetcode-ui/question.lua @@ -110,7 +110,8 @@ function Question:open_buffer(existed) end ---@param before boolean -function Question:inject(before) +---@param code string +function Question:inject(before, code) local inject = config.user.injector[self.lang] or {} local inj = before and inject.before or inject.after @@ -120,6 +121,10 @@ function Question:inject(before) inj = config.imports[self.lang] end + if type(inj) == "function" then + inj = inj(code) + end + if type(inj) == "table" then res = table.concat(inj, "\n") elseif type(inj) == "string" then @@ -143,12 +148,12 @@ function Question:injector(code) ("%s @leet end"):format(lang.comment), } - local before = self:inject(true) + local before = self:inject(true, code) if before then table.insert(parts, 1, before) end - local after = self:inject(false) + local after = self:inject(false, code) if after then table.insert(parts, after) end From b58e81327ff913146609b2c207350a375d29ab3b Mon Sep 17 00:00:00 2001 From: lunar <2100125584@qq.com> Date: Sun, 29 Dec 2024 18:14:20 +0800 Subject: [PATCH 2/2] don't want the injected code folded --- lua/leetcode-ui/question.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/leetcode-ui/question.lua b/lua/leetcode-ui/question.lua index f427800f..116e5be6 100644 --- a/lua/leetcode-ui/question.lua +++ b/lua/leetcode-ui/question.lua @@ -99,10 +99,10 @@ function Question:open_buffer(existed) ui_utils.buf_set_opts(self.bufnr, { buflisted = true }) ui_utils.win_set_buf(self.winid, self.bufnr, true) - local i = self:fold_range() - if i then - pcall(vim.cmd, ("%d,%dfold"):format(1, i)) - end + -- local i = self:fold_range() + -- if i then + -- pcall(vim.cmd, ("%d,%dfold"):format(1, i)) + -- end if existed and self.cache.status == "ac" then self:reset_lines()