godotengine / godot-vscode-plugin

Godot development tools for VSCode
MIT License
1.47k stars 148 forks source link

Provide style guidance for member ordering (and auto-fix) #667

Closed dabikuru closed 2 weeks ago

dabikuru commented 2 weeks ago

Godot version

4.2.2.stable

VS Code version

1.90.1

Godot Tools VS Code extension version

2.0.0

System information

MacOS

Problem statement

The GDScript style guide suggests a recommended ordering of member signals, variables, and methods.

I thought it would be really helpful if godot-tools provided an optional warning if the recommended ordering is not being followed, and offer to auto-fix if possible.

image

Proposed solution

I am not familiar with code formatting tools yet, so please forgive the high-level description!

For the auto-fix, I could imagine the following:

Note: to avoid unexpected behavior, within each category, the original order should be preserved. E.g.:

Calinou commented 2 weeks ago

Aside of the first four items (from @tool to docstring), reordering can change the code's behavior, so I doubt it's possible to do safely.

DaelonSuzuka commented 2 weeks ago

Calinou's right, this kind of thing is deceptively difficult to execute at an acceptable level of safety and reliability.

I also don't think top-level code organization is an appropriate target for auto-formatters. I'm familiar with clang-format, prettier, biomejs, black, ruff and others, and I'm not aware of one that will actually reorder sections of your files.

We appreciate the interest and your effort in describing a possible solution, but this feature doesn't really align with the extension's goals or available resources.

dabikuru commented 2 weeks ago

Thank you for the explanation, I see how auto-fix cannot easily be done safely.

Would it still make sense to at least provide a warning where the recommended ordering is not being followed? This could be an optional setting.

DaelonSuzuka commented 2 weeks ago

No, because merely detecting this situation requires almost as much work as generating the quick fix suggestions, eg correctly parsing all of GDScript and sorting every available language construct into the various categories from the "recommended ordering".

dabikuru commented 2 weeks ago

Understood, thank you!