Implement kind highlights (#584)

* Implement kind highlights

* Fix link
This commit is contained in:
hrsh7th
2021-11-27 19:20:44 +09:00
committed by GitHub
parent 7b744e0589
commit 593a6345de
3 changed files with 31 additions and 1 deletions

View File

@@ -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 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`). 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) #### sources[number].keyword_pattern (type: string)
The source specific keyword_pattern for override. The source specific keyword_pattern for override.
@@ -473,6 +477,18 @@ The fuzzy matched characters highlight.
The kind field. 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` #### `CmpItemMenu`
The menu field. The menu field.

View File

@@ -212,7 +212,7 @@ entry.get_view = function(self, suggest_offset)
view.kind.text = item.kind or '' view.kind.text = item.kind or ''
view.kind.bytes = #view.kind.text view.kind.bytes = #view.kind.text
view.kind.width = vim.str_utfindex(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 = {}
view.menu.text = item.menu or '' view.menu.text = item.menu or ''
view.menu.bytes = #view.menu.text view.menu.bytes = #view.menu.text

View File

@@ -5,6 +5,7 @@ vim.g.loaded_cmp = true
local api = require "cmp.utils.api" local api = require "cmp.utils.api"
local misc = require('cmp.utils.misc') local misc = require('cmp.utils.misc')
local types = require('cmp.types')
local config = require('cmp.config') local config = require('cmp.config')
local highlight = require('cmp.utils.highlight') local highlight = require('cmp.utils.highlight')
@@ -78,6 +79,11 @@ misc.set(_G, { 'cmp', 'plugin', 'colorscheme' }, function()
guibg = 'NONE', guibg = 'NONE',
ctermbg = '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', { highlight.inherit('CmpItemMenuDefault', 'Pmenu', {
guibg = 'NONE', guibg = 'NONE',
ctermbg = 'NONE', ctermbg = 'NONE',
@@ -104,6 +110,14 @@ end
if vim.fn.hlexists('CmpItemKind') ~= 1 then if vim.fn.hlexists('CmpItemKind') ~= 1 then
vim.cmd [[highlight! default link CmpItemKind CmpItemKindDefault]] vim.cmd [[highlight! default link CmpItemKind CmpItemKindDefault]]
end 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 if vim.fn.hlexists('CmpItemMenu') ~= 1 then
vim.cmd [[highlight! default link CmpItemMenu CmpItemMenuDefault]] vim.cmd [[highlight! default link CmpItemMenu CmpItemMenuDefault]]