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 ### Highlights
As languages differ quite a lot, here is a set of captures available to you when building a `highlights.scm` query. 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.
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.
#### Misc #### Misc
@ -196,7 +194,6 @@ Mainly for markup languages.
@text.underline ; underlined text @text.underline ; underlined text
@text.strike ; strikethrough text @text.strike ; strikethrough text
@text.title ; text that is part of a title @text.title ; text that is part of a title
@text.literal ; literal or verbatim text (e.g., inline code)
@text.quote ; text quotations @text.quote ; text quotations
@text.uri ; URIs (e.g. hyperlinks) @text.uri ; URIs (e.g. hyperlinks)
@text.math ; math environments (e.g. `$ ... $` in LaTeX) @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.environment.name ; text indicating the type of an environment
@text.reference ; text references, footnotes, citations, etc. @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.todo ; todo notes
@text.note ; info notes @text.note ; info notes
@text.warning ; warning notes @text.warning ; warning notes
@ -238,6 +239,14 @@ Used for XML-like tags.
@nospell ; for defining regions that should NOT be spellchecked @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 ### Locals
Note: pay specific attention to the captures here as they are a bit different to Note: pay specific attention to the captures here as they are a bit different to

View file

@ -112,10 +112,8 @@
(number_literal) @number (number_literal) @number
(char_literal) @character (char_literal) @character
[ ((preproc_arg) @function.macro (#set! "priority" 90))
(preproc_arg) (preproc_defined) @function.macro
(preproc_defined)
] @function.macro
(((field_expression (((field_expression
(field_identifier) @property)) @_parent (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_h5_marker) @text.title.5.marker (inline) @text.title.5)
(atx_heading (atx_h6_marker) @text.title.6.marker (inline) @text.title.6) (atx_heading (atx_h6_marker) @text.title.6.marker (inline) @text.title.6)
[ (link_title) @text.literal
(link_title) (indented_code_block) @text.literal.block
(indented_code_block) ((fenced_code_block) @text.literal.block (#set! "priority" 90))
(fenced_code_block)
] @text.literal
(info_string) @label (info_string) @label

View file

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