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

Commit 93e5485

Browse files
committed
feat: custom injection code snippets
1 parent 2a079ff commit 93e5485

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lua/leetcode-ui/question.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,36 @@ local log = require("leetcode.logger")
1919
local Question = Object("LeetQuestion")
2020

2121
function Question:get_snippet()
22+
local inject = config.user.inject
23+
-- If inject.start is a string, assign to inject_start
24+
-- else if inject.start is a string[], join into inject_start with "\n" as separator
25+
local inject_before = ""
26+
local inject_after = ""
27+
28+
if type(inject.before) == "string" then
29+
inject_before = inject.before
30+
else
31+
inject_before = table.concat(inject.before, "\n")
32+
end
33+
if type(inject.after) == "string" then
34+
inject_after = inject.after
35+
else
36+
inject_after = table.concat(inject.after, "\n")
37+
end
38+
2239
local snippets = self.q.code_snippets ~= vim.NIL and self.q.code_snippets or {}
2340
local snip = vim.tbl_filter(function(snip) return snip.lang_slug == self.lang end, snippets)[1]
2441
if not snip then return end
2542

2643
local lang = utils.get_lang(self.lang)
2744
snip.code = (snip.code or ""):gsub("\r\n", "\n")
28-
return ("%s @leet start\n%s\n%s @leet end"):format(lang.comment, snip.code, lang.comment)
45+
return ("%s\n%s @leet start\n%s\n%s @leet end\n%s"):format(
46+
inject_before,
47+
lang.comment,
48+
snip.code,
49+
lang.comment,
50+
inject_after
51+
)
2952
end
3053

3154
---@private

lua/leetcode/config/template.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ local M = {
110110
focus_testcases = "H", ---@type string
111111
focus_result = "L", ---@type string
112112
},
113+
114+
inject = {
115+
before = "", ---@type string|string[]
116+
after = "", ---@type string|string[]
117+
}
113118
}
114119

115120
return M

0 commit comments

Comments
 (0)