A Neovim plugin enabling you to solve LeetCode problems.
feat(pickers): using `web-devicons`
4 files changed, +27 -10
+3-2.neoconf.json
| @@ -3,10 +3,11 @@ | ||
| 3 | 3 | "library": { |
| 4 | 4 | "enabled": true, |
| 5 | 5 | "plugins": [ |
| 6 | - "nvim-treesitter/nvim-treesitter", | |
| 6 | + "nvim-treesitter", | |
| 7 | 7 | "telescope.nvim", |
| 8 | 8 | "plenary.nvim", |
| 9 | - "nui.nvim" | |
| 9 | + "nui.nvim", | |
| 10 | + "nvim-web-devicons" | |
| 10 | 11 | ] |
| 11 | 12 | } |
| 12 | 13 | } |
+2-1README.md
| @@ -42,13 +42,14 @@ https://github.com/kawre/leetcode.nvim/assets/69250723/309088c9-4ff7-4dff-ab61-a | ||
| 42 | 42 | |
| 43 | 43 | - [nvim-notify][nvim-notify] _**(optional)**_ |
| 44 | 44 | |
| 45 | -- [Nerd Font][nerd-font] _**(optional)**_ | |
| 45 | +- [Nerd Font][nerd-font] & [nvim-web-devicons] _**(optional)**_ | |
| 46 | 46 | |
| 47 | 47 | [nvim-treesitter]: https://github.com/nvim-treesitter/nvim-treesitter |
| 48 | 48 | [telescope.nvim]: https://github.com/nvim-telescope/telescope.nvim |
| 49 | 49 | [nui.nvim]: https://github.com/MunifTanjim/nui.nvim |
| 50 | 50 | [nvim-notify]: https://github.com/rcarriga/nvim-notify |
| 51 | 51 | [nerd-font]: https://www.nerdfonts.com |
| 52 | +[nvim-web-devicons]: https://github.com/nvim-tree/nvim-web-devicons | |
| 52 | 53 | |
| 53 | 54 | ## 📦 Installation |
| 54 | 55 |
+1-7lua/leetcode/pickers/question-tabs.lua
| @@ -24,14 +24,8 @@ local function display_current(entry) | ||
| 24 | 24 | end |
| 25 | 25 | |
| 26 | 26 | local function display_difficulty(q) |
| 27 | - local hl = { | |
| 28 | - ["Easy"] = "leetcode_easy", | |
| 29 | - ["Medium"] = "leetcode_medium", | |
| 30 | - ["Hard"] = "leetcode_hard", | |
| 31 | - } | |
| 32 | - | |
| 33 | 27 | local lang = utils.get_lang(q.lang) |
| 34 | - return { lang.icon } | |
| 28 | + return { lang.icon, "leetcode_lang_" .. lang.slug } | |
| 35 | 29 | end |
| 36 | 30 | |
| 37 | 31 | ---@param question lc.Cache.Question |
+21-0lua/leetcode/theme/init.lua
| @@ -1,12 +1,33 @@ | ||
| 1 | +local devicons_ok, devicons = pcall(require, "nvim-web-devicons") | |
| 2 | +local config = require("leetcode.config") | |
| 3 | + | |
| 1 | 4 | ---@class lc.Theme |
| 2 | 5 | local theme = {} |
| 3 | 6 | |
| 7 | +function theme.load_icons() | |
| 8 | + vim.tbl_map(function(l) | |
| 9 | + local icon, color = devicons.get_icon_color(l.ft) | |
| 10 | + | |
| 11 | + if icon then l.icon = icon end | |
| 12 | + if color then l.color = color end | |
| 13 | + | |
| 14 | + return l | |
| 15 | + end, config.langs) | |
| 16 | +end | |
| 17 | + | |
| 4 | 18 | function theme.load() |
| 5 | 19 | local default = require("leetcode.theme.default").get() |
| 6 | 20 | for key, t in pairs(default) do |
| 7 | 21 | key = "leetcode_" .. key |
| 8 | 22 | vim.api.nvim_set_hl(0, key, t) |
| 9 | 23 | end |
| 24 | + | |
| 25 | + if devicons_ok then theme.load_icons() end | |
| 26 | + | |
| 27 | + for _, lang in ipairs(config.langs) do | |
| 28 | + local name = "leetcode_lang_" .. lang.slug | |
| 29 | + vim.api.nvim_set_hl(0, name, { fg = lang.color }) | |
| 30 | + end | |
| 10 | 31 | end |
| 11 | 32 | |
| 12 | 33 | return theme |