Skip to content

Commit

Permalink
feat(presets): make better looking and more components
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Oct 13, 2024
1 parent d230f4f commit 02d3d25
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lua/care/presets/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,20 @@ function components.ColoredBlock(entry, character)
}
end

function components.Padding(size)
return { { string.rep(" ", size or 1), "@care.entry" } }
end

function components.KindName(entry, use_kind_color, highlight_group)
local completion_item = entry.completion_item
local entry_kind = type(completion_item.kind) == "string" and completion_item.kind
or require("care.utils.lsp").get_kind_name(completion_item.kind)
local preset_utils = require("care.presets.utils") or require("care.utils.lsp").get_kind_name(completion_item.kind)
print(use_kind_color and preset_utils.kind_highlight(entry, "fg") or highlight_group or "@care.entry")
print(entry_kind)
return {
{ entry_kind, use_kind_color and preset_utils.kind_highlight(entry, "fg") or highlight_group or "@care.entry" },
}
end

return components
7 changes: 6 additions & 1 deletion lua/care/presets/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ local Presets = {}
function Presets.Default(entry, data)
local components = require("care.presets.components")
return {
components.Padding(1),
components.Label(entry, data, true),
components.Padding(1),
components.KindIcon(entry, "fg"),
components.Padding(1),
}
end

function Presets.Atom(entry, data)
local components = require("care.presets.components")
return {
components.Padding(1),
components.KindIcon(entry, "blended"),
{ { " ", "@care.menu" } },
components.Padding(1),
components.Label(entry, data, true),
components.Padding(1),
}
end

Expand Down
11 changes: 11 additions & 0 deletions lua/care/types/preset_components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,16 @@
---@field Label fun(entry: care.entry, data: care.format_data, display_colored_block?: boolean): { [1]: string, [2]: string }[]
--- This component adds a colored block for the item if it is a color. The character used for the block can
--- optionally be configured.
---
--- ![image](https://github.com/user-attachments/assets/e6bf8620-92af-4ffa-8973-635cab7beec4)
---@field ColoredBlock fun(entry: care.entry, character?: string): { [1]: string, [2]: string }[]
--- This function is used to add padding. Use the parameter to determine the width.
---@field Padding fun(size: integer): { [1]: string, [2]: string }[]
--- This component allows to display the kind of the completion item as a string. You can use the second parameter
--- to choose whether the string should be highlighted with the color of the kind or if it should just use a given
--- highlight group which can be given with the 3rd parameter.
---
--- ![image](https://github.com/user-attachments/assets/4ceb2b54-50af-4459-96af-d485bba6ba3a)
---
--- ![image](https://github.com/user-attachments/assets/fb5ecb19-1009-4249-af6f-6a2ccb7873fc)
---@field KindName fun(entry: care.entry, use_kind_color: boolean, highlight_group: string?): { [1]: string, [2]: string }[]
10 changes: 8 additions & 2 deletions lua/care/types/presets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
--- return require("care.presets").<preset_name>(entry, data)
--- end
--- ```
--- You could also just use the shorter form
--- ```lua
--- format_entry = require("care.presets").<preset_name>
--- ```
---@class care.presets
--- The default preset. Just includes the label and a simple icon.
--- ![image](https://github.com/user-attachments/assets/d3d7d338-db32-471f-ae20-89ea7703cb55)
---
--- ![image](https://github.com/user-attachments/assets/962a3bc3-72d8-413b-9b02-90e43e7bced8)
---@field Default fun(entry: care.entry, data: care.format_data): { [1]: string, [2]: string }[][]
--- The atom preset is an atom-like configuration. It displays the kind icon with a blended colored background and
--- the label.
--- ![image](https://github.com/user-attachments/assets/f8715fa7-1a0e-4be9-85ae-14b85cc2b7fd)
---
--- ![image](https://github.com/user-attachments/assets/cb653979-ca57-49c8-ae23-510be1496a5c)
---@field Atom fun(entry: care.entry, data: care.format_data): { [1]: string, [2]: string }[][]

0 comments on commit 02d3d25

Please sign in to comment.