-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Golang indentation broken for type declarations and switch statements #1523
Comments
You're right, the current indentation system has some limitations. I'm currently rewriting it for that reason (see #1440). Unless i can think of some situation where this goes wrong, only applying indent once per line seems like a good idea. Basically if there are 2 indents and 1 outdent on the same line we currently see that as a net indent which we shouldn't do, right? As for the switch statement, couldn't that just be solved by adding the |
How did this behave before #1341 ? |
I think the first example should've worked correctly before but it's hard to say because there were some weird edge cases. In any case, what @GeorgeNewby suggested should be a simple fix for it. The switch statement seems like a simple problem with the |
I just tested using type Test struct {|} On newline insertion, the following nodes are queried: What's interesting is the // if we're calculating indentation for a brand new line then the current node will become the
// parent node. We need to take it's indentation level into account too.
let node_kind = node.kind();
if newline && query.indent.contains(node_kind) {
increment += 1;
} The new version #1341 calculates the indent on the When entering a newline, should it be calculating the indent for the line directly underneath or the closing bracket 2 lines down? |
I might be biased as I changed it to calculate the indent of the closing brace but I think it makes more sense:
|
…sue helix-editor#1523) Remove commented-out code
…sue helix-editor#1523) Remove commented-out code
* 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>
Reproduction steps
Type Declaration
Switch Statement
Environment
Explanation
I've been looking into the issue quite a bit and I think it's an issue with the choice of nodes in
indents.toml
and some limitations of https://github.com/tree-sitter/tree-sitter-go.The type declaration is it indented because of the following nodes:
type_declaration
,type_spec
andfield_declaration_list
inindents.toml
. I don't think we should be using thefield_declaration_list
as an indent as instead use the actualstruct_spec
node. However this causes issues with type grouping and nested structs.I don't think we can ever do perfect indenting with just changes to
indent.toml
as the following example has identical treesitter nodes yet different indentations.Maybe one way to handle this is to ignore consecutive indents on the same line e.g.
type_declaration
andstruct_spec
should only apply 1increment_from_line
instead of 2 (inhelix-core/src/indent.rs
).I'm currently looking into a solution and will create PR if I can solve it
The text was updated successfully, but these errors were encountered: