Sublime Forum

Typescript plugin format on save doesn't work correctly on files opened after load

#1

Hey, this issue is annoying for me, I have to frequently close and reopen Sublime to get the proper formatting, so I posted the full issue on the plugin repo: https://github.com/microsoft/TypeScript-Sublime-Plugin/issues/779

and maybe here there could be ideas for a workaround, I’ve been reading and maybe using AutomaticPluginReloader could help with a shortcut I can press or even better an automatic action to reload the Typescript plugin when I open new files

0 Likes

#2

Not a solution that you requested, but you can use this TS plugin https://github.com/sublimelsp/LSP-typescript
It doesn’t have annoyning bugs and works more smoothly. Just customize it as i described here
https://github.com/microsoft/TypeScript-Sublime-Plugin/issues/775#issuecomment-889771119

Also this statement looks strange for me “I have to frequently close and reopen Sublime to get the proper formatting”. Why you need to open/close sublime for formatting? I am using prettier, bind it to sublime hotkey and able to format file just by pressing hotkey. No need to close sublime.

1 Like

#3

Thanks, great answer, that’s probably what I need if I can figure how to make it format on save with some customized settings

I’ve configured my Preferences: LSP-typescript Settings like this:

// Settings in here override those in "LSP-typescript/LSP-typescript.sublime-settings"

{
  "settings": {
    "insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
    "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
  }
}

but this code

const f2 = function() {

}

gets formatted like that, there should a space between function and () instead

Would you happen to have an idea on this? (I asked it here btw https://github.com/sublimelsp/LSP-typescript/issues/82)

edit: What I meant by closing and opening ST to make it work, is that if a file is already opened in ST at loading time, formatting works, if a file is opened then saved, formatting doesn’t work with the customization (space after anonymius function)

0 Likes

#4

Ok LSP-typescript now support formatting settings, it’s perfect, thanks again

1 Like