sublimelsp / LSP-typescript

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

Auto format the code with Single Quotes #111

Closed zhandosweb closed 2 years ago

zhandosweb commented 2 years ago

Hello!

I'm first time installing LSP and LSP server language packages for Sublime Text, and very happy with those packages. I try to move from VS Code to Sublime, and try to get same experience.

I have 2 questions, that I faced now, can I ask my questions here, please?

  1. Can I force to use Single Quotes in my javascript files, when I save the edited .js files? I mean auto-format the saved files and replace double "" quotes with single ''.

  2. Is LSP-Typescript plugin able to remove empty spaces within my .js file? It's also about auto formatting the code after saving edited files.

In VS Code I'm using Prettier plugin, and Prettier auto formatting all those things above automatically (removing empty spaces, replacing double quotes to single, etc). And maybe I should use other extra plugin to formatting my .js files, but better, if it can be fixed with LSP plugins.

Sorry for my bad English, I believe you understand me. And thank you for all LSP team, amazing plugins giving me pleasure experience for coding.

rchl commented 2 years ago

This package is not concerned with linting but the https://github.com/sublimelsp/LSP-eslint can be used to fix spaces and quotes when configured properly.

zhandosweb commented 2 years ago

This package is not concerned with linting but the https://github.com/sublimelsp/LSP-eslint can be used to fix spaces and quotes when configured properly.

Sorry, can you tell me. Does LSP-typescript package support formatting .js files? Or only linting javascript code? I'm a little bit confused.

Because, when I saved my files, code will format automatically, and that's because of package LSP-typescript, right? Or this function is built in Sublime Text 4? Sorry for noob questions.

rchl commented 2 years ago

It's not really about linting but about type-checking.

It does provide some basic formatting abilities but nothing that you can rely on to fix your code to be consistent. For that you should configure eslint and use LSP-eslint. Or prettier (personally not a fan).

Formatting is not built-in into ST so it's either coming from this package (if you've enabled it) or some other package. Depends what kind of changes are being done.

zhandosweb commented 2 years ago

Thank you so much for the answers! Please, sir, let me ask the last question.

I see there is a command LSP: Format File. And LSP packages may format the files, but you said there are only basic features for formatting.

If I install another plugin for formatting (LSP-eslint or prettier), these plugins can go along together? Or I should disable auto-formatting first (I'm using now 2 plugins: LSP-html and LSP-typescript), and then configure another plugin for formatting? I'm just afraid about conflicts if there will work several plugins in same time for formatting a same file.

rchl commented 2 years ago

LSP-typescript barely does any formatting so I don't think it would conflict.

LSP-eslint applies the changes through Code Actions (refer to its readme) so it doesn't need formatting to be enabled. And if there are conflicts then you can disable LSP formatting on save.