Skip to content

Various Formatter Improvements - #746

Merged
DaelonSuzuka merged 28 commits into
godotengine:masterfrom
DaelonSuzuka:formatter_improvements
Nov 18, 2024
Merged

Various Formatter Improvements#746
DaelonSuzuka merged 28 commits into
godotengine:masterfrom
DaelonSuzuka:formatter_improvements

Conversation

@DaelonSuzuka

@DaelonSuzuka DaelonSuzuka commented Nov 3, 2024

Copy link
Copy Markdown
Collaborator

This introduces a new syntax for defining snapshot tests, and fixes at least #717, #734, #728.

Snapshot tests can now be defined in a single file using "blocks":

# --- IN ---
var  a  =   10
# --- OUT ---
var a = 10

I also FINALLY found a solution to remove leading empty newlines from blocks:

# --- IN ---
func test():

	pass
# --- OUT ---
func test():
	pass

# --- IN ---
class Test:

	func _ready():

		pass
# --- OUT ---
class Test:
	func _ready():
		pass

@limbonaut

limbonaut commented Nov 3, 2024

Copy link
Copy Markdown

Breaks on lines in a multiline string:

func dump() -> String:
	return """
	{
		level_file: '%s',
		md5_hash: %s,
		text: '%s',
		level_size: %s,
		world_pos: %s,
		preview_size: %s,
		preview_pos: %s,
		preview_texture: %s,
		explorer_layer: %s,
		connections: %s,
	}
	""" % [level_file, md5_hash, text, level_size, world_pos, preview_size, preview_pos, preview_texture, explorer_layer, connections]

👇

func dump() -> String:
	return """
	{
		level_file: '%s',
		md5_hash:%s,
		text: '%s',
		level_size:%s,
		world_pos:%s,
		preview_size:%s,
		preview_pos:%s,
		preview_texture:%s,
		explorer_layer:%s,
		connections:%s,
	}
	""" % [level_file, md5_hash, text, level_size, world_pos, preview_size, preview_pos, preview_texture, explorer_layer, connections]

@DaelonSuzuka

DaelonSuzuka commented Nov 3, 2024

Copy link
Copy Markdown
Collaborator Author

Thanks @limbonaut! That one's fixed now.

@limbonaut

Copy link
Copy Markdown

An issue with quotes and unique name specifier:

@onready var main_menu: Button = %"Main Menu"

👇

@onready var main_menu: Button = % "Main Menu"

@limbonaut

Copy link
Copy Markdown

That's all I found. Nice to see the old issues fixed, and it's shaping up to be a really solid formatter.

@DaelonSuzuka
DaelonSuzuka merged commit f648c37 into godotengine:master Nov 18, 2024
{
"name": "constant.numeric.float.gdscript",
"match": "(?x)\n (?<! \\w)(?:\n (?:\n \\.[0-9](?: _?[0-9] )*\n |\n [0-9](?: _?[0-9] )* \\. [0-9](?: _?[0-9] )*\n |\n [0-9](?: _?[0-9] )* \\.\n ) (?: [eE][+-]?[0-9](?: _?[0-9] )* )?\n |\n [0-9](?: _?[0-9] )* (?: [eE][+-]?[0-9](?: _?[0-9] )* )\n )([jJ])?\\b\n",
"captures": { "1": { "name": "storage.type.imaginary.number.gdscript" } }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imaginary number with j suffix? Are complex numbers supported syntax in GDScript now?
Is there a source proposal/docs or something?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I copied it from MagicPython and didn't notice the j's! Thanks for the catch.

@AlfishSoftware AlfishSoftware Nov 18, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to double-check by testing whether it supports, e.g. lower and uppercase e, E and f, F suffix (I don't think there's a LF suffix, as its float is always a double). Also whether it supports _ separators and . cases like 0. or .5. Float literals syntax can vary a lot depending on the language, e.g. GDShader (or whatever it's going to be called) technically accepts even weird cases like 0.f IIRC.

@DaelonSuzuka
DaelonSuzuka deleted the formatter_improvements branch January 4, 2025 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants