Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code actions such as format on save are not triggered when closing the file and Auto Save enabled #177787

Closed
ullumullu opened this issue Mar 21, 2023 · 4 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@ullumullu
Copy link

ullumullu commented Mar 21, 2023

Type: Bug

  1. Enable AutoSave via File > Auto Save
  2. Define a code action on save (in your settings.json) such as:
    "editor.formatOnSave": true
    or
    "editor.codeActionsOnSave": [
     "source.organizeImports",
     "source.fixAll"
    ]
    
  3. Modify a file and close it
  4. Code actions are not triggered
  5. Explicitly triggering a save via cmd+s triggers the code actions

For reference - the problem was discovered while working on a TypeScript project using the native language server organise imports functionality.

Expected behaviour

I'd expect that code actions on save would also get triggered when auto save is enabled (or at least when the file gets closed).

VS Code version: Code 1.75.0 (Universal) (e2816fe, 2023-02-01T15:24:42.903Z)
OS version: Darwin x64 22.3.0
Modes:
Sandboxed: No

System Info
Item Value
CPUs Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (16 x 2300)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 3, 4, 4
Memory (System) 32.00GB (0.72GB free)
Process Argv
Screen Reader no
VM 0%
Extensions: none
@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.76.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Mar 21, 2023
@mjbvz
Copy link
Collaborator

mjbvz commented Mar 21, 2023

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

@ullumullu
Copy link
Author

ullumullu commented Mar 22, 2023

@mjbvz yes I can also reproduce this with the insiders build

Version: 1.77.0-insider (Universal)
Commit: b8e4c550bc87aa1db64e612706ac5238035e9cc2
Date: 2023-03-22T05:24:06.369Z (2 hrs ago)
Electron: 19.1.11
Chromium: 102.0.5005.196
Node.js: 16.14.2
V8: 10.2.154.26-electron.0
OS: Darwin x64 22.3.0
Sandboxed: Yes

The only "adjustment" needed is to configure code actions (configuring one of them would already be enough):

settings.json

{
    "[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": [
            "source.organizeImports",
            "source.fixAll"
        ]
    },
    "files.autoSave": "afterDelay"
}

If I now add an unused import to a file while auto-save is enabled it is not getting removed without explicitly triggering a save. Even closing the file is not triggering the code actions.

Another finding I had in the meantime while playing around with the auto-save settings: I can scope down the issue when files.autoSave is set to "afterDelay". The other two options "onFocusChange" and "onWindowChange" correctly trigger the code actions.

Side note: adjusting files.autoSaveDelay seems to have no effect on the issue.

@mjbvz
Copy link
Collaborator

mjbvz commented Mar 29, 2023

Duplicate of #163920

Currently we only enable these actions on manual saves

@mjbvz mjbvz closed this as completed Mar 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants