forked from Mirrors/helix
Indentation rework (#1562)
* WIP: Rework indentation system * Add ComplexNode for context-aware indentation (including a proof of concept for assignment statements in rust) * Add switch statements to Go indents.toml (fixes the second half of issue #1523) Remove commented-out code * Migrate all existing indentation queries. Add more options to ComplexNode and use them to improve C/C++ indentation. * Add comments & replace Option<Vec<_>> with Vec<_> * Add more detailed documentation for tree-sitter indentation * Improve code style in indent.rs * Use tree-sitter queries for indentation instead of TOML config. Migrate existing indent queries. * Add documentation for the new indent queries. Change xtask docgen to look for indents.scm instead of indents.toml * Improve code style in indent.rs. Fix an issue with the rust indent query. * Move indentation test sources to separate files. Add `#not-kind-eq?`, `#same-line?` and `#not-same-line` custom predicates. Improve the rust and c indent queries. * Fix indent test. Improve rust indent queries. * Move indentation tests to integration test folder. * Improve code style in indent.rs. Reuse tree-sitter cursors for indentation queries. * Migrate HCL indent query * Replace custom loading in indent tests with a designated languages.toml * Update indent query file name for --health command. * Fix single-space formatting in indent queries. * Add explanation for unwrapping. Co-authored-by: Triton171 <triton0171@gmail.com>imgbot
parent
c18de0e8f0
commit
58758fee61
@ -0,0 +1,79 @@
|
||||
# Adding Indent Queries
|
||||
|
||||
Helix uses tree-sitter to correctly indent new lines. This requires
|
||||
a tree-sitter grammar and an `indent.scm` query file placed in
|
||||
`runtime/queries/{language}/indents.scm`. The indentation for a line
|
||||
is calculated by traversing the syntax tree from the lowest node at the
|
||||
beginning of the new line. Each of these nodes contributes to the total
|
||||
indent when it is captured by the query (in what way depends on the name
|
||||
of 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.
|
||||
|
||||
## Scopes
|
||||
|
||||
Added indents don't always apply to the whole node. For example, in most
|
||||
cases when a node should be indented, we actually only want everything
|
||||
except for its first line to be indented. For this, there are several
|
||||
scopes (more scopes may be added in the future if required):
|
||||
|
||||
- `all`:
|
||||
This scope applies to the whole captured node. This is only different from
|
||||
`tail` when the captured node is the first node on its line.
|
||||
|
||||
- `tail`:
|
||||
This scope applies to everything except for the first line of the
|
||||
captured node.
|
||||
|
||||
Every capture type has a default scope which should do the right thing
|
||||
in most situations. When a different scope is required, this can be
|
||||
changed by using a `#set!` declaration anywhere in the pattern:
|
||||
```scm
|
||||
(assignment_expression
|
||||
right: (_) @indent
|
||||
(#set! "scope" "all"))
|
||||
```
|
||||
|
||||
## Capture Types
|
||||
|
||||
- `@indent` (default scope `tail`):
|
||||
Increase the indent level by 1. Multiple occurences in the same line
|
||||
don't stack. If there is at least one `@indent` and one `@outdent`
|
||||
capture on the same line, the indent level isn't changed at all.
|
||||
|
||||
- `@outdent` (default scope `all`):
|
||||
Decrease the indent level by 1. The same rules as for `@indent` apply.
|
||||
|
||||
## Predicates
|
||||
|
||||
In some cases, an S-expression cannot express exactly what pattern should be matched.
|
||||
For that, tree-sitter allows for predicates to appear anywhere within a pattern,
|
||||
similar to how `#set!` declarations work:
|
||||
```scm
|
||||
(some_kind
|
||||
(child_kind) @indent
|
||||
(#predicate? arg1 arg2 ...)
|
||||
)
|
||||
```
|
||||
The number of arguments depends on the predicate that's used.
|
||||
Each argument is either a capture (`@name`) or a string (`"some string"`).
|
||||
The following predicates are supported by tree-sitter:
|
||||
|
||||
- `#eq?`/`#not-eq?`:
|
||||
The first argument (a capture) must/must not be equal to the second argument
|
||||
(a capture or a string).
|
||||
|
||||
- `#match?`/`#not-match?`:
|
||||
The first argument (a capture) must/must not match the regex given in the
|
||||
second argument (a string).
|
||||
|
||||
Additionally, we support some custom predicates for indent queries:
|
||||
|
||||
- `#not-kind-eq?`:
|
||||
The kind of the first argument (a capture) must not be equal to the second
|
||||
argument (a string).
|
||||
|
||||
- `#same-line?`/`#not-same-line?`:
|
||||
The captures given by the 2 arguments must/must not start on the same line.
|
@ -0,0 +1 @@
|
||||
../../../src/indent.rs
|
@ -0,0 +1,13 @@
|
||||
# This languages.toml should contain definitions for all languages for which we have indent tests
|
||||
[[language]]
|
||||
name = "rust"
|
||||
scope = "source.rust"
|
||||
injection-regex = "rust"
|
||||
file-types = ["rs"]
|
||||
comment-token = "//"
|
||||
roots = ["Cargo.toml", "Cargo.lock"]
|
||||
indent = { tab-width = 4, unit = " " }
|
||||
|
||||
[[grammar]]
|
||||
name = "rust"
|
||||
source = { git = "https://github.com/tree-sitter/tree-sitter-rust", rev = "a360da0a29a19c281d08295a35ecd0544d2da211" }
|
@ -0,0 +1,105 @@
|
||||
use std::{
|
||||
io::{self, stdout, Stdout, Write},
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
mod test {
|
||||
fn hello_world() {
|
||||
1 + 1;
|
||||
|
||||
let does_indentation_work = 1;
|
||||
|
||||
let mut really_long_variable_name_using_up_the_line =
|
||||
really_long_fn_that_should_definitely_go_on_the_next_line();
|
||||
really_long_variable_name_using_up_the_line =
|
||||
really_long_fn_that_should_definitely_go_on_the_next_line();
|
||||
really_long_variable_name_using_up_the_line |=
|
||||
really_long_fn_that_should_definitely_go_on_the_next_line();
|
||||
|
||||
let (
|
||||
a_long_variable_name_in_this_tuple,
|
||||
b_long_variable_name_in_this_tuple,
|
||||
c_long_variable_name_in_this_tuple,
|
||||
d_long_variable_name_in_this_tuple,
|
||||
e_long_variable_name_in_this_tuple,
|
||||
): (usize, usize, usize, usize, usize) =
|
||||
if really_long_fn_that_should_definitely_go_on_the_next_line() {
|
||||
(
|
||||
03294239434,
|
||||
1213412342314,
|
||||
21231234134,
|
||||
834534234549898789,
|
||||
9879234234543853457,
|
||||
)
|
||||
} else {
|
||||
(0, 1, 2, 3, 4)
|
||||
};
|
||||
|
||||
let test_function = function_with_param(this_param,
|
||||
that_param
|
||||
);
|
||||
|
||||
let test_function = function_with_param(
|
||||
this_param,
|
||||
that_param
|
||||
);
|
||||
|
||||
let test_function = function_with_proper_indent(param1,
|
||||
param2,
|
||||
);
|
||||
|
||||
let selection = Selection::new(
|
||||
changes
|
||||
.clone()
|
||||
.map(|(start, end, text): (usize, usize, Option<Tendril>)| {
|
||||
let len = text.map(|text| text.len()).unwrap() - 1; // minus newline
|
||||
let pos = start + len;
|
||||
Range::new(pos, pos)
|
||||
})
|
||||
.collect(),
|
||||
0,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, D> MyTrait<A, D> for YourType
|
||||
where
|
||||
A: TraitB + TraitC,
|
||||
D: TraitE + TraitF,
|
||||
{
|
||||
|
||||
}
|
||||
#[test]
|
||||
//
|
||||
match test {
|
||||
Some(a) => 1,
|
||||
None => {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
std::panic::set_hook(Box::new(move |info| {
|
||||
hook(info);
|
||||
}));
|
||||
|
||||
{ { {
|
||||
1
|
||||
}}}
|
||||
|
||||
pub fn change<I>(document: &Document, changes: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = Change> + ExactSizeIterator,
|
||||
{
|
||||
[
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
];
|
||||
(
|
||||
1,
|
||||
2
|
||||
);
|
||||
true
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
use helix_core::{
|
||||
indent::{treesitter_indent_for_pos, IndentStyle},
|
||||
syntax::Loader,
|
||||
Syntax,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
fn test_treesitter_indent_rust() {
|
||||
test_treesitter_indent("rust.rs", "source.rust");
|
||||
}
|
||||
#[test]
|
||||
fn test_treesitter_indent_rust_2() {
|
||||
test_treesitter_indent("indent.rs", "source.rust");
|
||||
// TODO Use commands.rs as indentation test.
|
||||
// Currently this fails because we can't align the parameters of a closure yet
|
||||
// test_treesitter_indent("commands.rs", "source.rust");
|
||||
}
|
||||
|
||||
fn test_treesitter_indent(file_name: &str, lang_scope: &str) {
|
||||
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
test_dir.push("tests/data/indent");
|
||||
|
||||
let mut test_file = test_dir.clone();
|
||||
test_file.push(file_name);
|
||||
let test_file = std::fs::File::open(test_file).unwrap();
|
||||
let doc = ropey::Rope::from_reader(test_file).unwrap();
|
||||
|
||||
let mut config_file = test_dir;
|
||||
config_file.push("languages.toml");
|
||||
let config = std::fs::read(config_file).unwrap();
|
||||
let config = toml::from_slice(&config).unwrap();
|
||||
let loader = Loader::new(config);
|
||||
|
||||
// set runtime path so we can find the queries
|
||||
let mut runtime = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
runtime.push("../runtime");
|
||||
std::env::set_var("HELIX_RUNTIME", runtime.to_str().unwrap());
|
||||
|
||||
let language_config = loader.language_config_for_scope(lang_scope).unwrap();
|
||||
let highlight_config = language_config.highlight_config(&[]).unwrap();
|
||||
let syntax = Syntax::new(&doc, highlight_config, std::sync::Arc::new(loader));
|
||||
let indent_query = language_config.indent_query().unwrap();
|
||||
let text = doc.slice(..);
|
||||
|
||||
for i in 0..doc.len_lines() {
|
||||
let line = text.line(i);
|
||||
if let Some(pos) = helix_core::find_first_non_whitespace_char(line) {
|
||||
let suggested_indent = treesitter_indent_for_pos(
|
||||
indent_query,
|
||||
&syntax,
|
||||
&IndentStyle::Spaces(4),
|
||||
text,
|
||||
i,
|
||||
text.line_to_char(i) + pos,
|
||||
false,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
line.get_slice(..pos).map_or(false, |s| s == suggested_indent),
|
||||
"Wrong indentation on line {}:\n\"{}\" (original line)\n\"{}\" (suggested indentation)\n",
|
||||
i+1,
|
||||
line.slice(..line.len_chars()-1),
|
||||
suggested_indent,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
[
|
||||
(compound_statement)
|
||||
(field_declaration_list)
|
||||
(enumerator_list)
|
||||
(parameter_list)
|
||||
(init_declarator)
|
||||
(case_statement)
|
||||
(expression_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"case"
|
||||
"}"
|
||||
"]"
|
||||
] @outdent
|
||||
|
||||
(if_statement
|
||||
consequence: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(while_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(do_statement
|
||||
body: (_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
||||
(for_statement
|
||||
")"
|
||||
(_) @indent
|
||||
(#not-kind-eq? @indent "compound_statement")
|
||||
(#set! "scope" "all"))
|
@ -1,16 +0,0 @@
|
||||
indent = [
|
||||
"compound_statement",
|
||||
"field_declaration_list",
|
||||
"enumerator_list",
|
||||
"parameter_list",
|
||||
"init_declarator",
|
||||
"case_statement",
|
||||
"condition_clause",
|
||||
"expression_statement",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"case",
|
||||
"}",
|
||||
"]",
|
||||
]
|
@ -0,0 +1,10 @@
|
||||
[
|
||||
(if_condition)
|
||||
(foreach_loop)
|
||||
(while_loop)
|
||||
(function_def)
|
||||
(macro_def)
|
||||
(normal_command)
|
||||
] @indent
|
||||
|
||||
")" @outdent
|
@ -1,12 +0,0 @@
|
||||
indent = [
|
||||
"if_condition",
|
||||
"foreach_loop",
|
||||
"while_loop",
|
||||
"function_def",
|
||||
"macro_def",
|
||||
"normal_command",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
")"
|
||||
]
|
@ -0,0 +1,3 @@
|
||||
; inherits: c
|
||||
|
||||
(access_specifier) @outdent
|
@ -1,17 +0,0 @@
|
||||
indent = [
|
||||
"compound_statement",
|
||||
"field_declaration_list",
|
||||
"enumerator_list",
|
||||
"parameter_list",
|
||||
"init_declarator",
|
||||
"case_statement",
|
||||
"condition_clause",
|
||||
"expression_statement",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"case",
|
||||
"access_specifier",
|
||||
"}",
|
||||
"]",
|
||||
]
|
@ -0,0 +1,20 @@
|
||||
[
|
||||
(class_body)
|
||||
(function_body)
|
||||
(function_expression_body)
|
||||
(declaration)
|
||||
(initializers)
|
||||
(switch_block)
|
||||
(if_statement)
|
||||
(formal_parameter_list)
|
||||
(formal_parameter)
|
||||
(list_literal)
|
||||
(return_statement)
|
||||
(arguments)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
@ -1,20 +0,0 @@
|
||||
indent = [
|
||||
"class_body",
|
||||
"function_body",
|
||||
"function_expression_body",
|
||||
"declaration",
|
||||
"initializers",
|
||||
"switch_block",
|
||||
"if_statement",
|
||||
"formal_parameter_list",
|
||||
"formal_parameter",
|
||||
"list_literal",
|
||||
"return_statement",
|
||||
"arguments"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
"]",
|
||||
")"
|
||||
]
|
@ -0,0 +1,12 @@
|
||||
[
|
||||
(function_definition)
|
||||
(while_statement)
|
||||
(for_statement)
|
||||
(if_statement)
|
||||
(begin_statement)
|
||||
(switch_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"end"
|
||||
] @outdent
|
@ -1,12 +0,0 @@
|
||||
indent = [
|
||||
"function_definition",
|
||||
"while_statement",
|
||||
"for_statement",
|
||||
"if_statement",
|
||||
"begin_statement",
|
||||
"switch_statement",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"end"
|
||||
]
|
@ -0,0 +1,19 @@
|
||||
[
|
||||
(init_declarator)
|
||||
(compound_statement)
|
||||
(preproc_arg)
|
||||
(field_declaration_list)
|
||||
(case_statement)
|
||||
(conditional_expression)
|
||||
(enumerator_list)
|
||||
(struct_specifier)
|
||||
(compound_literal_expression)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"#define"
|
||||
"#ifdef"
|
||||
"#endif"
|
||||
"{"
|
||||
"}"
|
||||
] @outdent
|
@ -1,19 +0,0 @@
|
||||
indent = [
|
||||
"init_declarator",
|
||||
"compound_statement",
|
||||
"preproc_arg",
|
||||
"field_declaration_list",
|
||||
"case_statement",
|
||||
"conditional_expression",
|
||||
"enumerator_list",
|
||||
"struct_specifier",
|
||||
"compound_literal_expression"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"#define",
|
||||
"#ifdef",
|
||||
"#endif",
|
||||
"{",
|
||||
"}"
|
||||
]
|
@ -0,0 +1,26 @@
|
||||
[
|
||||
(import_declaration)
|
||||
(const_declaration)
|
||||
(type_declaration)
|
||||
(type_spec)
|
||||
(func_literal)
|
||||
(literal_value)
|
||||
(element)
|
||||
(keyed_element)
|
||||
(expression_case)
|
||||
(default_case)
|
||||
(type_case)
|
||||
(communication_case)
|
||||
(argument_list)
|
||||
(field_declaration_list)
|
||||
(block)
|
||||
(type_switch_statement)
|
||||
(expression_switch_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"case"
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
@ -1,30 +0,0 @@
|
||||
indent = [
|
||||
"import_declaration",
|
||||
"const_declaration",
|
||||
#"var_declaration",
|
||||
#"short_var_declaration",
|
||||
"type_declaration",
|
||||
"type_spec",
|
||||
# simply block should be enough
|
||||
# "function_declaration",
|
||||
# "method_declaration",
|
||||
# "composite_literal",
|
||||
"func_literal",
|
||||
"literal_value",
|
||||
"element",
|
||||
"keyed_element",
|
||||
"expression_case",
|
||||
"default_case",
|
||||
"type_case",
|
||||
"communication_case",
|
||||
"argument_list",
|
||||
"field_declaration_list",
|
||||
"block",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"case",
|
||||
"}",
|
||||
"]",
|
||||
")"
|
||||
]
|
@ -0,0 +1,13 @@
|
||||
[
|
||||
(object)
|
||||
(block)
|
||||
(tuple)
|
||||
(for_tuple_expr)
|
||||
(for_object_expr)
|
||||
] @indent
|
||||
|
||||
[
|
||||
(object_end)
|
||||
(block_end)
|
||||
(tuple_end)
|
||||
] @outdent
|
@ -1,13 +0,0 @@
|
||||
indent = [
|
||||
"object",
|
||||
"block",
|
||||
"tuple",
|
||||
"for_tuple_expr",
|
||||
"for_object_expr"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"object_end",
|
||||
"block_end",
|
||||
"tuple_end"
|
||||
]
|
@ -0,0 +1,22 @@
|
||||
[
|
||||
(array)
|
||||
(object)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
|
||||
(statement_block)
|
||||
(object_pattern)
|
||||
(class_body)
|
||||
(named_imports)
|
||||
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(template_substitution)
|
||||
(export_clause)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
@ -1,28 +0,0 @@
|
||||
indent = [
|
||||
"array",
|
||||
"object",
|
||||
"arguments",
|
||||
"formal_parameters",
|
||||
|
||||
"statement_block",
|
||||
"object_pattern",
|
||||
"class_body",
|
||||
"named_imports",
|
||||
|
||||
"binary_expression",
|
||||
"return_statement",
|
||||
"template_substitution",
|
||||
# (expression_statement (call_expression))
|
||||
"export_clause",
|
||||
|
||||
# typescript
|
||||
"enum_declaration",
|
||||
"interface_declaration",
|
||||
"object_type",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
"]",
|
||||
")"
|
||||
]
|
@ -0,0 +1,9 @@
|
||||
[
|
||||
(object)
|
||||
(array)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"]"
|
||||
"}"
|
||||
] @outdent
|
@ -1,9 +0,0 @@
|
||||
indent = [
|
||||
"object",
|
||||
"array"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"]",
|
||||
"}"
|
||||
]
|
@ -0,0 +1,2 @@
|
||||
(block_mapping_pair) @indent
|
||||
|
@ -1,3 +0,0 @@
|
||||
indent = [
|
||||
"block_mapping_pair",
|
||||
]
|
@ -0,0 +1,3 @@
|
||||
(basic_block) @indent
|
||||
|
||||
(label) @outdent
|
@ -1,7 +0,0 @@
|
||||
indent = [
|
||||
"basic_block",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"label",
|
||||
]
|
@ -0,0 +1,6 @@
|
||||
[
|
||||
(function_body)
|
||||
(instruction)
|
||||
] @indent
|
||||
|
||||
"}" @outdent
|
@ -1,8 +0,0 @@
|
||||
indent = [
|
||||
"function_body",
|
||||
"instruction",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
]
|
@ -0,0 +1,24 @@
|
||||
[
|
||||
(function_definition)
|
||||
(variable_declaration)
|
||||
(local_variable_declaration)
|
||||
(field)
|
||||
(local_function)
|
||||
(function)
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(for_in_statement)
|
||||
(repeat_statement)
|
||||
(return_statement)
|
||||
(while_statement)
|
||||
(table)
|
||||
(arguments)
|
||||
(do_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"end"
|
||||
"until"
|
||||
"}"
|
||||
")"
|
||||
] @outdent
|
@ -1,24 +0,0 @@
|
||||
indent = [
|
||||
"function_definition",
|
||||
"variable_declaration",
|
||||
"local_variable_declaration",
|
||||
"field",
|
||||
"local_function",
|
||||
"function",
|
||||
"if_statement",
|
||||
"for_statement",
|
||||
"for_in_statement",
|
||||
"repeat_statement",
|
||||
"return_statement",
|
||||
"while_statement",
|
||||
"table",
|
||||
"arguments",
|
||||
"do_statement",
|
||||
]
|
||||
|
||||
oudent = [
|
||||
"end",
|
||||
"until",
|
||||
"}",
|
||||
")",
|
||||
]
|
@ -0,0 +1,18 @@
|
||||
[
|
||||
; "function",
|
||||
(bind)
|
||||
(assert)
|
||||
(with)
|
||||
(let)
|
||||
(if)
|
||||
|
||||
(attrset)
|
||||
(list)
|
||||
(indented_string)
|
||||
(parenthesized)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
] @outdent
|
@ -1,18 +0,0 @@
|
||||
indent = [
|
||||
# "function",
|
||||
"bind",
|
||||
"assert",
|
||||
"with",
|
||||
"let",
|
||||
"if",
|
||||
|
||||
"attrset",
|
||||
"list",
|
||||
"indented_string",
|
||||
"parenthesized",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
"]",
|
||||
]
|
@ -0,0 +1,12 @@
|
||||
[
|
||||
(let_binding)
|
||||
(type_binding)
|
||||
(structure)
|
||||
(signature)
|
||||
(record_declaration)
|
||||
(function_expression)
|
||||
(match_case)
|
||||
] @indent
|
||||
|
||||
"}" @outdent
|
||||
|
@ -1,13 +0,0 @@
|
||||
indent = [
|
||||
"let_binding",
|
||||
"type_binding",
|
||||
"structure",
|
||||
"signature",
|
||||
"record_declaration",
|
||||
"function_expression",
|
||||
"match_case",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
]
|
@ -0,0 +1,15 @@
|
||||
[
|
||||
(function)
|
||||
(identifier)
|
||||
(method_invocation)
|
||||
(if_statement)
|
||||
(unless_statement)
|
||||
(if_simple_statement)
|
||||
(unless_simple_statement)
|
||||
(variable_declaration)
|
||||
(block)
|
||||
(list_item)
|
||||
(word_list_qw)
|
||||
] @indent
|
||||
|
||||
"}" @outdent
|
@ -1,17 +0,0 @@
|
||||
indent = [
|
||||
"function",
|
||||
"identifier",
|
||||
"method_invocation",
|
||||
"if_statement",
|
||||
"unless_statement",
|
||||
"if_simple_statement",
|
||||
"unless_simple_statement",
|
||||
"variable_declaration",
|
||||
"block",
|
||||
"list_item",
|
||||
"word_list_qw"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}"
|
||||
]
|
@ -0,0 +1,17 @@
|
||||
[
|
||||
(array_creation_expression)
|
||||
(arguments)
|
||||
(formal_parameters)
|
||||
(compound_statement)
|
||||
(declaration_list)
|
||||
(binary_expression)
|
||||
(return_statement)
|
||||
(expression_statement)
|
||||
(switch_block)
|
||||
(anonymous_function_use_clause)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
")"
|
||||
] @outdent
|
@ -1,17 +0,0 @@
|
||||
indent = [
|
||||
"array_creation_expression",
|
||||
"arguments",
|
||||
"formal_parameters",
|
||||
"compound_statement",
|
||||
"declaration_list",
|
||||
"binary_expression",
|
||||
"return_statement",
|
||||
"expression_statement",
|
||||
"switch_block",
|
||||
"anonymous_function_use_clause",
|
||||
]
|
||||
|
||||
oudent = [
|
||||
"}",
|
||||
")",
|
||||
]
|
@ -0,0 +1,11 @@
|
||||
[
|
||||
(messageBody)
|
||||
(enumBody)
|
||||
(oneofBody)
|
||||
(serviceBody)
|
||||
(rpcBody)
|
||||
(msgLit)
|
||||
] @indent
|
||||
|
||||
"}" @outdent
|
||||
|
@ -1,12 +0,0 @@
|
||||
indent = [
|
||||
"messageBody",
|
||||
"enumBody",
|
||||
"oneofBody",
|
||||
"serviceBody",
|
||||
"rpcBody",
|
||||
"msgLit",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
]
|
@ -0,0 +1,38 @@
|
||||
[
|
||||
(list)
|
||||
(tuple)
|
||||
(dictionary)
|
||||
(set)
|
||||
|
||||
(if_statement)
|
||||
(for_statement)
|
||||
(while_statement)
|
||||
(with_statement)
|
||||
(try_statement)
|
||||
(import_from_statement)
|
||||
|
||||
(parenthesized_expression)
|
||||
(generator_expression)
|
||||
(list_comprehension)
|
||||
(set_comprehension)
|
||||
(dictionary_comprehension)
|
||||
|
||||
(tuple_pattern)
|
||||
(list_pattern)
|
||||
(argument_list)
|
||||
(parameters)
|
||||
(binary_operator)
|
||||
|
||||
(function_definition)
|
||||
(class_definition)
|
||||
] @indent
|
||||
|
||||
[
|
||||
")"
|
||||
"]"
|
||||
"}"
|
||||
(return_statement)
|
||||
(pass_statement)
|
||||
(raise_statement)
|
||||
] @outdent
|
||||
|
@ -1,39 +0,0 @@
|
||||
indent = [
|
||||
"list",
|
||||
"tuple",
|
||||
"dictionary",
|
||||
"set",
|
||||
|
||||
"if_statement",
|
||||
"for_statement",
|
||||
"while_statement",
|
||||
"with_statement",
|
||||
"try_statement",
|
||||
"import_from_statement",
|
||||
|
||||
"parenthesized_expression",
|
||||
"generator_expression",
|
||||
"list_comprehension",
|
||||
"set_comprehension",
|
||||
"dictionary_comprehension",
|
||||
|
||||
"tuple_pattern",
|
||||
"list_pattern",
|
||||
"argument_list",
|
||||
"parameters",
|
||||
"binary_operator",
|
||||
|
||||
"function_definition",
|
||||
"class_definition",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
")",
|
||||
"]",
|
||||
"}",
|
||||
"return_statement",
|
||||
"pass_statement",
|
||||
"raise_statement",
|
||||
]
|
||||
|
||||
ignore = ["string"]
|
@ -0,0 +1,25 @@
|
||||
[
|
||||
(argument_list)
|
||||
(array)
|
||||
(begin)
|
||||
(block)
|
||||
(call)
|
||||
(class)
|
||||
(case)
|
||||
(do_block)
|
||||
(elsif)
|
||||
(if)
|
||||
(hash)
|
||||
(method)
|
||||
(module)
|
||||
(singleton_class)
|
||||
(singleton_method)
|
||||
] @indent
|
||||
|
||||
[
|
||||
")"
|
||||
"}"
|
||||
"]"
|
||||
"end"
|
||||
"when"
|
||||
] @outdent
|
@ -1,25 +0,0 @@
|
||||
indent = [
|
||||
"argument_list",
|
||||
"array",
|
||||
"begin",
|
||||
"block",
|
||||
"call",
|
||||
"class",
|
||||
"case",
|
||||
"do_block",
|
||||
"elsif",
|
||||
"if",
|
||||
"hash",
|
||||
"method",
|
||||
"module",
|
||||
"singleton_class",
|
||||
"singleton_method",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
")",
|
||||
"}",
|
||||
"]",
|
||||
"end",
|
||||
"when",
|
||||
]
|
@ -0,0 +1,80 @@
|
||||
[
|
||||
(use_list)
|
||||
(block)
|
||||
(match_block)
|
||||
(arguments)
|
||||
(parameters)
|
||||
(declaration_list)
|
||||
(field_declaration_list)
|
||||
(field_initializer_list)
|
||||
(struct_pattern)
|
||||
(tuple_pattern)
|
||||
(unit_expression)
|
||||
(enum_variant_list)
|
||||
(call_expression)
|
||||
(binary_expression)
|
||||
(field_expression)
|
||||
(tuple_expression)
|
||||
(array_expression)
|
||||
(where_clause)
|
||||
|
||||
(token_tree)
|
||||
(macro_definition)
|
||||
(token_tree_pattern)
|
||||
(token_repetition)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
||||
|
||||
; Indent the right side of assignments.
|
||||
; The #not-same-line? predicate is required to prevent an extra indent for e.g.
|
||||
; an else-clause where the previous if-clause starts on the same line as the assignment.
|
||||
(assignment_expression
|
||||
.
|
||||
(_) @expr-start
|
||||
right: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(compound_assignment_expr
|
||||
.
|
||||
(_) @expr-start
|
||||
right: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(let_declaration
|
||||
.
|
||||
(_) @expr-start
|
||||
value: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(if_let_expression
|
||||
.
|
||||
(_) @expr-start
|
||||
value: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
(static_item
|
||||
.
|
||||
(_) @expr-start
|
||||
value: (_) @indent
|
||||
(#not-same-line? @indent @expr-start)
|
||||
(#set! "scope" "all")
|
||||
)
|
||||
|
||||
; Some field expressions where the left part is a multiline expression are not
|
||||
; indented by cargo fmt.
|
||||
; Because this multiline expression might be nested in an arbitrary number of
|
||||
; field expressions, this can only be matched using a Regex.
|
||||
(field_expression
|
||||
value: (_) @val
|
||||
"." @outdent
|
||||
(#match? @val "(\\A[^\\n\\r]+\\([\\t ]*(\\n|\\r).*)|(\\A[^\\n\\r]*\\{[\\t ]*(\\n|\\r))")
|
||||
)
|
@ -1,28 +0,0 @@
|
||||
indent = [
|
||||
"use_list",
|
||||
"block",
|
||||
"match_block",
|
||||
"arguments",
|
||||
"parameters",
|
||||
"declaration_list",
|
||||
"field_declaration_list",
|
||||
"field_initializer_list",
|
||||
"struct_pattern",
|
||||
"tuple_pattern",
|
||||
"unit_expression",
|
||||
"enum_variant_list",
|
||||
"call_expression",
|
||||
"binary_expression",
|
||||
"field_expression",
|
||||
"tuple_expression",
|
||||
"array_expression",
|
||||
"where_clause",
|
||||
"macro_invocation"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"where",
|
||||
"}",
|
||||
"]",
|
||||
")"
|
||||
]
|
@ -0,0 +1,22 @@
|
||||
[
|
||||
(block)
|
||||
(arguments)
|
||||
(parameter)
|
||||
(class_definition)
|
||||
(trait_definition)
|
||||
(object_definition)
|
||||
(function_definition)
|
||||
(val_definition)
|
||||
(import_declaration)
|
||||
(while_expression)
|
||||
(do_while_expression)
|
||||
(for_expression)
|
||||
(try_expression)
|
||||
(match_expression)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
@ -1,23 +0,0 @@
|
||||
|
||||
indent = [
|
||||
"block",
|
||||
"arguments",
|
||||
"parameter",
|
||||
"class_definition",
|
||||
"trait_definition",
|
||||
"object_definition",
|
||||
"function_definition",
|
||||
"val_definition",
|
||||
"import_declaration",
|
||||
"while_expression",
|
||||
"do_while_expression",
|
||||
"for_expression",
|
||||
"try_expression",
|
||||
"match_expression"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
"]",
|
||||
")"
|
||||
]
|
@ -0,0 +1,17 @@
|
||||
[
|
||||
(element)
|
||||
(if_statement)
|
||||
(each_statement)
|
||||
(await_statement)
|
||||
] @indent
|
||||
|
||||
[
|
||||
(end_tag)
|
||||
(else_statement)
|
||||
(if_end_expr)
|
||||
(each_end_expr)
|
||||
(await_end_expr)
|
||||
">"
|
||||
"/>"
|
||||
] @outdent
|
||||
|
@ -1,18 +0,0 @@
|
||||
indent = [
|
||||
"element"
|
||||
"if_statement"
|
||||
"each_statement"
|
||||
"await_statement"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"end_tag"
|
||||
"else_statement"
|
||||
"if_end_expr"
|
||||
"each_end_expr"
|
||||
"await_end_expr"
|
||||
">"
|
||||
"/>"
|
||||
]
|
||||
|
||||
ignore = "comment"
|
@ -0,0 +1,3 @@
|
||||
(statement) @indent
|
||||
|
||||
"}" @outdent
|
@ -1,7 +0,0 @@
|
||||
indent = [
|
||||
"statement",
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
]
|
@ -0,0 +1,7 @@
|
||||
; inherits: javascript
|
||||
|
||||
[
|
||||
(enum_declaration)
|
||||
(interface_declaration)
|
||||
(object_type)
|
||||
] @indent
|
@ -1 +0,0 @@
|
||||
../javascript/indents.toml
|
@ -0,0 +1,2 @@
|
||||
(block_mapping_pair) @indent
|
||||
|
@ -1,3 +0,0 @@
|
||||
indent = [
|
||||
"block_mapping_pair",
|
||||
]
|
@ -0,0 +1,16 @@
|
||||
[
|
||||
(Block)
|
||||
(BlockExpr)
|
||||
(ContainerDecl)
|
||||
(SwitchExpr)
|
||||
(AssignExpr)
|
||||
(ErrorUnionExpr)
|
||||
(Statement)
|
||||
(InitList)
|
||||
] @indent
|
||||
|
||||
[
|
||||
"}"
|
||||
"]"
|
||||
")"
|
||||
] @outdent
|
@ -1,16 +0,0 @@
|
||||
indent = [
|
||||
"Block",
|
||||
"BlockExpr",
|
||||
"ContainerDecl",
|
||||
"SwitchExpr",
|
||||
"AssignExpr",
|
||||
"ErrorUnionExpr",
|
||||
"Statement",
|
||||
"InitList"
|
||||
]
|
||||
|
||||
outdent = [
|
||||
"}",
|
||||
"]",
|
||||
")"
|
||||
]
|
Loading…
Reference in New Issue