From e288f9c3c2e39be8fb4f481064a44e00c95b2b1c Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 11 Nov 2024 18:54:56 +0100 Subject: [PATCH] feat: integrations for icons fixes https://github.com/max397574/care.nvim/issues/68 fixes https://github.com/max397574/care.nvim/issues/67 fixes https://github.com/max397574/care.nvim/issues/136 --- docs/configuration_recipes.md | 38 +++++++++++++++++++++++++++++++++++ lua/care/config.lua | 29 ++++++++++++++++++++++++++ lua/care/types/config.lua | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/docs/configuration_recipes.md b/docs/configuration_recipes.md index 636b316..4811b86 100644 --- a/docs/configuration_recipes.md +++ b/docs/configuration_recipes.md @@ -81,6 +81,44 @@ end vim.fn.setreg("+", table.concat(documentation, "\n")) ``` +## Integrations for icons + +There are various integrations with different plugins for icons in care.nvim + +### Mini.icons + +Install mini.icons as described in +[the readme](https://github.com/echasnovski/mini.icons/tree/main). (Don't forget +to call `require"mini.icons".setup()`!). + +Then use the following configuration for care. + +```lua +require("care").setup({ + ui = { + type_icons = "mini.icons" + } +}) +``` + +Mini.icons also allows you to use ascii icons by using `{ style = "ascii" }` in +the setup. + +### Lspkind.nvim + +Install lspkind.nvim as described in +[the readme](https://github.com/onsails/lspkind.nvim/tree/master). + +Then use the following configuration for care. + +```lua +require("care").setup({ + ui = { + type_icons = "lspkind" + } +}) +``` + ## Manual completion like builtin neovim You can use filters to only complete certain sources. This can be used to create diff --git a/lua/care/config.lua b/lua/care/config.lua index 27f7ccb..9493db6 100644 --- a/lua/care/config.lua +++ b/lua/care/config.lua @@ -86,6 +86,35 @@ function config.setup(opts) else config.options = vim.tbl_deep_extend("force", config.options, opts or {}) end + + if type(config.options.ui.type_icons) == "string" then + if config.options.ui.type_icons == "mini.icons" then + ---@diagnostic disable-next-line: undefined-field + if not _G.MiniIcons then + vim.notify("[care.nvim] Using an unavailable source ui.type_icons (mini.icons)", vim.log.levels.WARN) + config.options.ui.type_icons = config.defaults.ui.type_icons + return + end + local icons = {} + ---@diagnostic disable-next-line: param-type-mismatch + for name, _ in pairs(config.defaults.ui.type_icons) do + icons[name] = _G.MiniIcons.get("lsp", string.lower(name)) + end + config.options.ui.type_icons = icons + elseif config.options.ui.type_icons == "lspkind" then + local ok, lsp_kind = pcall(require, "lspkind") + if not ok then + vim.notify("[care.nvim] Using an unavailable source ui.type_icons (lspkind)", vim.log.levels.WARN) + config.options.ui.type_icons = config.defaults.ui.type_icons + return + else + config.options.ui.type_icons = lsp_kind.symbol_map + end + else + vim.notify("[care.nvim] Using an invalid string value for ui.type_icons", vim.log.levels.WARN) + config.options.ui.type_icons = config.defaults.ui.type_icons + end + end end config.setup({}) diff --git a/lua/care/types/config.lua b/lua/care/types/config.lua index 7de605d..11d29c9 100644 --- a/lua/care/types/config.lua +++ b/lua/care/types/config.lua @@ -85,7 +85,7 @@ --- window. It also has a field to define the character used for the scrollbar. ---@field docs_view? care.config.ui.docs --- This is a table which defines the different icons. ----@field type_icons? care.config.ui.type_icons +---@field type_icons? care.config.ui.type_icons|string --- Configuration of ghost text. ---@field ghost_text? care.config.ui.ghost_text