vscode: breaking: codeActionsOnSave

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.83.0
  • OS Version: *

Steps to Reproduce:

With version 1.83.0, codeActionsOnSave accepts only an object. Unfortunately for my use case is deal-breaker because I would like to apply format and sorting before the lint. With the object configuration, it is not possible anymore.

This is my actual configuration:

"editor.codeActionsOnSave": {
    "editor.formatOnSave": "always",
    "source.organizeImports": "always",
    "source.sortImports": "always",
    "source.fixAll": "always"
  }

There is an old issue that describes my exact same case: https://github.com/microsoft/vscode/issues/88131.

Do you have any workaround to achieve the same result, or can you please consider rolling back the array configuration?

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 26
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

verified on latest insiders

Version: 1.84.0-insider (user setup) Commit: eb4f3c149f34d82b9763a08230907cf79e7fc103 Date: 2023-10-10T07:26:46.161Z Electron: 25.8.4 ElectronBuildId: 24154031 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Windows_NT x64 10.0.22621

roger. looking at it rn, and draft PR is mentioned here. will take a look at this again first thing in the morning.

Running into this issue as well, so it is very much appreciated @justschen that you are looking into this.

Specifically, we are using a combination of Prettier and ESLint for formatting and linting to enforce JS Standard Style, which depends on the order in which the actions are applied.

  "editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"],
  "editor.defaultFormatter": "esbenp.prettier-vscode",

Being able to format the document via Prettier and then applying ESLint fixes does not seem to be possible with the object notation right now.

With v1.83.0, when the array is used for codeActionsOnSave, one gets a Incorrect type. Expected "object". message in the settings.json file and no code actions are applied on save.

Candidate PR will just add back support for arrays for now! Under discussion atm if orderings from objects will be considered.

Error is coming from 153335b in saveParticipants (lines 283, where string[] was replaced)

Interesting case - when there are Code Actions in the array, even with the error (saying Incorrect type...), do code actions still run?

I tried rolling back to my previous conf: image

"editor.codeActionsOnSave": [
    "editor.formatOnSave",
    "source.organizeImports",
    "source.sortImports",
    "source.fixAll"
  ]

And unfortunately no actions are performed

image

Arrays for codeactionsonsave were what allowed the “Format Code Action”, rohit-gohri.format-code-action to work. This was important because the array determines the order which you can’t do with an object. This was broken with 1.83 change to object.

Hi @justschen, here is a repro. Consider this spec file: https://github.com/orchy-mfe/orchy-core/blob/main/packages/web-component/src/configuration-client/httpConfigurationClient.spec.ts

Here is the behaviour of vscode 1.82: https://github.com/microsoft/vscode/assets/6383527/dbbea965-3d57-4393-87b4-77eff17da0e0

While this is the behaviour of vscode 1.83, without any change in the configuration: https://github.com/microsoft/vscode/assets/6383527/6fd9ee90-3db2-4cf0-93d6-91df72ee297a

If I update the configuration to be an object, this is the final result: https://github.com/microsoft/vscode/assets/6383527/0090e1ed-6b7e-495d-ab4d-becc65ac1588

As you can see, at each save imports are flickering but never really fixed.

Or maybe when 153335b from @justschen added type and additionalProperties in lines 55-59 above these overrode the oneOf array at lines 41+ ?

This is possible. If I try with an array this is the result: image

And no actions are performed (with the array filled with the proper actions)