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

Hybrid indentation can cause incorrect results at the end of indent scopes #10336

Closed
tsaraki opened this issue Apr 10, 2024 · 2 comments · Fixed by #10527
Closed

Hybrid indentation can cause incorrect results at the end of indent scopes #10336

tsaraki opened this issue Apr 10, 2024 · 2 comments · Fixed by #10527
Labels
A-indent Area: Indentation C-bug Category: This is a bug

Comments

@tsaraki
Copy link

tsaraki commented Apr 10, 2024

Summary

On windows, using Windows Terminal (new), in golang after closing curly brace open_below and/or open_above lost identation and start insert mode from first char of the line. But if before closing bracket is empty line, all works fine. Helix log doesnt represent much

Reproduction Steps

I tried this:

----some := 50
----if some > 34 {
--------fmt.Println("herhe")
----} <- cursor

open_below

I expected this to happen:

----some := 50
----if some > 34 {
--------fmt.Println("herhe")
----}
----<- cursor

Instead, this happened:

----some := 50
----if some > 34 {
--------fmt.Println("herhe")
----}
<- cursor

I tried this:

----some := 50
----if some > 34 {
--------fmt.Println("herhe")

----} <- cursor

open_below

As usually:

----some := 50
----if some > 34 {
--------fmt.Println("herhe")

----}
----<- cursor

Helix log

~/.cache/helix/helix.log

2024-04-10T19:44:20.771 helix_lsp::transport [ERROR] gopls err: <- StreamClosed

Platform

Windows

Terminal Emulator

wt 1.19.240322001

Installation Method

releases page

Helix Version

helix 24.3 (2cadec0)

@tsaraki tsaraki added the C-bug Category: This is a bug label Apr 10, 2024
@pascalkuthe
Copy link
Member

pascalkuthe commented Apr 11, 2024

@Triton171 this is a regression caused by #8307.

The hybrid indentation heuristic is not working as intended here. :set indentation-heuristic tree-sitter fixes this.

Proper reproduction case:

func main() {
	some := 50
	if some > 34 {
		fmt.Println("herhe")
	}
}

indentation after the second last closing brace is wrong.

With tree-sitter heuristic i<ret>foo inserts

func main() {
	some := 50
	if some > 34 {
		fmt.Println("herhe")
	}
    foo
}

Doing the same thing with the hybrid heuristic produces:

func main() {
	some := 50
	if some > 34 {
		fmt.Println("herhe")
	}
foo
}

@pascalkuthe pascalkuthe added the A-indent Area: Indentation label Apr 11, 2024
@pascalkuthe pascalkuthe changed the title Open_below/above ignoring indetadion Hybrid indentation can cause incorrect results at the end of indent scopes Apr 11, 2024
@Triton171
Copy link
Contributor

Thanks for the clean reproduction case @pascalkuthe! The issue was caused by the code that decides whether a tree-sitter node is the first in a line: Previously, we checked this by looking at the syntax tree but that can go wrong if the tree-sitter grammar creates nodes that end with whitespace. The Go grammar inserts "newline" nodes for some reason, which causes Helix to treat the newline node as the beginning of the line & not the node afterwards (} in this case). The linked PR fixes this & also simplifies the code a bit.

In theory, this issue could also occur with the tree-sitter indent heuristic, but the necessary circumstances are a lot less likely (due to the way most indent queries are currently structured).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-indent Area: Indentation C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants