godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.6k stars 170 forks source link

Formatter silently breaks with leading minus sign in multiline statement #717

Open cjmaxik opened 2 months ago

cjmaxik commented 2 months ago

Godot version

v4.3.stable.official [77dcf97d8]

VS Code version

1.93.1

Godot Tools VS Code extension version

2.1.0

System information

Windows 11

Issue description

If one uses a multiline statement and one of the lines has a leading minus sign, the formatter silently breaks.

Steps to reproduce

The following examples will break the formatter.

var test1 := deg_to_rad(
    -90
)

var test2 := Vector2(
    -0.0,
    1.0
)

var test3 := Vector3(
    0.0,
    -0.0,
    0.0
)

func get_audio_compensation() -> float:
    return AudioServer.get_time_since_last_mix() \
        - AudioServer.get_output_latency() \
        + (1 / Engine.get_frames_per_second()) * 2
nemoDreamer commented 3 weeks ago

Oh my God, that's it!!! I had a file that stopped getting formatted, and I couldn't for the life of me figure out what in my config was causing this to happen...!

😆 🤣 😢

DaelonSuzuka commented 3 weeks ago

Correctly detecting this situation might be approaching the limits of this formatter, but I might be able to make it continue formatting even if there's a problem....

DaelonSuzuka commented 3 weeks ago

I expected this to be difficult because the textmate tokenizer doesn't preserve a lot of context across lines, but it was actually a simple index-out-of-bounds error because the - is the 0th token and token n-1 doesn't exist.

This will be fixed in the next release.

nemoDreamer commented 2 weeks ago

Oh perfect! Happy it turned out to be “simple”! Thanks!

On Sun, Nov 3, 2024 at 11:28 AM David Kincaid @.***> wrote:

I expected this to be difficult because the textmate tokenizer doesn't preserve a lot of context across lines, but it was actually a simple index-out-of-bounds error because the - is the 0th token and token n-1 doesn't exist.

This will be fixed in the next release.

— Reply to this email directly, view it on GitHub https://github.com/godotengine/godot-vscode-plugin/issues/717#issuecomment-2453486261, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACIVYA6CYUSSNDRUDE4SDZ6Y6IBAVCNFSM6AAAAABOI7DYBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJTGQ4DMMRWGE . You are receiving this because you commented.Message ID: @.***>