From cb46f6e467268edf917cc3617b4c024a66b256de Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:32:17 -0500 Subject: feat(treesitter): support URLs (#27132) Tree-sitter queries can add URLs to a capture using the `#set!` directive, e.g. (inline_link (link_text) @text.reference (link_destination) @text.uri (#set! @text.reference "url" @text.uri)) The pattern above is included by default in the `markdown_inline` highlight query so that users with supporting terminals will see hyperlinks. For now, this creates a hyperlink for *all* Markdown URLs of the pattern [link text](link url), even if `link url` does not contain a valid protocol (e.g. if `link url` is a path to a file). We may wish to change this in the future to only linkify when the URL has a valid protocol scheme, but for now we delegate handling this to the terminal emulator. In order to support directives which reference other nodes, the highlighter must be updated to use `iter_matches` rather than `iter_captures`. The former provides the `match` table which maps capture IDs to nodes. However, this has its own challenges: - `iter_matches` does not guarantee the order in which patterns are iterated matches the order in the query file. So we must enforce ordering manually using "subpriorities" (#27131). The pattern index of each match dictates the extmark's subpriority. - When injections are used, the highlighter contains multiple trees. The pattern indices of each tree must be offset relative to the maximum pattern index from all previous trees to ensure that extmarks appear in the correct order. - The `iter_captures` implementation currently has a bug where the "match" table is only returned for the first capture within a pattern (see #27274). This bug means that `#set!` directives in a query apply only to the first capture within a pattern. Unfortunately, many queries in the wild have come to depend on this behavior. `iter_matches` does not share this flaw, so switching to `iter_matches` exposed bugs in existing highlight queries. These queries have been updated in this repo, but may still need to be updated by users. The `#set!` directive applies to the _entire_ query pattern when used without a capture argument. To make `#set!` apply only to a single capture, the capture must be given as an argument. --- runtime/queries/vimdoc/highlights.scm | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'runtime/queries/vimdoc') diff --git a/runtime/queries/vimdoc/highlights.scm b/runtime/queries/vimdoc/highlights.scm index 294fa94f10..0c10b3c0b3 100644 --- a/runtime/queries/vimdoc/highlights.scm +++ b/runtime/queries/vimdoc/highlights.scm @@ -12,21 +12,30 @@ (tag "*" @markup.heading.5.marker - (#set! conceal "") - text: (_) @label) + . + text: (_) @label + . + "*" @markup.heading.5.marker + (#set! @markup.heading.5.marker conceal "")) (taglink - "|" @markup.link - (#set! conceal "") - text: (_) @markup.link) + "|" @markup.link.delimiter + . + text: (_) @markup.link + . + "|" @markup.link.delimiter + (#set! @markup.link.delimiter conceal "")) (optionlink text: (_) @markup.link) (codespan "`" @markup.raw.delimiter - (#set! conceal "") - text: (_) @markup.raw) + . + text: (_) @markup.raw + . + "`" @markup.raw.delimiter + (#set! @markup.raw.delimiter conceal "")) ((codeblock) @markup.raw.block (#set! "priority" 90)) -- cgit From 987dff6713af618ca2be8a2542d4a65f2ab42510 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sun, 17 Mar 2024 13:13:12 +0100 Subject: feat(treesitter): update Vimdoc parser and queries to v2.4.0 --- runtime/queries/vimdoc/highlights.scm | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'runtime/queries/vimdoc') diff --git a/runtime/queries/vimdoc/highlights.scm b/runtime/queries/vimdoc/highlights.scm index 0c10b3c0b3..70a3a2f206 100644 --- a/runtime/queries/vimdoc/highlights.scm +++ b/runtime/queries/vimdoc/highlights.scm @@ -7,48 +7,46 @@ (column_heading) @markup.heading.4 (column_heading - "~" @markup.heading.4.marker + "~" @markup.heading.4 (#set! conceal "")) (tag - "*" @markup.heading.5.marker - . - text: (_) @label - . - "*" @markup.heading.5.marker - (#set! @markup.heading.5.marker conceal "")) + "*" @label + (#set! conceal "")) + +(tag + text: (_) @label) (taglink - "|" @markup.link.delimiter - . - text: (_) @markup.link - . - "|" @markup.link.delimiter - (#set! @markup.link.delimiter conceal "")) + "|" @markup.link + (#set! conceal "")) + +(taglink + text: (_) @markup.link) (optionlink text: (_) @markup.link) (codespan - "`" @markup.raw.delimiter - . - text: (_) @markup.raw - . - "`" @markup.raw.delimiter - (#set! @markup.raw.delimiter conceal "")) + "`" @markup.raw + (#set! conceal "")) + +(codespan + text: (_) @markup.raw) ((codeblock) @markup.raw.block (#set! "priority" 90)) (codeblock - [ - ">" - (language) - ] @markup.raw.delimiter + ">" @markup.raw + (#set! conceal "")) + +(codeblock + (language) @label (#set! conceal "")) (block - "<" @markup.raw.delimiter + "<" @markup.raw (#set! conceal "")) (argument) @variable.parameter @@ -57,6 +55,8 @@ (url) @string.special.url +(modeline) @keyword.directive + ((note) @comment.note (#any-of? @comment.note "Note:" "NOTE:" "Notes:")) -- cgit