Skip to content

Commit

Permalink
feat: integrations for icons
Browse files Browse the repository at this point in the history
fixes #68
fixes #67
fixes #136
  • Loading branch information
max397574 committed Nov 11, 2024
1 parent ab5a039 commit e288f9c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
38 changes: 38 additions & 0 deletions docs/configuration_recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions lua/care/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down
2 changes: 1 addition & 1 deletion lua/care/types/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e288f9c

Please sign in to comment.