godotengine / godot-vscode-plugin

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

Add a settings option to turn formatter on and off #580

Closed witnessmonolith closed 4 months ago

witnessmonolith commented 5 months ago

Godot version

4/irrelevant

VS Code version

irrelevant

Godot Tools VS Code extension version

2.0.0

System information

irrelevant

Problem statement

It would be nice to have an on/off option for the built-in code formatter, because, as of right now, it is still in development and would introduce problems and inconsistencies from time to time, and other parts of the extension shouldn't be affected by this.

My point is, disabling the formatter will unblock users who don't care as much for the code formatting, those, who are using alternatives such as Scony's solution, and those, who are willing to use and test some other functionality of the extension aside from the formatting.

I tried to play around the settings.json but to no luck:

{
    "editor.defaultFormatter": null,
    "[gdscript]": {
        "editor.defaultFormatter": null, // it's set to "geequlim.godot-tools" automatically somewhere?
    }
}

Also, didn't find the option to turn the formatter off (if it's already exists).

Proposed solution

To have something like

"godotTools.editor.enableFormatter": true,

available for the configuration.

DaelonSuzuka commented 4 months ago

Formatters in VSCode are only invoked when you request them, so I don't understand why this would be necessary. Do you have format-on-save enabled?

Maybe you could try:

{
    "[gdscript]": {
        "editor.formatOnSave": false
    }
}
microaeris commented 4 months ago

@DaelonSuzuka Thanks for the suggestion. I tried this:

    "editor.formatOnSave": true,
    "[gdscript]": {
        "editor.formatOnSave": false
    },

but doesn't work. Looks like "gdscript" isn't a known language identifier by VSCode.

Does the extension define the language identifier?

DaelonSuzuka commented 4 months ago

When are your files actually being formatted? Do you have editor.formatOnType enabled too (why would anybody want format-on-type?)? For troubleshooting purposes, what happens if you disable formatOnSave entirely>

Does the extension define the language identifier?

Yes, gdscript is the identifier for the GDScript language, as defined by this extension.

I have this block:

"[gdscript]": {
    "editor.defaultFormatter": "geequlim.godot-tools",
    "editor.insertSpaces": false
},

in my VSCode settings, so I'm pretty sure that's the correct syntax for per-language settings.

microaeris commented 4 months ago

Thank you! I figured out my issue. Tl;dr: my test was bad. and this does work:

    "editor.formatOnSave": true,
    "[gdscript]": {
        "editor.formatOnSave": false
    },

Thanks for your help!

DaelonSuzuka commented 4 months ago

Awesome, I'm glad that fixes it.