From 2244a5d40c83d477839f91cb6d6a4aeb02446a97 Mon Sep 17 00:00:00 2001 From: omentic Date: Wed, 1 May 2024 23:29:52 +0000 Subject: deploy: 12eec890240a05d1e090114f7f4fdd7c1ee8ff88 --- guides/indent.html | 37 +++++++++++++++++++++++++------------ guides/injection.html | 6 +++++- guides/rainbow_bracket_queries.html | 6 +++--- guides/textobject.html | 2 +- 4 files changed, 34 insertions(+), 17 deletions(-) (limited to 'guides') diff --git a/guides/indent.html b/guides/indent.html index a968f7bb..25be199a 100644 --- a/guides/indent.html +++ b/guides/indent.html @@ -189,6 +189,14 @@ the capture.
Note that it matters where these added indents begin. For example, multiple indent level increases that start on the same line only increase the total indent level by 1. See Capture types.
+By default, Helix uses the hybrid
indentation heuristic. This means that
+indent queries are not used to compute the expected absolute indentation of a
+line but rather the expected difference in indentation between the new and an
+already existing line. This difference is then added to the actual indentation
+of the already existing line. Since this makes errors in the indent queries
+harder to find, it is recommended to disable it when testing via
+:set indent-heuristic tree-sitter
. The rest of this guide assumes that
+the tree-sitter
heuristic is used.
When Helix is inserting a new line through o
, O
, or <ret>
, to determine
the indent level for the new line, the query in indents.scm
is run on the
@@ -283,7 +291,7 @@ actually have been extended).
// 3x @outdent
}
((block) @indent)
-["}" ")"] @outdent
+["}" ")"] @outdent
Note how on the second line, we have two blocks begin on the same line. In this case, since both captures occur on the same line, they are combined and only @@ -323,7 +331,7 @@ whitespace-sensitive.
the cursor on a line feed ends up being the entire inside of the class. Because of this, it will miss the entire function node and its indent capture, leading to an indent level one too small. -To address this case, @extend
tells helix to "extend" the captured node's span
+
To address this case, @extend
tells helix to "extend" the captured node's span
to the line feed and every consecutive line that has a greater indent level than
the line of the node.
(parenthesized_expression) @indent
@@ -431,7 +439,7 @@ similar to how #set!
declarations work:
)
The number of arguments depends on the predicate that's used.
-Each argument is either a capture (@name
) or a string ("some string"
).
+Each argument is either a capture (@name
) or a string ("some string"
).
The following predicates are supported by tree-sitter:
#any-of?
/#not-any-of?
:
+The first argument (a capture) must/must not be one of the other arguments
+(strings).
Additionally, we support some custom predicates for indent queries:
#![allow(unused)] fn main() { fn aha() { // ←─────────────────────────────────────╮ - let take = "on me"; // ←──────────────╮ scope: │ - let take = "me on"; // ├─ "tail" ├─ (block) @indent + let take = "on me"; // ←──────────────╮ scope: │ + let take = "me on"; // ├─ "tail" ├─ (block) @indent let ill = be_gone_days(1 || 2); // │ │ -} // ←───────────────────────────────────┴──────────┴─ "}" @outdent - // scope: "all" +} // ←───────────────────────────────────┴──────────┴─ "}" @outdent + // scope: "all" }
We can write the following query with the #set!
declaration:
((block) @indent
- (#set! "scope" "tail"))
-("}" @outdent
- (#set! "scope" "all"))
+ (#set! "scope" "tail"))
+("}" @outdent
+ (#set! "scope" "all"))
-As we can see, the "tail" scope covers the node, except for the first line. +
As we can see, the "tail" scope covers the node, except for the first line.
Everything up to and including the closing brace gets an indent level of 1.
-Then, on the closing brace, we encounter an outdent with a scope of "all", which
+Then, on the closing brace, we encounter an outdent with a scope of "all", which
means the first line is included, and the indent level is cancelled out on this
line. (Note these scopes are the defaults for @indent
and @outdent
—they are
written explicitly for demonstration.)
#any-of?
(standard):
+The first argument (a capture) must be one of the other arguments (strings).
runtime/queries/tsq/rainbows.scm
file in the repository root.
First we'll add the @rainbow.bracket
captures. TSQ only has parentheses and
square brackets:
["(" ")" "[" "]"] @rainbow.bracket
+["(" ")" "[" "]"] @rainbow.bracket
The ordering of the nodes within the alternation (square brackets) is not
taken into consideration.
@@ -207,7 +207,7 @@ names of rules in the grammar. Brackets are usually written in tree-sitter
grammars as literal strings, for example:
{
// ...
- arguments: seq("(", repeat($.argument), ")"),
+ arguments: seq("(", repeat($.argument), ")"),
// ...
}
@@ -254,7 +254,7 @@ indirect descendants of some node captured with @rainbow.scope
.
If we want to highlight the <
, >
and </
nodes with rainbow colors, we
capture them as @rainbow.bracket
:
["<" ">" "</"] @rainbow.bracket
+["<" ">" "</"] @rainbow.bracket
And we capture (element)
as @rainbow.scope
because (element)
nodes nest
within each other: they increment the nesting level and switch to the next
diff --git a/guides/textobject.html b/guides/textobject.html
index a47fd8a6..d67f0dda 100644
--- a/guides/textobject.html
+++ b/guides/textobject.html
@@ -203,7 +203,7 @@ for example).
comment.around
-Example query files can be found in the helix GitHub repository.
+Example query files can be found in the helix GitHub repository.
Queries for textobject based navigation
Tree-sitter based navigation in Helix is done using captures in the
following order:
--
cgit v1.2.3-70-g09d2