A Neovim plugin enabling you to solve LeetCode problems.
refactor(hooks)!: rename hooks
6 files changed, +17 -15
+4-4README.md
| @@ -133,10 +133,10 @@ To see full configuration types see [template.lua](./lua/leetcode/config/templat | ||
| 133 | 133 | |
| 134 | 134 | hooks = { |
| 135 | 135 | ---@type fun()[] |
| 136 | - LeetEnter = {}, | |
| 136 | + ["enter"] = {}, | |
| 137 | 137 | |
| 138 | 138 | ---@type fun(question: lc.ui.Question)[] |
| 139 | - LeetQuestionNew = {}, | |
| 139 | + ["question_enter"] = {}, | |
| 140 | 140 | }, |
| 141 | 141 | |
| 142 | 142 | keys = { |
| @@ -258,10 +258,10 @@ List of functions that get executed on specified event | ||
| 258 | 258 | ```lua |
| 259 | 259 | hooks = { |
| 260 | 260 | ---@type fun()[] |
| 261 | - LeetEnter = {}, | |
| 261 | + ["enter"] = {}, | |
| 262 | 262 | |
| 263 | 263 | ---@type fun(question: lc.ui.Question)[] |
| 264 | - LeetQuestionNew = {}, | |
| 264 | + ["question_enter"] = {}, | |
| 265 | 265 | }, |
| 266 | 266 | ``` |
| 267 | 267 |
+4-4README.zh.md
| @@ -135,10 +135,10 @@ https://github.com/kawre/leetcode.nvim/assets/69250723/aee6584c-e099-4409-b114-1 | ||
| 135 | 135 | |
| 136 | 136 | hooks = { |
| 137 | 137 | ---@type fun()[] |
| 138 | - LeetEnter = {}, | |
| 138 | + ["enter"] = {}, | |
| 139 | 139 | |
| 140 | 140 | ---@type fun(question: lc.ui.Question)[] |
| 141 | - LeetQuestionNew = {}, | |
| 141 | + ["question_enter"] = {}, | |
| 142 | 142 | }, |
| 143 | 143 | |
| 144 | 144 | keys = { |
| @@ -260,10 +260,10 @@ injector = { ---@type table<lc.lang, lc.inject> | ||
| 260 | 260 | ```lua |
| 261 | 261 | hooks = { |
| 262 | 262 | ---@type fun()[] |
| 263 | - LeetEnter = {}, | |
| 263 | + ["enter"] = {}, | |
| 264 | 264 | |
| 265 | 265 | ---@type fun(question: lc.ui.Question)[] |
| 266 | - LeetQuestionNew = {}, | |
| 266 | + ["question_enter"] = {}, | |
| 267 | 267 | }, |
| 268 | 268 | ``` |
| 269 | 269 |
+2-2lua/leetcode-ui/question.lua
| @@ -133,7 +133,7 @@ function Question:handle_mount() | ||
| 133 | 133 | self.console = Console(self) |
| 134 | 134 | self.info = Info(self) |
| 135 | 135 | |
| 136 | - utils.exec_hook("LeetQuestionNew", self) | |
| 136 | + utils.exec_hook("question_enter", self) | |
| 137 | 137 | |
| 138 | 138 | return self |
| 139 | 139 | end |
| @@ -209,7 +209,7 @@ Question.change_lang = vim.schedule_wrap(function(self, lang) | ||
| 209 | 209 | |
| 210 | 210 | self.bufnr = new_bufnr |
| 211 | 211 | if bufloaded == 0 then -- |
| 212 | - utils.exec_hook("LeetQuestionNew", self) | |
| 212 | + utils.exec_hook("question_enter", self) | |
| 213 | 213 | end |
| 214 | 214 | else |
| 215 | 215 | log.error("Changing language failed") |
+1-1lua/leetcode.lua
| @@ -58,7 +58,7 @@ function leetcode.start(on_vimenter) | ||
| 58 | 58 | Menu():mount() |
| 59 | 59 | |
| 60 | 60 | local utils = require("leetcode.utils") |
| 61 | - utils.exec_hook("LeetEnter") | |
| 61 | + utils.exec_hook("enter") | |
| 62 | 62 | |
| 63 | 63 | return true |
| 64 | 64 | end |
+4-4lua/leetcode/config/template.lua
| @@ -21,8 +21,8 @@ | ||
| 21 | 21 | ---| "bash" |
| 22 | 22 | |
| 23 | 23 | ---@alias lc.hook |
| 24 | ----| "LeetEnter" | |
| 25 | ----| "LeetQuestionNew" | |
| 24 | +---| "enter" | |
| 25 | +---| "question_enter" | |
| 26 | 26 | |
| 27 | 27 | ---@alias lc.size |
| 28 | 28 | ---| string |
| @@ -99,10 +99,10 @@ local M = { | ||
| 99 | 99 | |
| 100 | 100 | hooks = { |
| 101 | 101 | ---@type fun()[] |
| 102 | - LeetEnter = {}, | |
| 102 | + ["enter"] = {}, | |
| 103 | 103 | |
| 104 | 104 | ---@type fun(question: lc.ui.Question)[] |
| 105 | - LeetQuestionNew = {}, | |
| 105 | + ["question_open"] = {}, | |
| 106 | 106 | }, |
| 107 | 107 | |
| 108 | 108 | keys = { |
+2-0lua/leetcode/utils.lua
| @@ -76,6 +76,8 @@ function utils.exec_hook(event, ...) | ||
| 76 | 76 | local fns = config.user.hooks[event] |
| 77 | 77 | if not fns then log.error("unknown hook event: " .. event) end |
| 78 | 78 | |
| 79 | + if type(fns) == "function" then fns = { fns } end | |
| 80 | + | |
| 79 | 81 | for i, fn in ipairs(fns) do |
| 80 | 82 | local ok, msg = pcall(vim.schedule_wrap(fn), ...) |
| 81 | 83 | if not ok then log.error(("bad hook #%d in `%s` event: %s"):format(i, event, msg)) end |