From 593a6345de3b8186a3b5d5501b6e137ca17f1653 Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sat, 27 Nov 2021 19:20:44 +0900 Subject: [PATCH] Implement kind highlights (#584) * Implement kind highlights * Fix link --- README.md | 16 ++++++++++++++++ lua/cmp/entry.lua | 2 +- plugin/cmp.lua | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d82c0d9..1898c8d 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,10 @@ The source customization options. It is defined by each source. The priority of the source. If you don't specify it, the source priority will be determined by the default algorithm (see `sorting.priority_weight`). +#### sources[number].trigger_characters (type: string[]) + +The source specific triggerCharacters for override. + #### sources[number].keyword_pattern (type: string) The source specific keyword_pattern for override. @@ -473,6 +477,18 @@ The fuzzy matched characters highlight. The kind field. +#### `CmpItemKind%KIND_NAME%` + +The specific kind highlights. +You can see the name on [lsp.lua#L108](./lua/cmp/types/lsp.lua#L108). + +For example, You can change the highlight like this if you want to override only the `Method` kind. + +``` +highlight! CmpItemKindMethod guibg=NONE guifg=LightYellow +``` + + #### `CmpItemMenu` The menu field. diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index 686c0de..495e607 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -212,7 +212,7 @@ entry.get_view = function(self, suggest_offset) view.kind.text = item.kind or '' view.kind.bytes = #view.kind.text view.kind.width = vim.str_utfindex(view.kind.text) - view.kind.hl_group = 'CmpItemKind' + view.kind.hl_group = 'CmpItemKind' .. types.lsp.CompletionItemKind[self:get_kind()] view.menu = {} view.menu.text = item.menu or '' view.menu.bytes = #view.menu.text diff --git a/plugin/cmp.lua b/plugin/cmp.lua index e0db0cc..1c67c25 100644 --- a/plugin/cmp.lua +++ b/plugin/cmp.lua @@ -5,6 +5,7 @@ vim.g.loaded_cmp = true local api = require "cmp.utils.api" local misc = require('cmp.utils.misc') +local types = require('cmp.types') local config = require('cmp.config') local highlight = require('cmp.utils.highlight') @@ -78,6 +79,11 @@ misc.set(_G, { 'cmp', 'plugin', 'colorscheme' }, function() guibg = 'NONE', ctermbg = 'NONE', }) + for name in pairs(types.lsp.CompletionItemKind) do + if type(name) == 'string' then + vim.cmd(([[highlight! default link CmpItemKind%sDefault CmpItemKindDefault]]):format(name)) + end + end highlight.inherit('CmpItemMenuDefault', 'Pmenu', { guibg = 'NONE', ctermbg = 'NONE', @@ -104,6 +110,14 @@ end if vim.fn.hlexists('CmpItemKind') ~= 1 then vim.cmd [[highlight! default link CmpItemKind CmpItemKindDefault]] end +for name in pairs(types.lsp.CompletionItemKind) do + if type(name) == 'string' then + local hi = ('CmpItemKind%s'):format(name) + if vim.fn.hlexists(hi) ~= 1 then + vim.cmd(([[highlight! default link %s %sDefault]]):format(hi, hi)) + end + end +end if vim.fn.hlexists('CmpItemMenu') ~= 1 then vim.cmd [[highlight! default link CmpItemMenu CmpItemMenuDefault]]