mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
docs: apply current colorscheme to default highlight groups
Problem: Not all default highlight groups show their actual colors. Solution: Refactor `vimhelp.lua` and apply it to all relevant lists (UI groups, syntax groups, treesitter groups, LSP groups, diagnostic groups).
This commit is contained in:
@@ -480,23 +480,23 @@ Use |LspTokenUpdate| and |vim.lsp.semantic_tokens.highlight_token()| for more
|
|||||||
complex highlighting.
|
complex highlighting.
|
||||||
|
|
||||||
The following groups are linked by default to standard |group-name|s:
|
The following groups are linked by default to standard |group-name|s:
|
||||||
>
|
|
||||||
@lsp.type.class Structure
|
@lsp.type.class Structure
|
||||||
@lsp.type.decorator Function
|
@lsp.type.decorator Function
|
||||||
@lsp.type.enum Structure
|
@lsp.type.enum Structure
|
||||||
@lsp.type.enumMember Constant
|
@lsp.type.enumMember Constant
|
||||||
@lsp.type.function Function
|
@lsp.type.function Function
|
||||||
@lsp.type.interface Structure
|
@lsp.type.interface Structure
|
||||||
@lsp.type.macro Macro
|
@lsp.type.macro Macro
|
||||||
@lsp.type.method Function
|
@lsp.type.method Function
|
||||||
@lsp.type.namespace Structure
|
@lsp.type.namespace Structure
|
||||||
@lsp.type.parameter Identifier
|
@lsp.type.parameter Identifier
|
||||||
@lsp.type.property Identifier
|
@lsp.type.property Identifier
|
||||||
@lsp.type.struct Structure
|
@lsp.type.struct Structure
|
||||||
@lsp.type.type Type
|
@lsp.type.type Type
|
||||||
@lsp.type.typeParameter TypeDef
|
@lsp.type.typeParameter TypeDef
|
||||||
@lsp.type.variable Identifier
|
@lsp.type.variable Identifier
|
||||||
<
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
EVENTS *lsp-events*
|
EVENTS *lsp-events*
|
||||||
|
|
||||||
|
@@ -196,51 +196,51 @@ be preferred names for highlight groups that are common for many languages.
|
|||||||
These are the suggested group names (if syntax highlighting works properly
|
These are the suggested group names (if syntax highlighting works properly
|
||||||
you can see the actual color, except for "Ignore"):
|
you can see the actual color, except for "Ignore"):
|
||||||
|
|
||||||
Comment any comment
|
Comment any comment
|
||||||
|
|
||||||
Constant any constant
|
Constant any constant
|
||||||
String a string constant: "this is a string"
|
String a string constant: "this is a string"
|
||||||
Character a character constant: 'c', '\n'
|
Character a character constant: 'c', '\n'
|
||||||
Number a number constant: 234, 0xff
|
Number a number constant: 234, 0xff
|
||||||
Boolean a boolean constant: TRUE, false
|
Boolean a boolean constant: TRUE, false
|
||||||
Float a floating point constant: 2.3e10
|
Float a floating point constant: 2.3e10
|
||||||
|
|
||||||
Identifier any variable name
|
Identifier any variable name
|
||||||
Function function name (also: methods for classes)
|
Function function name (also: methods for classes)
|
||||||
|
|
||||||
Statement any statement
|
Statement any statement
|
||||||
Conditional if, then, else, endif, switch, etc.
|
Conditional if, then, else, endif, switch, etc.
|
||||||
Repeat for, do, while, etc.
|
Repeat for, do, while, etc.
|
||||||
Label case, default, etc.
|
Label case, default, etc.
|
||||||
Operator "sizeof", "+", "*", etc.
|
Operator "sizeof", "+", "*", etc.
|
||||||
Keyword any other keyword
|
Keyword any other keyword
|
||||||
Exception try, catch, throw
|
Exception try, catch, throw
|
||||||
|
|
||||||
PreProc generic Preprocessor
|
PreProc generic Preprocessor
|
||||||
Include preprocessor #include
|
Include preprocessor #include
|
||||||
Define preprocessor #define
|
Define preprocessor #define
|
||||||
Macro same as Define
|
Macro same as Define
|
||||||
PreCondit preprocessor #if, #else, #endif, etc.
|
PreCondit preprocessor #if, #else, #endif, etc.
|
||||||
|
|
||||||
Type int, long, char, etc.
|
Type int, long, char, etc.
|
||||||
StorageClass static, register, volatile, etc.
|
StorageClass static, register, volatile, etc.
|
||||||
Structure struct, union, enum, etc.
|
Structure struct, union, enum, etc.
|
||||||
Typedef A typedef
|
Typedef a typedef
|
||||||
|
|
||||||
Special any special symbol
|
Special any special symbol
|
||||||
SpecialChar special character in a constant
|
SpecialChar special character in a constant
|
||||||
Tag you can use CTRL-] on this
|
Tag you can use CTRL-] on this
|
||||||
Delimiter character that needs attention
|
Delimiter character that needs attention
|
||||||
SpecialComment special things inside a comment
|
SpecialComment special things inside a comment
|
||||||
Debug debugging statements
|
Debug debugging statements
|
||||||
|
|
||||||
Underlined text that stands out, HTML links
|
Underlined text that stands out, HTML links
|
||||||
|
|
||||||
Ignore left blank, hidden |hl-Ignore|
|
Ignore left blank, hidden |hl-Ignore|
|
||||||
|
|
||||||
Error any erroneous construct
|
Error any erroneous construct
|
||||||
|
|
||||||
Todo anything that needs extra attention; mostly the
|
Todo anything that needs extra attention; mostly the
|
||||||
keywords TODO FIXME and XXX
|
keywords TODO FIXME and XXX
|
||||||
|
|
||||||
The names marked with * are the preferred groups; the others are minor groups.
|
The names marked with * are the preferred groups; the others are minor groups.
|
||||||
|
@@ -393,58 +393,58 @@ instance, to highlight comments differently per language: >vim
|
|||||||
hi link @comment.doc.java String
|
hi link @comment.doc.java String
|
||||||
<
|
<
|
||||||
The following captures are linked by default to standard |group-name|s:
|
The following captures are linked by default to standard |group-name|s:
|
||||||
>
|
|
||||||
@text.literal Comment
|
|
||||||
@text.reference Identifier
|
|
||||||
@text.title Title
|
|
||||||
@text.uri Underlined
|
|
||||||
@text.underline Underlined
|
|
||||||
@text.todo Todo
|
|
||||||
|
|
||||||
@comment Comment
|
@text.literal Comment
|
||||||
@punctuation Delimiter
|
@text.reference Identifier
|
||||||
|
@text.title Title
|
||||||
|
@text.uri Underlined
|
||||||
|
@text.underline Underlined
|
||||||
|
@text.todo Todo
|
||||||
|
|
||||||
@constant Constant
|
@comment Comment
|
||||||
@constant.builtin Special
|
@punctuation Delimiter
|
||||||
@constant.macro Define
|
|
||||||
@define Define
|
|
||||||
@macro Macro
|
|
||||||
@string String
|
|
||||||
@string.escape SpecialChar
|
|
||||||
@string.special SpecialChar
|
|
||||||
@character Character
|
|
||||||
@character.special SpecialChar
|
|
||||||
@number Number
|
|
||||||
@boolean Boolean
|
|
||||||
@float Float
|
|
||||||
|
|
||||||
@function Function
|
@constant Constant
|
||||||
@function.builtin Special
|
@constant.builtin Special
|
||||||
@function.macro Macro
|
@constant.macro Define
|
||||||
@parameter Identifier
|
@define Define
|
||||||
@method Function
|
@macro Macro
|
||||||
@field Identifier
|
@string String
|
||||||
@property Identifier
|
@string.escape SpecialChar
|
||||||
@constructor Special
|
@string.special SpecialChar
|
||||||
|
@character Character
|
||||||
|
@character.special SpecialChar
|
||||||
|
@number Number
|
||||||
|
@boolean Boolean
|
||||||
|
@float Float
|
||||||
|
|
||||||
@conditional Conditional
|
@function Function
|
||||||
@repeat Repeat
|
@function.builtin Special
|
||||||
@label Label
|
@function.macro Macro
|
||||||
@operator Operator
|
@parameter Identifier
|
||||||
@keyword Keyword
|
@method Function
|
||||||
@exception Exception
|
@field Identifier
|
||||||
|
@property Identifier
|
||||||
|
@constructor Special
|
||||||
|
|
||||||
|
@conditional Conditional
|
||||||
|
@repeat Repeat
|
||||||
|
@label Label
|
||||||
|
@operator Operator
|
||||||
|
@keyword Keyword
|
||||||
|
@exception Exception
|
||||||
|
|
||||||
|
@variable Identifier
|
||||||
|
@type Type
|
||||||
|
@type.definition Typedef
|
||||||
|
@storageclass StorageClass
|
||||||
|
@structure Structure
|
||||||
|
@namespace Identifier
|
||||||
|
@include Include
|
||||||
|
@preproc PreProc
|
||||||
|
@debug Debug
|
||||||
|
@tag Tag
|
||||||
|
|
||||||
@variable Identifier
|
|
||||||
@type Type
|
|
||||||
@type.definition Typedef
|
|
||||||
@storageclass StorageClass
|
|
||||||
@structure Structure
|
|
||||||
@namespace Identifier
|
|
||||||
@include Include
|
|
||||||
@preproc PreProc
|
|
||||||
@debug Debug
|
|
||||||
@tag Tag
|
|
||||||
<
|
|
||||||
*treesitter-highlight-spell*
|
*treesitter-highlight-spell*
|
||||||
The special `@spell` capture can be used to indicate that a node should be
|
The special `@spell` capture can be used to indicate that a node should be
|
||||||
spell checked by Nvim's builtin |spell| checker. For example, the following
|
spell checked by Nvim's builtin |spell| checker. For example, the following
|
||||||
|
@@ -2,6 +2,27 @@
|
|||||||
vim.treesitter.start()
|
vim.treesitter.start()
|
||||||
|
|
||||||
-- add custom highlights for list in `:h highlight-groups`
|
-- add custom highlights for list in `:h highlight-groups`
|
||||||
if vim.endswith(vim.fs.normalize(vim.api.nvim_buf_get_name(0)), '/doc/syntax.txt') then
|
local bufname = vim.fs.normalize(vim.api.nvim_buf_get_name(0))
|
||||||
require('vim.vimhelp').highlight_groups()
|
if vim.endswith(bufname, '/doc/syntax.txt') then
|
||||||
|
require('vim.vimhelp').highlight_groups({
|
||||||
|
{ start = [[\*group-name\*]], stop = '^======', match = '^(%w+)\t' },
|
||||||
|
{ start = [[\*highlight-groups\*]], stop = '^======', match = '^(%w+)\t' },
|
||||||
|
})
|
||||||
|
elseif vim.endswith(bufname, '/doc/treesitter.txt') then
|
||||||
|
require('vim.vimhelp').highlight_groups({
|
||||||
|
{
|
||||||
|
start = [[\*treesitter-highlight-groups\*]],
|
||||||
|
stop = [[\*treesitter-highlight-spell\*]],
|
||||||
|
match = '^@[%w%p]+',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
elseif vim.endswith(bufname, '/doc/diagnostic.txt') then
|
||||||
|
require('vim.vimhelp').highlight_groups({
|
||||||
|
{ start = [[\*diagnostic-highlights\*]], stop = '^======', match = '^(%w+)' },
|
||||||
|
})
|
||||||
|
elseif vim.endswith(bufname, '/doc/lsp.txt') then
|
||||||
|
require('vim.vimhelp').highlight_groups({
|
||||||
|
{ start = [[\*lsp-highlight\*]], stop = '^------', match = '^(%w+)' },
|
||||||
|
{ start = [[\*lsp-semantic-highlight\*]], stop = '^======', match = '^@[%w%p]+' },
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
@@ -2,28 +2,30 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Called when editing the doc/syntax.txt file
|
--- Apply current colorscheme to lists of default highlight groups
|
||||||
function M.highlight_groups()
|
---
|
||||||
local save_cursor = vim.fn.getcurpos()
|
--- Note: {patterns} is assumed to be sorted by occurrence in the file.
|
||||||
|
--- @param patterns {start:string,stop:string,match:string}[]
|
||||||
local start_lnum = vim.fn.search([[\*highlight-groups\*]], 'c')
|
function M.highlight_groups(patterns)
|
||||||
if start_lnum == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local end_lnum = vim.fn.search('^======')
|
|
||||||
if end_lnum == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local ns = vim.api.nvim_create_namespace('vimhelp')
|
local ns = vim.api.nvim_create_namespace('vimhelp')
|
||||||
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||||
|
|
||||||
|
local save_cursor = vim.fn.getcurpos()
|
||||||
|
|
||||||
|
for _, pat in pairs(patterns) do
|
||||||
|
local start_lnum = vim.fn.search(pat.start, 'c')
|
||||||
|
local end_lnum = vim.fn.search(pat.stop)
|
||||||
|
if start_lnum == 0 or end_lnum == 0 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
for lnum = start_lnum, end_lnum do
|
for lnum = start_lnum, end_lnum do
|
||||||
local word = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1]:match('^(%w+)\t')
|
local word = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1]:match(pat.match)
|
||||||
if vim.fn.hlexists(word) ~= 0 then
|
if vim.fn.hlexists(word) ~= 0 then
|
||||||
vim.api.nvim_buf_set_extmark(0, ns, lnum - 1, 0, { end_col = #word, hl_group = word })
|
vim.api.nvim_buf_set_extmark(0, ns, lnum - 1, 0, { end_col = #word, hl_group = word })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
vim.fn.setpos('.', save_cursor)
|
vim.fn.setpos('.', save_cursor)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user