sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin
MIT License
135 stars 11 forks source link

Disable default formatting #118

Closed ganigeorgiev closed 2 years ago

ganigeorgiev commented 2 years ago

This is similar to #53.

The default lsp-typescript formatting that is applied after save is conflicting with our internal guidelines and I can't find a way to disable it (ST4 with the latest LSP and LSP-typescript plugins).

lsp_format_on_save doesn't seems to be working on per client bases. I've tried setting the following in LSP-typescript.sublime-settings but it doesn't override the lsp_format_on_save value from LSP.sublime-settings:

"settings": {
    "lsp_format_on_save": false
}

_I've also tried "typescript.format.enable": false (this is what is used in VSCode) but without success._

Is there a way to disable the auto format for the typescript lsp server only? The lsp_format_on_save doc comment indicates that it should be possible, as far as I understand, but it seems that I'm not setting it properly:

  // Run the server's formatProvider (if supported) on a file before saving.
  // This option is also supported in syntax-specific settings and/or in the
  // "settings" section of project files.
  "lsp_format_on_save": false,
ganigeorgiev commented 2 years ago

After a second read of the lsp_format_on_save comment, I've actually managed to disable it for typescript files by setting the option to false in the syntax-specific preferences TypeScript.sublime-setitngs.

This kinda works but it also prevents other lsp servers (eg. eslint) to run and I had to add a Ctrl+S binding to trigger the specific server formatter.

Is there any other way to disable only the lsp-typescript formatter?

rchl commented 2 years ago

The https://github.com/typescript-language-server/typescript-language-server server doesn't currently support disabling that functionality. It would have to be extended to support that feature first.

Depending on which servers you are using, you might be able to migrate from lsp_format_on_save to lsp_code_actions_on_save. It provides more flexibility. eslint server supports that at least.

ganigeorgiev commented 2 years ago

Thanks for the note about lsp_code_actions_on_save, I'll see if I can make use of it.

Based on this other issue - https://github.com/typescript-language-server/typescript-language-server/issues/257, I guess you are against adding the disable format option it in the language server (and to some extend I could understand your reasoning), so I'll close this one.

rchl commented 2 years ago

I forgot about it but I think you can also disable certain features by adding something like this in LSP-typescript preferences:

    "disabled_capabilities": {
        "documentFormattingProvider": true,
        "documentRangeFormattingProvider": true,
    },
ganigeorgiev commented 2 years ago

Ah, thanks this was exactly what I was looking for. Can confirm, the above successfully disables the typescript server formatting for me without any hacks.

airtonix commented 1 year ago

for myself, since i have lsp-eslint,

// LSP.sublime-settings
    "lsp_format_on_save": false,
    "lsp_code_actions_on_save": {
        "source.fixAll": true,
        "source.fixAll.eslint": true,
    },