Vscode: Temporarily Set Configuration For Save Operation

Created on 25 Dec 2018  路  10Comments  路  Source: microsoft/vscode

I'm maintaining the EditorConfig extension and am in dire need of a feature that would eliminate some issues with respect to the following settings and potentially more in the future (e.g., end of line setting):

  • files.insertFinalNewline
  • files.trimFinalNewlines
  • files.trimTrailingWhitespace

Specifically, I need a way to short-circuit / override these settings temporarily for a file-save operation, because allowing vscode to perform any kind of trimming is destructive and either irreversible or extremely hacky to fix. It's like asking me to unpunch someone.

Basically, I need a way to change the way that vscode does a built-in save operation on a per-file basis (which is how EditorConfig works). Pre-save TextEdits are not good enough, because whatever I do before a save could potentially be wiped out with vscode's destructive trimming after the fact.

Another option, of course, would be to make EditorConfig a built-in feature of vscode, which I think makes all the sense in the world.

_Note: these issues only surfaced after vscode introduced these editor settings, because now we have 2 things trying to do the same thing._

Related issues

api feature-request

Most helpful comment

Looks like the VS Code project itself is now recommending the EditorConfig extension. Would be nice if it was prioritized adding/changing what's needed so it can be implemented fully and accurately.

All 10 comments

VS Code already has TextEditorOptions which holds similar settings to be overridden by an extension.

I guess it can be extended with tri-state properties (null - use config, true - run, ignoring config, false - don't run, ignoring config) that allow the extension to override whether these built-in pre save actions will be ran.

This will also allow the extension to reuse the built-in actions rather than reimplementing them in it's own code.

@bpasero any insights into the real solution would be appreciated, I was convinced this was a bug in VS Code itself until I confirmed --disable-extensions worked and searched for the culprit extension. Editor config is a very popular extension (even featured right now) and this bug is forcing me to uninstall.

Adding @jrieken to this thread who added the API for doing something pre-save.

Another option, of course, would be to make EditorConfig a built-in feature of vscode, which I think makes all the sense in the world.

Yes, probably a good idea at some point.

There's also this discussion happening on the extension repo: https://github.com/editorconfig/editorconfig-vscode/issues/208#issuecomment-451728131

I think this is the underlying cause of the issue https://github.com/Microsoft/vscode/issues/66214

@jedmao is this still relevant given https://github.com/Microsoft/vscode/issues/66214?

This issue is about not being able to override per TextEditor whether the pre-save operations run. Which is what the editorconfig extension needs in order to be implemented correctly. Otherwise if the pre-save operations are configured to run via the settings, they will run even if the editorconfig file says otherwise.

@Tyriar what you mentioned is a different issue.

@segevfiner is correct. This issue is absolutely still relevant.

Any updates on this guy?

Looks like the VS Code project itself is now recommending the EditorConfig extension. Would be nice if it was prioritized adding/changing what's needed so it can be implemented fully and accurately.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

philipgiuliani picture philipgiuliani  路  3Comments

villiv picture villiv  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments

chrisdias picture chrisdias  路  3Comments

ryan-wong picture ryan-wong  路  3Comments