diff --git a/README.md b/README.md index 2ba71ac3..9fcacbba 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/doc/crates.txt b/doc/crates.txt index d2a19904..9013fd3e 100644 --- a/doc/crates.txt +++ b/doc/crates.txt @@ -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, @@ -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` @@ -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: \ No newline at end of file diff --git a/lua/crates/config.lua b/lua/crates/config.lua index dec87b41..b514ea46 100644 --- a/lua/crates/config.lua +++ b/lua/crates/config.lua @@ -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 = {}, }, } + + + + + + + + + + + + + + + + + @@ -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 = [[ diff --git a/lua/crates/highlight.lua b/lua/crates/highlight.lua index 98a00f96..e1266538 100644 --- a/lua/crates/highlight.lua +++ b/lua/crates/highlight.lua @@ -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() diff --git a/lua/crates/src/common.lua b/lua/crates/src/common.lua index 8dd0c4b5..21c56d72 100644 --- a/lua/crates/src/common.lua +++ b/lua/crates/src/common.lua @@ -1,4 +1,10 @@ -local M = {CompletionList = {}, CompletionItem = {}, } +local M = {CompletionList = {}, CompletionItem = {}, CmpCompletionExtension = {}, } + + + + + + @@ -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 @@ -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 diff --git a/teal/crates/config.tl b/teal/crates/config.tl index 2b52c1cd..00d95f4e 100644 --- a/teal/crates/config.tl +++ b/teal/crates/config.tl @@ -179,6 +179,7 @@ local record M insert_closing_quote: boolean text: SrcTextConfig coq: CoqConfig + cmp: CmpConfig end record SrcTextConfig @@ -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 @@ -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 = [[ diff --git a/teal/crates/highlight.tl b/teal/crates/highlight.tl index 7e96106e..f0c2ca54 100644 --- a/teal/crates/highlight.tl +++ b/teal/crates/highlight.tl @@ -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() diff --git a/teal/crates/src/common.tl b/teal/crates/src/common.tl index 9be91e70..7749d0c8 100644 --- a/teal/crates/src/common.tl +++ b/teal/crates/src/common.tl @@ -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 @@ -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 @@ -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