godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.55k stars 163 forks source link

Formatter adds redundant spacing near minus/negation operator #579

Closed witnessmonolith closed 7 months ago

witnessmonolith commented 8 months ago

Godot version

4.2.1 stable

VS Code version

1.85.2

Godot Tools VS Code extension version

2.0.0 (current main branch, e2f2dc4)

System information

Windows 11 Home

Issue description

Hello. Seems like I've detected a minor but quite annoying bug.

With the code line like this:

cam_basis = cam_basis.rotated(cam_basis.x, -cam_basis.get_euler().x)

Formatter makes it like this, adding a redundant spacing after the - operator:

cam_basis = cam_basis.rotated(cam_basis.x, - cam_basis.get_euler().x)

Surprisingly enough, the following line from the same document is formatted correctly:

@onready var gravity = -ProjectSettings.get_setting("physics/3d/default_gravity")

The file in question is cubio.gd from the official "3D Kinematic character" demo

Steps to reproduce

  1. Build and install the VSIX version of the extension (the e2f2dc4 commit, I used the npm run package way to build it)
  2. Apply the required settings (Godot editor path, etc.)
  3. Get the official 3d platformer demo
  4. Open the project in Godot 4.2.1, locate and load the cubio.gd into the VSCode
  5. Format the file (Alt-Shift-F, or just hit "Save", if format on save VSCode option is enabled)
  6. See the redundant spacing at the line 27 in the -cam_basis.get_euler().x expression
DaelonSuzuka commented 8 months ago

Yeah this is a difficult case to detect with the parser I'm using. I'll add this to the test suite.

DaelonSuzuka commented 7 months ago

Good news, this was already being parsed correctly! It was just missing a rule to control the spacing, which is comparatively much easier.

Thanks for catching and reporting this!