fix(highlights): lower priority for codeblocks with injections (#4905)

This commit is contained in:
Christian Clason 2023-06-05 14:09:44 +02:00 committed by GitHub
parent 2d6e73ab2f
commit a034c7aa25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 14 deletions

View file

@ -82,9 +82,7 @@ you can mark the language as optional (by putting it between parenthesis).
### Highlights
As languages differ quite a lot, here is a set of captures available to you when building a `highlights.scm` query.
One important thing to note is that many of these capture groups are not supported by `neovim` for now, and will not have any
effect on highlighting. We will work on improving highlighting in the near future though.
As languages differ quite a lot, here is a set of captures available to you when building a `highlights.scm` query. Note that your colorscheme needs to define (or link) these captures as highlight groups.
#### Misc
@ -196,7 +194,6 @@ Mainly for markup languages.
@text.underline ; underlined text
@text.strike ; strikethrough text
@text.title ; text that is part of a title
@text.literal ; literal or verbatim text (e.g., inline code)
@text.quote ; text quotations
@text.uri ; URIs (e.g. hyperlinks)
@text.math ; math environments (e.g. `$ ... $` in LaTeX)
@ -204,6 +201,10 @@ Mainly for markup languages.
@text.environment.name ; text indicating the type of an environment
@text.reference ; text references, footnotes, citations, etc.
@text.literal ; literal or verbatim text (e.g., inline code)
@text.literal.block ; literal or verbatim text as a stand-alone block
; (use priority 90 for blocks with injections)
@text.todo ; todo notes
@text.note ; info notes
@text.warning ; warning notes
@ -238,6 +239,14 @@ Used for XML-like tags.
@nospell ; for defining regions that should NOT be spellchecked
```
#### Priority
Captures can be assigned a priority to control precedence of highlights via the
`#set! "priority" <number>` directive (see `:h treesitter-highlight-priority`).
The default priority for treesitter highlights is `100`; queries should only
set priorities between `90` and `120`, to avoid conflict with other sources of
highlighting (such as diagnostics or LSP semantic tokens).
### Locals
Note: pay specific attention to the captures here as they are a bit different to

View file

@ -112,10 +112,8 @@
(number_literal) @number
(char_literal) @character
[
(preproc_arg)
(preproc_defined)
] @function.macro
((preproc_arg) @function.macro (#set! "priority" 90))
(preproc_defined) @function.macro
(((field_expression
(field_identifier) @property)) @_parent

View file

@ -9,11 +9,9 @@
(atx_heading (atx_h5_marker) @text.title.5.marker (inline) @text.title.5)
(atx_heading (atx_h6_marker) @text.title.6.marker (inline) @text.title.6)
[
(link_title)
(indented_code_block)
(fenced_code_block)
] @text.literal
(link_title) @text.literal
(indented_code_block) @text.literal.block
((fenced_code_block) @text.literal.block (#set! "priority" 90))
(info_string) @label

View file

@ -15,7 +15,7 @@
(codespan
"`" @conceal (#set! conceal "")
text: (_) @text.literal)
(codeblock) @text.literal
((codeblock) @text.literal.block (#set! "priority" 90))
(codeblock
[">" (language)] @conceal (#set! conceal ""))
(block