irongit

A Neovim plugin enabling you to solve LeetCode problems.

feat(pickers): using `web-devicons`

kawreauthored
parent ddb0fb6commit 29e2f0308ccc79a4e85063c1919e8580fb54435bBrowse files

4 files changed, +27 -10

+3-2.neoconf.json
@@ -3,10 +3,11 @@
33 "library": {
44 "enabled": true,
55 "plugins": [
6- "nvim-treesitter/nvim-treesitter",
6+ "nvim-treesitter",
77 "telescope.nvim",
88 "plenary.nvim",
9- "nui.nvim"
9+ "nui.nvim",
10+ "nvim-web-devicons"
1011 ]
1112 }
1213 }
+2-1README.md
@@ -42,13 +42,14 @@ https://github.com/kawre/leetcode.nvim/assets/69250723/309088c9-4ff7-4dff-ab61-a
4242
4343 - [nvim-notify][nvim-notify] _**(optional)**_
4444
45-- [Nerd Font][nerd-font] _**(optional)**_
45+- [Nerd Font][nerd-font] & [nvim-web-devicons] _**(optional)**_
4646
4747 [nvim-treesitter]: https://github.com/nvim-treesitter/nvim-treesitter
4848 [telescope.nvim]: https://github.com/nvim-telescope/telescope.nvim
4949 [nui.nvim]: https://github.com/MunifTanjim/nui.nvim
5050 [nvim-notify]: https://github.com/rcarriga/nvim-notify
5151 [nerd-font]: https://www.nerdfonts.com
52+[nvim-web-devicons]: https://github.com/nvim-tree/nvim-web-devicons
5253
5354 ## 📦 Installation
5455
+1-7lua/leetcode/pickers/question-tabs.lua
@@ -24,14 +24,8 @@ local function display_current(entry)
2424 end
2525
2626 local function display_difficulty(q)
27- local hl = {
28- ["Easy"] = "leetcode_easy",
29- ["Medium"] = "leetcode_medium",
30- ["Hard"] = "leetcode_hard",
31- }
32-
3327 local lang = utils.get_lang(q.lang)
34- return { lang.icon }
28+ return { lang.icon, "leetcode_lang_" .. lang.slug }
3529 end
3630
3731 ---@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+
14 ---@class lc.Theme
25 local theme = {}
36
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+
418 function theme.load()
519 local default = require("leetcode.theme.default").get()
620 for key, t in pairs(default) do
721 key = "leetcode_" .. key
822 vim.api.nvim_set_hl(0, key, t)
923 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
1031 end
1132
1233 return theme