godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.54k stars 160 forks source link

Several formatter issues #671

Closed limbonaut closed 3 months ago

limbonaut commented 3 months ago

Godot version

4.2.2-stable

VS Code version

1.89.1

Godot Tools VS Code extension version

1ff626ba4797b3ca38a7d3c9c8f923056a65e9cd

System information

Manjaro Linux

Issue description

Note: Severity stated in parentheses, my own opinion. Some of these issues are probably connected or the same.

Issue: Comment header disappears (CRITICAL)

All comment lines before extends Node disappear on format. It's a common practice to include licensing info at the top of the file.

Issue: Two lines separation after extends X | class_name is not respected (TRIVIAL)

According to the style guide example, it's two blank lines after class doc. However, it's not mentioned in the guide's text anywhere, so feel free to ignore this.

Issue: Blank lines are removed between commented out functions (MAJOR)

@export var some_var: int = 0

# func some_static_1() -> void:
#   pass

# func some_static_2() -> void:
#   pass

↓↓↓↓↓

@export var some_var: int = 0
# func some_static_1() -> void:
#   pass
# func some_static_2() -> void:
#   pass

Issue: #endregion gets collapsed into function body (MINOR)

#region SomeRegion

func some_func():
    pass

#endregion

↓↓↓↓↓

#region SomeRegion

func some_func():
    pass
#endregion

Issue: Plus sign & whitespace strangeness (MINOR)

var pb = get_node("Node" + str(i+1))

↓↓↓↓↓

var pb = get_node("Node"+ str(i+1))

Issue: Spaces introduced into String.match() calls (MINOR)

s.match("some_expression")

↓↓↓↓↓

s. match ("some_expression")

Issue: Typed array arguments don't follow density rules (MINOR)

func _init(m: Array[int] = []) -> void:
↓↓↓
func _init(m: Array[int]=[]) -> void:

Issue: Blank lines removed in comment blocks inside a function (MINOR)

func commented_blocks():
    var a = 0

    # var b = 1
    # var c = 2

    var d = 3

↓↓↓↓↓

func commented_blocks():
    var a = 0
    # var b = 1
    # var c = 2

    var d = 3

Issue: Comment blocks at the end of file disappear on format (CRITICAL)

Comment lines at the EOF are progressively DELETED on format.

func some_func() -> void:
     pass

# func commented_func_1() -> void:
#     pass

↓↓↓↓↓

func some_func() -> void:
     pass

Steps to reproduce

GDScript test file: test_formatter_new.zip

DaelonSuzuka commented 3 months ago

Wow, my last change to the empty line deletion code caused a TON of problems. I might have to just revert it and not have context-sensitive behavior.

DaelonSuzuka commented 3 months ago

Every case mentioned here should be fixed in #672, except typed array args when dense==true.