A Neovim plugin enabling you to solve LeetCode problems.
docs(readme): `cn` section
8 files changed, +58 -55
+17-8README.md
| @@ -72,21 +72,27 @@ To see full configuration types see [template.lua](./lua/leetcode/config/templat | ||
| 72 | 72 | |
| 73 | 73 | ```lua |
| 74 | 74 | { |
| 75 | - ---@type lc.domain | |
| 76 | - domain = "com", -- For now "com" is the only one supported | |
| 77 | - | |
| 78 | 75 | ---@type string |
| 79 | 76 | arg = "leetcode.nvim", |
| 80 | 77 | |
| 81 | 78 | ---@type lc.lang |
| 82 | 79 | lang = "cpp", |
| 83 | 80 | |
| 81 | + cn = { -- leetcode.cn | |
| 82 | + enabled = false, ---@type boolean | |
| 83 | + translate_problems = true, ---@type boolean | |
| 84 | + }, | |
| 85 | + | |
| 84 | 86 | ---@type string |
| 85 | 87 | directory = vim.fn.stdpath("data") .. "/leetcode/", |
| 86 | 88 | |
| 87 | 89 | ---@type boolean |
| 88 | 90 | logging = true, |
| 89 | 91 | |
| 92 | + cache = { | |
| 93 | + update_interval = 60 * 60 * 24 * 7, ---@type integer 7 days | |
| 94 | + }, | |
| 95 | + | |
| 90 | 96 | console = { |
| 91 | 97 | open_on_runcode = true, ---@type boolean |
| 92 | 98 | |
| @@ -147,13 +153,15 @@ Language to start your session with | ||
| 147 | 153 | lang = "cpp" |
| 148 | 154 | ``` |
| 149 | 155 | |
| 150 | -### domain | |
| 156 | +### cn | |
| 151 | 157 | |
| 152 | -[LeetCode] domain. | |
| 158 | +Use [leetcode.cn] instead of [leetcode.com][leetcode] | |
| 153 | 159 | |
| 154 | 160 | ```lua |
| 155 | ----@type lc.domain | |
| 156 | -domain = "com" -- For now "com" is the only one supported | |
| 161 | +cn = { -- leetcode.cn | |
| 162 | + enabled = false, ---@type boolean | |
| 163 | + translate_problems = true, ---@type boolean | |
| 164 | +}, | |
| 157 | 165 | ``` |
| 158 | 166 | |
| 159 | 167 | ### directory |
| @@ -242,7 +250,7 @@ image_support = false, -- setting this to `true` will disable question descripti | ||
| 242 | 250 | Can take optional arguments. To stack argument values separate them by a `,` |
| 243 | 251 | |
| 244 | 252 | ``` |
| 245 | -Leet list status=<status> topics=<topic1,...,topicN> difficulty=<difficulty> | |
| 253 | +Leet list status=<status> difficulty=<difficulty> | |
| 246 | 254 | ``` |
| 247 | 255 | |
| 248 | 256 | ## 🚀 Usage |
| @@ -303,6 +311,7 @@ return { | ||
| 303 | 311 | [image.nvim]: https://github.com/3rd/image.nvim |
| 304 | 312 | [lazy.nvim]: https://github.com/folke/lazy.nvim |
| 305 | 313 | [leetcode]: https://leetcode.com |
| 314 | +[leetcode.cn]: https://leetcode.cn | |
| 306 | 315 | [leetcode.nvim]: https://github.com/kawre/leetcode.nvim |
| 307 | 316 | [neovim]: https://github.com/neovim/neovim |
| 308 | 317 | [nerd-font]: https://www.nerdfonts.com |
+14-7README.zh.md
| @@ -76,21 +76,27 @@ https://github.com/kawre/leetcode.nvim/assets/69250723/309088c9-4ff7-4dff-ab61-a | ||
| 76 | 76 | |
| 77 | 77 | ```lua |
| 78 | 78 | { |
| 79 | - ---@type lc.domain | |
| 80 | - domain = "com", -- 目前仅支持 "com" | |
| 81 | - | |
| 82 | 79 | ---@type string |
| 83 | 80 | arg = "leetcode.nvim", |
| 84 | 81 | |
| 85 | 82 | ---@type lc.lang |
| 86 | 83 | lang = "cpp", |
| 87 | 84 | |
| 85 | + cn = { -- leetcode.cn | |
| 86 | + enabled = false, ---@type boolean | |
| 87 | + translate_problems = true, ---@type boolean | |
| 88 | + }, | |
| 89 | + | |
| 88 | 90 | ---@type string |
| 89 | 91 | directory = vim.fn.stdpath("data") .. "/leetcode/", |
| 90 | 92 | |
| 91 | 93 | ---@type boolean |
| 92 | 94 | logging = true, |
| 93 | 95 | |
| 96 | + cache = { | |
| 97 | + update_interval = 60 * 60 * 24 * 7, ---@type integer 7 days | |
| 98 | + }, | |
| 99 | + | |
| 94 | 100 | console = { |
| 95 | 101 | open_on_runcode = true, ---@type boolean |
| 96 | 102 | |
| @@ -127,7 +133,7 @@ https://github.com/kawre/leetcode.nvim/assets/69250723/309088c9-4ff7-4dff-ab61-a | ||
| 127 | 133 | }, |
| 128 | 134 | |
| 129 | 135 | ---@type boolean |
| 130 | - image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行 | |
| 136 | + image_support = false, -- setting this to `true` will disable question description wrap | |
| 131 | 137 | } |
| 132 | 138 | ``` |
| 133 | 139 | |
| @@ -151,9 +157,9 @@ arg = "leetcode.nvim" | ||
| 151 | 157 | lang = "cpp" |
| 152 | 158 | ``` |
| 153 | 159 | |
| 154 | -### domain | |
| 160 | +### cn | |
| 155 | 161 | |
| 156 | -[LeetCode] 领域 | |
| 162 | +将 [leetcode.com][leetcode] 替换为 [leetcode.cn] | |
| 157 | 163 | |
| 158 | 164 | ```lua |
| 159 | 165 | ---@type lc.domain |
| @@ -246,7 +252,7 @@ image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行 | ||
| 246 | 252 | 可以带有可选参数。要堆叠参数值,请使用 , 将它们分隔开 |
| 247 | 253 | |
| 248 | 254 | ``` |
| 249 | -Leet list status=<status> topics=<topic1,...,topicN> difficulty=<difficulty> | |
| 255 | +Leet list status=<status> difficulty=<difficulty> | |
| 250 | 256 | ``` |
| 251 | 257 | |
| 252 | 258 | ## 🚀 使用方法 |
| @@ -301,6 +307,7 @@ return { | ||
| 301 | 307 | [image.nvim]: https://github.com/3rd/image.nvim |
| 302 | 308 | [lazy.nvim]: https://github.com/folke/lazy.nvim |
| 303 | 309 | [leetcode]: https://leetcode.com |
| 310 | +[leetcode.cn]: https://leetcode.cn | |
| 304 | 311 | [leetcode.nvim]: https://github.com/kawre/leetcode.nvim |
| 305 | 312 | [neovim]: https://github.com/neovim/neovim |
| 306 | 313 | [nerd-font]: https://www.nerdfonts.com |
+1-1lua/leetcode/command/arguments.lua
| @@ -79,7 +79,7 @@ arguments.list = { | ||
| 79 | 79 | -- orderBy = { "desc", "asc" }, |
| 80 | 80 | difficulty = { "Easy", "Medium", "Hard" }, |
| 81 | 81 | status = { "ac", "notac", "todo" }, |
| 82 | - topics = topics, | |
| 82 | + -- topics = topics, | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return arguments |
+1-1lua/leetcode/config/init.lua
| @@ -39,7 +39,7 @@ end | ||
| 39 | 39 | function config.load_plugins() |
| 40 | 40 | local plugins = {} |
| 41 | 41 | |
| 42 | - if config.user.plugins.cn.enabled then table.insert(plugins, "cn") end | |
| 42 | + if config.user.cn.enabled then table.insert(plugins, "cn") end | |
| 43 | 43 | |
| 44 | 44 | for _, plugin in ipairs(plugins) do |
| 45 | 45 | local ok, plug = pcall(require, "leetcode-plugins." .. plugin) |
+8-21lua/leetcode/config/template.lua
| @@ -24,18 +24,16 @@ | ||
| 24 | 24 | ---| "react" |
| 25 | 25 | ---| "vanillajs" |
| 26 | 26 | |
| 27 | ----@alias lc.domain | |
| 28 | ----| "com" | |
| 29 | ----| "cn" | |
| 30 | - | |
| 31 | 27 | ---@alias lc.hook |
| 32 | 28 | ---| "LeetEnter" |
| 33 | 29 | ---| "LeetQuestionNew" |
| 34 | 30 | |
| 35 | 31 | ---@class lc.UserConfig |
| 36 | 32 | local M = { |
| 37 | - ---@type lc.domain | |
| 38 | - domain = "com", -- For now "com" is the only one supported | |
| 33 | + cn = { -- leetcode.cn | |
| 34 | + enabled = false, ---@type boolean | |
| 35 | + translate_problems = true, ---@type boolean | |
| 36 | + }, | |
| 39 | 37 | |
| 40 | 38 | ---@type string |
| 41 | 39 | arg = "leetcode.nvim", |
| @@ -49,6 +47,10 @@ local M = { | ||
| 49 | 47 | ---@type boolean |
| 50 | 48 | logging = true, |
| 51 | 49 | |
| 50 | + cache = { | |
| 51 | + update_interval = 60 * 60 * 24 * 7, ---@type integer 7 days | |
| 52 | + }, | |
| 53 | + | |
| 52 | 54 | console = { |
| 53 | 55 | open_on_runcode = true, ---@type boolean |
| 54 | 56 | |
| @@ -86,21 +88,6 @@ local M = { | ||
| 86 | 88 | |
| 87 | 89 | ---@type boolean |
| 88 | 90 | image_support = false, -- setting this to `true` will disable question description wrap |
| 89 | - | |
| 90 | - cache = { | |
| 91 | - ---@type integer | |
| 92 | - update_interval = 60 * 60 * 24 * 7, -- 7 days | |
| 93 | - }, | |
| 94 | - | |
| 95 | - plugins = { | |
| 96 | - cn = { | |
| 97 | - enabled = true, | |
| 98 | - translate_problems = true, ---@type boolean | |
| 99 | - }, | |
| 100 | - }, | |
| 101 | - -- cn = { | |
| 102 | - -- translate = true, ---@type boolean | |
| 103 | - -- }, | |
| 104 | 91 | } |
| 105 | 92 | |
| 106 | 93 | return M |
+14-14lua/leetcode/pickers/question.lua
| @@ -108,20 +108,20 @@ local function filter_questions(questions, opts) | ||
| 108 | 108 | |
| 109 | 109 | ---@param q lc.Cache.Question |
| 110 | 110 | return vim.tbl_filter(function(q) |
| 111 | - if opts.topics then | |
| 112 | - for _, topic in ipairs(opts.topics) do | |
| 113 | - local flag = false | |
| 114 | - | |
| 115 | - for _, tag in ipairs(q.topic_tags) do | |
| 116 | - if tag.slug == topic then | |
| 117 | - flag = true | |
| 118 | - break | |
| 119 | - end | |
| 120 | - end | |
| 121 | - | |
| 122 | - if not flag then return false end | |
| 123 | - end | |
| 124 | - end | |
| 111 | + -- if opts.topics then | |
| 112 | + -- for _, topic in ipairs(opts.topics) do | |
| 113 | + -- local flag = false | |
| 114 | + -- | |
| 115 | + -- for _, tag in ipairs(q.topic_tags) do | |
| 116 | + -- if tag.slug == topic then | |
| 117 | + -- flag = true | |
| 118 | + -- break | |
| 119 | + -- end | |
| 120 | + -- end | |
| 121 | + -- | |
| 122 | + -- if not flag then return false end | |
| 123 | + -- end | |
| 124 | + -- end | |
| 125 | 125 | |
| 126 | 126 | if opts.difficulty then |
| 127 | 127 | if not vim.tbl_contains(opts.difficulty, q.difficulty) then return false end |
+1-1lua/leetcode/utils.lua
| @@ -145,7 +145,7 @@ end | ||
| 145 | 145 | ---@param translated_content string |
| 146 | 146 | function utils.translate(content, translated_content) |
| 147 | 147 | if config.is_cn then |
| 148 | - if config.user.plugins.cn.translate_problems then | |
| 148 | + if config.user.cn.translate_problems then | |
| 149 | 149 | return translated_content or content |
| 150 | 150 | else |
| 151 | 151 | return content or translated_content |