Skip to content

Commit

Permalink
feat: custom nvim-cmp item kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
saecki committed Oct 5, 2023
1 parent 344ff11 commit 86b31c9
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ require('crates').setup {
enabled = false,
name = "Crates",
},
cmp = {
use_custom_kind = true,
kind_text = {
version = "Version",
feature = "Feature",
},
kind_highlight = {
version = "CmpItemKindVersion",
feature = "CmpItemKindFeature",
},
},
},
null_ls = {
enabled = false,
Expand Down
65 changes: 65 additions & 0 deletions doc/crates.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ For more information about individual config options see |crates-config|.
enabled = false,
name = "Crates",
},
cmp = {
use_custom_kind = true,
kind_text = {
version = "Version",
feature = "Feature",
},
kind_highlight = {
version = "CmpItemKindVersion",
feature = "CmpItemKindFeature",
},
},
},
null_ls = {
enabled = false,
Expand Down Expand Up @@ -1294,6 +1305,54 @@ src.coq.name *crates-config-src-coq-name*
The source name displayed by |coq_nvim|.


src.cmp *crates-config-src-cmp*
Type: `section`

Configuration options for the |nvim-cmp| completion source.


src.cmp.use_custom_kind *crates-config-src-cmp-use_custom_kind*
Type: `boolean`, Default: `true`

Use custom a custom kind to display inside the |nvim-cmp| completion menu.


src.cmp.kind_text *crates-config-src-cmp-kind_text*
Type: `section`

The kind text shown in the |nvim-cmp| completion menu.


src.cmp.kind_text.version *crates-config-src-cmp-kind_text-version*
Type: `string`, Default: `"Version"`

The version kind text shown in the |nvim-cmp| completion menu.


src.cmp.kind_text.feature *crates-config-src-cmp-kind_text-feature*
Type: `string`, Default: `"Feature"`

The feature kind text shown in the |nvim-cmp| completion menu.


src.cmp.kind_highlight *crates-config-src-cmp-kind_highlight*
Type: `section`

Highlight groups used for the kind text in the |nvim-cmp| completion menu.


src.cmp.kind_highlight.version *crates-config-src-cmp-kind_highlight-version*
Type: `string`, Default: `"CmpItemKindVersion"`

Highlight group used for the version kind text in the |nvim-cmp| completion menu.


src.cmp.kind_highlight.feature *crates-config-src-cmp-kind_highlight-feature*
Type: `string`, Default: `"CmpItemKindFeature"`

Highlight group used for the feature kind text in the |nvim-cmp| completion menu.


null_ls *crates-config-null_ls*
Type: `section`

Expand Down Expand Up @@ -1414,5 +1473,11 @@ CratesNvimPopupDependencyVersion *crates-hl-CratesNvimPopupDependencyVersion*
CratesNvimPopupLoading *crates-hl-CratesNvimPopupLoading*
Default: links to |Special|

CmpItemKindVersion *crates-hl-CmpItemKindVersion*
Default: links to |Special|

CmpItemKindFeature *crates-hl-CmpItemKindFeature*
Default: links to |Special|


vim:tw=78:ts=8:ft=help:norl:
82 changes: 81 additions & 1 deletion lua/crates/config.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
local M = {Config = {TextConfig = {}, HighlightConfig = {}, DiagnosticConfig = {}, PopupConfig = {}, PopupTextConfig = {}, PopupHighlightConfig = {}, PopupKeyConfig = {}, SrcConfig = {}, SrcTextConfig = {}, CoqConfig = {}, NullLsConfig = {}, }, SchemaElement = {Deprecated = {}, }, }
local M = {Config = {TextConfig = {}, HighlightConfig = {}, DiagnosticConfig = {}, PopupConfig = {}, PopupTextConfig = {}, PopupHighlightConfig = {}, PopupKeyConfig = {}, SrcConfig = {}, SrcTextConfig = {}, CoqConfig = {}, CmpConfig = {}, CmpKindTextConfig = {}, CmpKindHighlightConfig = {}, NullLsConfig = {}, }, SchemaElement = {Deprecated = {}, }, }




















Expand Down Expand Up @@ -1350,6 +1367,69 @@ entry(schema_src_coq, "name", {
]],
})

entry(schema_src, "cmp", {
type = "section",
description = [[
Configuration options for the |nvim-cmp| completion source.
]],
fields = {},
})
local schema_src_cmp = schema_src.cmp.fields
entry(schema_src_cmp, "use_custom_kind", {
type = "boolean",
default = true,
description = [[
Use custom a custom kind to display inside the |nvim-cmp| completion menu.
]],
})

entry(schema_src_cmp, "kind_text", {
type = "section",
description = [[
The kind text shown in the |nvim-cmp| completion menu.
]],
fields = {},
})
local schema_src_cmp_kind_text = schema_src_cmp.kind_text.fields
entry(schema_src_cmp_kind_text, "version", {
type = "string",
default = "Version",
description = [[
The version kind text shown in the |nvim-cmp| completion menu.
]],
})
entry(schema_src_cmp_kind_text, "feature", {
type = "string",
default = "Feature",
description = [[
The feature kind text shown in the |nvim-cmp| completion menu.
]],
})

entry(schema_src_cmp, "kind_highlight", {
type = "section",
description = [[
Highlight groups used for the kind text in the |nvim-cmp| completion menu.
]],
fields = {},
})
local schema_src_cmp_kind_hi = schema_src_cmp.kind_highlight.fields
entry(schema_src_cmp_kind_hi, "version", {
type = "string",
default = "CmpItemKindVersion",
description = [[
Highlight group used for the version kind text in the |nvim-cmp| completion menu.
]],
})
entry(schema_src_cmp_kind_hi, "feature", {
type = "string",
default = "CmpItemKindFeature",
description = [[
Highlight group used for the feature kind text in the |nvim-cmp| completion menu.
]],
})


entry(M.schema, "null_ls", {
type = "section",
description = [[
Expand Down
3 changes: 3 additions & 0 deletions lua/crates/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ M.highlights = {
{ "CratesNvimPopupOptional", { default = true, link = "Comment" } },
{ "CratesNvimPopupDependencyVersion", { default = true, link = "String" } },
{ "CratesNvimPopupLoading", { default = true, link = "Special" } },

{ "CmpItemKindVersion", { default = true, link = "Special" } },
{ "CmpItemKindFeature", { default = true, link = "Special" } },
}

function M.define()
Expand Down
20 changes: 19 additions & 1 deletion lua/crates/src/common.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
local M = {CompletionList = {}, CompletionItem = {}, }
local M = {CompletionList = {}, CompletionItem = {}, CmpCompletionExtension = {}, }









Expand Down Expand Up @@ -50,6 +56,12 @@ local function complete_versions(crate, versions)
elseif v.parsed.pre then
r.documentation = state.cfg.src.text.prerelease
end
if state.cfg.src.cmp.use_custom_kind then
r.cmp = {
kind_text = state.cfg.src.cmp.kind_text.version,
kind_hl_group = state.cfg.src.cmp.kind_highlight.version,
}
end

table.insert(items, r)
end
Expand Down Expand Up @@ -86,6 +98,12 @@ local function complete_features(crate, cf, versions)
r.insertText = f.name .. cf.quote.s
end
end
if state.cfg.src.cmp.use_custom_kind then
r.cmp = {
kind_text = state.cfg.src.cmp.kind_text.feature,
kind_hl_group = state.cfg.src.cmp.kind_highlight.feature,
}
end

table.insert(items, r)
end
Expand Down
80 changes: 80 additions & 0 deletions teal/crates/config.tl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ local record M
insert_closing_quote: boolean
text: SrcTextConfig
coq: CoqConfig
cmp: CmpConfig
end

record SrcTextConfig
Expand All @@ -191,6 +192,22 @@ local record M
name: string
end

record CmpConfig
use_custom_kind: boolean
kind_text: CmpKindTextConfig
kind_highlight: CmpKindHighlightConfig
end

record CmpKindTextConfig
version: string
feature: string
end

record CmpKindHighlightConfig
version: string
feature: string
end

record NullLsConfig
enabled: boolean
name: string
Expand Down Expand Up @@ -1350,6 +1367,69 @@ entry(schema_src_coq, "name", {
]],
})

entry(schema_src, "cmp", {
type = "section",
description = [[
Configuration options for the |nvim-cmp| completion source.
]],
fields = {},
})
local schema_src_cmp = schema_src.cmp.fields
entry(schema_src_cmp, "use_custom_kind", {
type = "boolean",
default = true,
description = [[
Use custom a custom kind to display inside the |nvim-cmp| completion menu.
]],
})

entry(schema_src_cmp, "kind_text", {
type = "section",
description = [[
The kind text shown in the |nvim-cmp| completion menu.
]],
fields = {},
})
local schema_src_cmp_kind_text = schema_src_cmp.kind_text.fields
entry(schema_src_cmp_kind_text, "version", {
type = "string",
default = "Version",
description = [[
The version kind text shown in the |nvim-cmp| completion menu.
]],
})
entry(schema_src_cmp_kind_text, "feature", {
type = "string",
default = "Feature",
description = [[
The feature kind text shown in the |nvim-cmp| completion menu.
]],
})

entry(schema_src_cmp, "kind_highlight", {
type = "section",
description = [[
Highlight groups used for the kind text in the |nvim-cmp| completion menu.
]],
fields = {},
})
local schema_src_cmp_kind_hi = schema_src_cmp.kind_highlight.fields
entry(schema_src_cmp_kind_hi, "version", {
type = "string",
default = "CmpItemKindVersion",
description = [[
Highlight group used for the version kind text in the |nvim-cmp| completion menu.
]],
})
entry(schema_src_cmp_kind_hi, "feature", {
type = "string",
default = "CmpItemKindFeature",
description = [[
Highlight group used for the feature kind text in the |nvim-cmp| completion menu.
]],
})


entry(M.schema, "null_ls", {
type = "section",
description = [[
Expand Down
3 changes: 3 additions & 0 deletions teal/crates/highlight.tl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ M.highlights = {
{ "CratesNvimPopupOptional", { default = true, link = "Comment" } },
{ "CratesNvimPopupDependencyVersion", { default = true, link = "String" } },
{ "CratesNvimPopupLoading", { default = true, link = "Special" } },

{ "CmpItemKindVersion", { default = true, link = "Special" } },
{ "CmpItemKindFeature", { default = true, link = "Special" } },
}

function M.define()
Expand Down
18 changes: 18 additions & 0 deletions teal/crates/src/common.tl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ local record M
deprecated: boolean|nil
sortText: string|nil
insertText: string|nil
cmp: CmpCompletionExtension|nil
end

record CmpCompletionExtension
kind_text: string
kind_hl_group: string
end
end

Expand Down Expand Up @@ -50,6 +56,12 @@ local function complete_versions(crate: toml.Crate, versions: {Version}): Comple
elseif v.parsed.pre then
r.documentation = state.cfg.src.text.prerelease
end
if state.cfg.src.cmp.use_custom_kind then
r.cmp = {
kind_text = state.cfg.src.cmp.kind_text.version,
kind_hl_group = state.cfg.src.cmp.kind_highlight.version,
}
end

table.insert(items, r)
end
Expand Down Expand Up @@ -86,6 +98,12 @@ local function complete_features(crate: toml.Crate, cf: toml.Feature, versions:
r.insertText = f.name .. cf.quote.s
end
end
if state.cfg.src.cmp.use_custom_kind then
r.cmp = {
kind_text = state.cfg.src.cmp.kind_text.feature,
kind_hl_group = state.cfg.src.cmp.kind_highlight.feature,
}
end

table.insert(items, r)
end
Expand Down

0 comments on commit 86b31c9

Please sign in to comment.