A Neovim plugin enabling you to solve LeetCode problems.
refactor: reset code on open by default
5 files changed, +17 -31
+3-9lua/leetcode-ui/question.lua
| @@ -48,14 +48,10 @@ function Question:set_lines(code) | ||
| 48 | 48 | end |
| 49 | 49 | |
| 50 | 50 | function Question:reset_lines() |
| 51 | - if not self.reset then | |
| 52 | - return | |
| 53 | - end | |
| 54 | - | |
| 55 | 51 | local new_lines = self:snippet(true) or "" |
| 56 | 52 | |
| 57 | 53 | vim.schedule(function() -- |
| 58 | - log.info("Previous code found and reseted\nTo undo, simply press `u`") | |
| 54 | + log.info("Previous code found and reset\nTo undo, simply press `u`") | |
| 59 | 55 | end) |
| 60 | 56 | |
| 61 | 57 | self:set_lines(new_lines) |
| @@ -315,14 +311,12 @@ Question.change_lang = vim.schedule_wrap(function(self, lang) | ||
| 315 | 311 | end) |
| 316 | 312 | |
| 317 | 313 | ---@param problem lc.cache.Question |
| 318 | ----@param reset boolean | |
| 319 | -function Question:init(problem, reset) | |
| 314 | +function Question:init(problem) | |
| 320 | 315 | self.cache = problem |
| 321 | 316 | self.lang = config.lang |
| 322 | - self.reset = reset and true or false | |
| 323 | 317 | end |
| 324 | 318 | |
| 325 | ----@type fun(question: lc.cache.Question, reset?: boolean): lc.ui.Question | |
| 319 | +---@type fun(question: lc.cache.Question): lc.ui.Question | |
| 326 | 320 | local LeetQuestion = Question |
| 327 | 321 | |
| 328 | 322 | return LeetQuestion |
+2-2lua/leetcode/command/init.lua
| @@ -140,7 +140,7 @@ function cmd.qot() | ||
| 140 | 140 | return log.err(err) |
| 141 | 141 | end |
| 142 | 142 | local problemlist = require("leetcode.cache.problemlist") |
| 143 | - Question(problemlist.get_by_title_slug(qot.title_slug), true):mount() | |
| 143 | + Question(problemlist.get_by_title_slug(qot.title_slug)):mount() | |
| 144 | 144 | end) |
| 145 | 145 | end |
| 146 | 146 | |
| @@ -168,7 +168,7 @@ function cmd.random_question(opts) | ||
| 168 | 168 | |
| 169 | 169 | local item = problems.get_by_title_slug(q.title_slug) or {} |
| 170 | 170 | local Question = require("leetcode-ui.question") |
| 171 | - Question(item, true):mount() | |
| 171 | + Question(item):mount() | |
| 172 | 172 | end |
| 173 | 173 | |
| 174 | 174 | function cmd.start_with_cmd() |
+6-7lua/leetcode/config/hooks.lua
| @@ -2,15 +2,14 @@ | ||
| 2 | 2 | local hooks = {} |
| 3 | 3 | |
| 4 | 4 | hooks["question_enter"] = { |
| 5 | - vim.schedule_wrap(function(q) | |
| 5 | + function(q) | |
| 6 | 6 | -- https://github.com/kawre/leetcode.nvim/issues/14 |
| 7 | - if q.lang ~= "rust" then | |
| 8 | - return | |
| 7 | + if q.lang == "rust" then | |
| 8 | + pcall(function() | |
| 9 | + require("rust-tools.standalone").start_standalone_client() | |
| 10 | + end) | |
| 9 | 11 | end |
| 10 | - pcall(function() | |
| 11 | - require("rust-tools.standalone").start_standalone_client() | |
| 12 | - end) | |
| 13 | - end), | |
| 12 | + end, | |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | return hooks |
+2-9lua/leetcode/pickers/question.lua
| @@ -128,7 +128,7 @@ return { | ||
| 128 | 128 | }), |
| 129 | 129 | sorter = conf.generic_sorter(theme), |
| 130 | 130 | attach_mappings = function(prompt_bufnr, map) |
| 131 | - local function mount_question(reset) | |
| 131 | + actions.select_default:replace(function() | |
| 132 | 132 | local selection = action_state.get_selected_entry() |
| 133 | 133 | if not selection then |
| 134 | 134 | return |
| @@ -140,14 +140,7 @@ return { | ||
| 140 | 140 | end |
| 141 | 141 | |
| 142 | 142 | actions.close(prompt_bufnr) |
| 143 | - Question(q, reset):mount() | |
| 144 | - end | |
| 145 | - | |
| 146 | - actions.select_default:replace(function() | |
| 147 | - mount_question() | |
| 148 | - end) | |
| 149 | - map({ "n", "i" }, "<C-Enter>", function() | |
| 150 | - mount_question(true) | |
| 143 | + Question(q):mount() | |
| 151 | 144 | end) |
| 152 | 145 | |
| 153 | 146 | return true |