microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.44k stars 12.42k forks source link

Plugins - support a 'willSave' hook #15917

Open egamma opened 7 years ago

egamma commented 7 years ago

Background angelozerr/tslint-language-service#32.

The tslint language server extension should support an option to auto fix lint rules with a fixer before a file is saved. The plugin API should support a willSave method that a plugin can use to perform an operation like auto fixing before the document is saved. In addition there needs to be request that the TypeScript language client like VS Code can use to inform the TypeScript language server that the user is about to save a file.

RyanCavanaugh commented 7 years ago

I'd rather this was handled as part of a Format Document request. Modifying a file on save isn't really a user-apparent pattern.

egamma commented 7 years ago

@RyanCavanaugh doing this as part of the getFormattingEditsForDocument request makes good sense and it blends well with format on save support. However, what is missing, is that the request has a some context information whether it was triggered as part of a save or not. For the tslint example the user would not want auto fix on each format request but only on save.

Modifying a file on save isn't really a user-apparent pattern.

Support for 'format on save' or 'auto fix on save' are common and supported by many editors IDEs. The key is that this is done as a pre-save operation so that a file is not saved twice.

aleclarson commented 5 years ago

Can/should this be investigated soon?