Skip to content
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 indent issues when auto-pairs = false #7910

Open
salarkhan opened this issue Aug 11, 2023 · 4 comments
Open

golang indent issues when auto-pairs = false #7910

salarkhan opened this issue Aug 11, 2023 · 4 comments
Labels
A-indent Area: Indentation A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR

Comments

@salarkhan
Copy link

Summary

when writing expressions, i expect an outdent when i input the matching pair. in some cases, the closing brace is in line with the content of the expression:
Screenshot 2023-08-11 at 8 35 08 AM

in other cases like creating a function, i expect an indent after opening the brace and hitting enter, yet it does not.

all of these scenarios are resolved if i close the braces immediately, and then fill in the content.

Reproduction Steps

indent.mp4

Helix log

No response

Platform

macOS

Terminal Emulator

kitty 0.28.0

Helix Version

helix 23.05

@salarkhan salarkhan added the C-bug Category: This is a bug label Aug 11, 2023
@woojiq
Copy link
Contributor

woojiq commented Aug 11, 2023

Iirc that's how a tree-sitter works. This is not specific to golang. If you select your function without the closing brace and run :tree-sitter-subtree you will see that there is an error when parsing the source code. This is why indent-queries don't work well in this situation.

Edit:
image

image

As you can see in the second example, there is no Block node that is used to increase the indentation by 1.

@woojiq
Copy link
Contributor

woojiq commented Aug 11, 2023

Probably duplicate of #6044

@pascalkuthe
Copy link
Member

pascalkuthe commented Aug 11, 2023

Yeah the closing bracket not causing a decent without autopairs is both known and expected and would be covered by #6044.

For the error nodes causing indents we do sometimes work around situations like this by also matching error nodes in the tree sitter indent captures.

CC @Triton171

@Triton171
Copy link
Contributor

I think at least for simple scenarios it should be possible to fix this my matching error nodes. A possible pattern would be:

(ERROR
    "{" @indent @extend
)

This correctly indents a function even if the closing } is missing. However, an incomplete if statement inside the function is not indented correctly. Finding queries that work correctly for multiple incomplete nesting levels seems non-trivial since the tree-sitter grammar behaves weirdly in these cases. If you experiment a bit and look at the syntax tree (using the :tree-sitter-subtree and :tree-sitter-scopes commands), you might be able to find queries that cover most of the common situations though.

@pascalkuthe pascalkuthe added C-enhancement Category: Improvements A-language-support Area: Support for programming/text languages A-indent Area: Indentation E-easy Call for participation: Experience needed to fix: Easy / not much E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR and removed C-bug Category: This is a bug labels Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-indent Area: Indentation A-language-support Area: Support for programming/text languages C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR
Projects
None yet
Development

No branches or pull requests

4 participants