godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.59k stars 169 forks source link

GDScript formatter sometimes adds spaces around minus sign #609

Open cwoongh opened 8 months ago

cwoongh commented 8 months ago

Godot version

4.2.1

VS Code version

1.86.2

Godot Tools VS Code extension version

2.0.0

System information

Linux

Issue description

I'm not sure of the exact conditions, but sometimes the formatter adds a space around the minus sign.

Steps to reproduce

Try formatting this code.

rotate_y(-event.relative.x * sensitivity)
camera.rotate_x(-event.relative.y * sensitivity)
camera.rotation.x = clampf(camera.rotation.x, -PI / 2, PI / 2)

It becomes:

rotate_y( - event.relative.x * sensitivity)
camera.rotate_x( - event.relative.y * sensitivity)
camera.rotation.x = clampf(camera.rotation.x, -PI / 2, PI / 2)

The -PI on the last line is fine, but -event.relative.x becomes - event.relative.x.

Calinou commented 8 months ago

Can you check if the PR build from https://github.com/godotengine/godot-vscode-plugin/pull/605 resolves this?

Install the VSIX within this ZIP archive from VS Code's command palette: https://nightly.link/godotengine/godot-vscode-plugin/actions/runs/8041615053/godot-tools.zip

DaelonSuzuka commented 8 months ago

605 doesn't fix this yet, but it's going to.

DaelonSuzuka commented 8 months ago

Now this issue should be fixed in #605.

image

vpyatnitskiy commented 8 months ago

There's still some wonky behavior around minus signs in the PR build, sadly. In the examples below first lines are the original code, second lines are the formatter output:

func foo(bar = -1, baz := -2 * Vector2.UP):
func foo(bar=- 1, baz:=- 2 * Vector2.UP):
var foo := -1
var foo := - 1
var foo := -2 * Vector2.UP
var foo := - 2 * Vector2.UP
if -foo > 0: pass
if - foo > 0: pass
var foo := 2 ** -10
var foo := 2 ** - 10

Plus, apparently, the unary plus suffers from the same issues?

var foo := +5
var foo := + 5
var foo := range(-5, +5)
var foo := range(-5, + 5)
DaelonSuzuka commented 8 months ago

Great list, thank you. That helps a lot.

rakkarage commented 7 months ago

const _path_scene := preload("res://Interface/Path.tscn") adds space after preload? const _path_scene := preload ("res://Interface/Path.tscn")


func _target_to(tile: Vector2i, turn := true) -> void: removes spaces around := when in func? func _target_to(tile: Vector2i, turn:=true) -> void:

func set_door(p: Vector2i, type = Random.next(Door.size())) -> void: removes spaces around = when in func? func set_door(p: Vector2i, type=Random.next(Door.size())) -> void:


mob.scale = Vector2i(-1, 1) forces spaces before and after -? mob.scale = Vector2i( - 1, 1)

var dx := -i - 1 in this case the unary - should have a space before but not after and the second - should have spaces on both sides i think? var dx := - i - 1


Thank you.

DaelonSuzuka commented 7 months ago

@rakkarage These have all been reported and I think all of them have been fixed, but the fix hasn't been released yet.

rakkarage commented 7 months ago

Thanks. Sorry I attempted test with Fix:605. Some were fixed but these were not. I will wait for next ver.

DaelonSuzuka commented 7 months ago

I definitely appreciate the report. I'll double check that your examples are all covered in the formatter test suite.