sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable default formatting

ganigeorgiev opened this issue · comments

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,

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?

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.

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 - typescript-language-server/typescript-language-server#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.

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,
    },

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.

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,
	},