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

codeActionOnSave doesn't work on save on focus lost #163920

Closed
copdips opened this issue Oct 18, 2022 · 5 comments
Closed

codeActionOnSave doesn't work on save on focus lost #163920

copdips opened this issue Oct 18, 2022 · 5 comments
Assignees
Labels
editor-code-actions Editor inplace actions (Ctrl + .) feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan

Comments

@copdips
Copy link

copdips commented Oct 18, 2022

Type: Bug

Behaviour

Expected vs. Actual

When I move my mouse from the active editor to another, the previous active editor will auto save the file and perform the codeActionsOnSave, which for my case, the isort, but it doesn't, it only saved the file as I can see that the white point besides the file name disappeared, and the file is not sorted.

While pressing manually Ctrl+S in the active editor does perform the code action well, only during auto-save when losting focus doesn't work.

Does VSCode have two kinds of OnSave ?

part of my settings:

  "isort.args": [
    "--profile",
    "black"
  ],
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    },
  },

Steps to reproduce:

  1. open two editor groups
  2. edit a file in the right group
  3. move mouse to the left group
  4. the file in the right group perform auto-save, till here, all OK, the white point besides the file name has gone, in git diff, it does show the saved changes
  5. the file in the right group should perform also editor.codeActionsOnSave within auto-save.

With Ctrl+S manually, all works.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.10
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


languageServer: "Pylance"

linting
• flake8Args: "<placeholder>"
• flake8Enabled: true
• banditArgs: "<placeholder>"
• banditEnabled: true
• mypyEnabled: true

formatting
• provider: "none"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true

VS Code version: Code 1.72.2 (d045a5e, 2022-10-12T22:15:18.074Z)
OS version: Windows_NT x64 10.0.19044
Modes:
Sandboxed: No
Remote OS version: Linux x64 5.10.102.1-microsoft-standard-WSL2

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz (8 x 3302)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
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) undefined
Memory (System) 15.79GB (1.03GB free)
Process Argv --crash-reporter-id bb220bc4-eaf8-40b8-a6e4-da196f80e1e5
Screen Reader no
VM 0%
Item Value
Remote WSL: Ubuntu2004
OS Linux x64 5.10.102.1-microsoft-standard-WSL2
CPUs 11th Gen Intel(R) Core(TM) i7-11370H @ 3.30GHz (8 x 3302)
Memory (System) 9.72GB (5.69GB free)
VM 0%
Extensions (211)
Extension Author (truncated) Version
better-comments aar 3.0.2
project-manager ale 12.7.0
spellright ban 3.0.90
python-manifest-template ben 1.0.1
docs-view bie 0.0.11
mermaid-markdown-syntax-highlighting bpr 1.4.2
codeswing cod 0.0.21
flask-snippets Cod 1.1.0
flask-snippets cst 0.1.3
azure-devops-snippets dam 1.0.6
LogFileHighlighter emi 2.16.0
pythonsnippets frh 1.0.2
remotehub Git 0.44.0
vscode-drawio hed 1.6.4
output-colorizer IBM 0.1.2
better-dockerfile-syntax jef 1.0.2
vscode-peacock joh 4.2.2
thinking-in-code los 0.0.11
github-linker man 0.0.11
dotenv mik 1.0.1
vscode-azurevirtualmachines ms- 0.6.2
python ms- 2022.16.1
jupyter-keymap ms- 1.0.0
remote-containers ms- 0.255.4
remote-ssh ms- 0.90.1
remote-ssh-edit ms- 0.84.0
remote-wsl ms- 0.72.0
vscode-remote-extensionpack ms- 0.21.0
azure-repos ms- 0.20.0
remote-repositories ms- 0.22.0
shellman Rem 5.6.0
scala sca 0.5.6
rewrap stk 1.16.3
errorlens use 3.6.0
gistfs vsl 0.4.1
vscode-todo-highlight way 1.0.5
jinja who 0.0.8
vscode-openapi 42C 4.14.1
vscode-base64 ada 0.1.0
arepl alm 2.0.3
vscode-pull-request-azdo ank 0.0.25
swagger-viewer Arj 3.1.2
vsc-export asl 1.2.0
armview ben 0.4.6
markdown-checkbox bie 0.3.3
markdown-mermaid bie 1.15.2
markdown-preview-github-styles bie 1.0.1
mermaid-markdown-syntax-highlighting bpr 1.4.2
vscode-importmagic bra 0.2.5
better-toml bun 0.3.2
path-intellisense chr 2.8.1
regex chr 0.4.0
vscode-postgres cko 1.4.0
codeswing cod 0.0.21
gitignore cod 0.9.0
vscode-github-actions csc 0.24.2
excel-to-markdown-table csh 1.3.0
screenshot-clipboard Dar 1.0.0
vscode-markdownlint Dav 0.48.1
vscode-quick-select dba 0.2.9
k8s-snippets dog 0.4.2
githistory don 0.6.19
gitlens eam 13.0.2
prettier-vscode esb 9.9.0
git-project-manager fel 1.8.2
code-runner for 0.11.8
docker-explorer for 0.1.7
shell-format fox 7.2.2
seito-openfile Fr4 1.8.9
github-linker gim 0.2.5
vscode-pull-request-github Git 0.50.0
gc-excelviewer Gra 4.2.56
todo-tree Gru 0.0.219
terraform has 2.24.3
vscode-test-explorer hbe 2.21.1
vscode-drawio hed 1.6.4
yaml-plus-json hil 1.11.0
rest-client hum 0.25.1
gzipdecompressor Hyu 1.2.0
format-python-docstrings ian 1.2.1
vscode-edit-csv jan 0.7.2
vscode-kafka jep 0.15.0
nbpreviewer jit 1.2.2
vscode-insertdatestring jsy 2.3.1
vscode-codemetrics kis 1.24.0
kite kit 0.147.0
snowflake-driver-for-sqltools kos 0.4.2
pasteurl kuk 0.5.4
vscode-leetcode Lee 0.18.1
restructuredtext lex 189.2.0
restructuredtext-pack lex 1.0.1
vscode-python-test-adapter lit 0.7.1
thinking-in-code los 0.0.11
wikilens los 0.0.5
bash-ide-vscode mad 1.14.0
csvtomarkdown mar 0.0.1
code-coverage mar 1.8.6
rainbow-csv mec 3.2.0
azure-work-management Mel 1.0.8
git-graph mhu 1.30.0
vscode-github-blamer mih 1.0.0
file-downloader min 1.0.12
mindaro min 1.0.120220915
vscode-exec-node mir 0.5.4
ecdc mit 1.8.0
azure-pipelines ms- 1.208.0
azure-dev ms- 0.3.0
vscode-apimanagement ms- 1.0.5
vscode-azureappservice ms- 0.24.4
vscode-azurefunctions ms- 1.8.1
vscode-azurelogicapps ms- 1.0.40
vscode-azureresourcegroups ms- 0.5.6
vscode-azurestaticwebapps ms- 0.11.3
vscode-azurestorage ms- 0.15.0
vscode-azureterraform ms- 0.3.2
vscode-azurevirtualmachines ms- 0.6.2
vscode-bicep ms- 0.11.1
vscode-cosmosdb ms- 0.19.2
vscode-docker ms- 1.22.1
vscode-logicapps ms- 1.1.14
vscode-dotnet-runtime ms- 1.5.0
kind-vscode ms- 0.0.3
vscode-aks-tools ms- 1.3.4
vscode-kubernetes-tools ms- 1.3.10
data-workspace-vscode ms- 0.3.0
mssql ms- 1.16.0
sql-database-projects-vscode ms- 0.19.0
black-formatter ms- 2022.4.0
isort ms- 2022.2.0
python ms- 2022.16.1
vscode-pylance ms- 2022.10.20
jupyter ms- 2022.9.1202862440
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.10
vscode-jupyter-cell-tags ms- 0.1.6
vscode-jupyter-slideshow ms- 0.1.5
azure-account ms- 0.11.2
azurecli ms- 0.5.0
live-server ms- 0.4.3
makefile-tools ms- 0.6.0
powershell ms- 2022.8.5
test-adapter-converter ms- 0.1.6
vscode-node-azure-pack ms- 1.1.0
azurerm-vscode-tools msa 0.15.8
sqltools mtx 0.25.1
sqltools-driver-mssql mtx 0.3.0
sqltools-driver-pg mtx 0.3.0
sqltools-driver-sqlite mtx 0.4.0
vscode-paste-image mus 1.0.4
color-highlight nau 2.5.0
gremlins nho 0.26.0
vscode-pylens nin 0.1.6
autodocstring njp 0.6.1
vscode-python-typehint njq 1.4.1
docker-compose p1c 0.3.5
databricks-vscode pai 1.1.4
vscode-versionlens pfl 1.0.10
vscode-json-enhanced qua 1.1.2
quicktype qui 12.0.46
vscode-data-table Ran 1.12.0
vscode-thunder-client ran 1.20.0
fabric8-analytics red 0.3.6
java red 1.11.0
vscode-commons red 0.0.6
vscode-xml red 0.21.0
vscode-yaml red 1.10.1
elastic ria 0.13.3
vscode-sort-json ric 1.20.0
bash-debug rog 0.3.9
vscode-paste-and-indent Rub 0.0.8
vscode-coverage-gutters rya 2.10.2
partial-diff ryu 1.4.3
text-marker ryu 1.11.0
jinjahtml sam 0.19.0
kubernetes-file-system-explorer san 1.0.28
scala sca 0.5.6
metals sca 1.20.0
kubernetesapply Sha 1.4.1
trailing-spaces sha 0.4.1
markdown-preview-enhanced shd 0.6.3
vscode-table-formatter shu 1.2.1
vscode-fileutils sle 3.5.0
vscode-zipexplorer sle 0.3.1
sonarlint-vscode Son 3.11.0
sourcery sou 0.12.11
code-spell-checker str 2.10.1
markdowntable Tak 0.10.2
even-better-toml tam 0.18.1
vscode-markdown-paste-image tel 0.19.1
html-preview-vscode tht 0.2.5
shellcheck tim 0.23.1
vscode-mermaid-editor tom 0.15.0
simple-rst tro 1.5.2
json2yaml tux 0.2.0
sort-lines Tyr 1.9.1
usql-vscode-ext usq 0.2.15
intellicode-api-usage-examples Vis 0.2.5
vscodeintellicode Vis 1.2.28
vscode-java-debug vsc 0.45.0
vscode-java-dependency vsc 0.21.0
vscode-java-pack vsc 0.25.3
vscode-java-test vsc 0.37.1
vscode-maven vsc 0.39.0
gistfs vsl 0.4.1
vscode-mermaid-preview vst 1.6.3
gitblame wad 9.0.1
change-case wma 1.0.0
vscode-jumpy wma 0.3.1
vscode-behave-test-adapter You 0.0.2
markdown-all-in-one yzh 3.4.3
markdown-editor zaa 0.1.10
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
i497e931:30553904
vsccc:30566497
pyindex848:30577860
nodejswelcome1:30587005
40g7c324:30573242

@onemen
Copy link

onemen commented Oct 19, 2022

I dont know if this related, but today I see command 'organizeImports' not found on every save

My settings:

...
  "editor.codeActionsOnSave": {
    "source.organizeImports": true,
    "source.fixAll": true
  },
...

VS Code Insider:

Version: 1.73.0-insider (user setup)
Commit: 7ea2788a43a4c35d8da63a419725ba2485de395b
Date: 2022-10-19T05:28:16.879Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.22621
Sandboxed: Yes

@tanhakabir

This comment was marked as spam.

@mjbvz mjbvz added feature-request Request for new features or functionality editor-code-actions Editor inplace actions (Ctrl + .) labels Dec 5, 2022
@vscodenpa vscodenpa added this to the Backlog Candidates milestone Dec 5, 2022
@vscodenpa
Copy link

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@vscodenpa
Copy link

🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@justschen
Copy link
Contributor

Code Actions' behavior on save in the editor has been modified from Booleans to an enum with the following options:

always: Code Actions with always be run on any kind of save (autosave when exiting or changing focus, explicit save, etc).
explicit: Code Actions will be run only when explicitly saving.
never: Code Actions will never be run on save.

The Booleans for true and false are still supported as well (true -> explicit, false -> never), but make sure to swtich to the enum to run actions on auto save.

This can be enabled with the following setting:

"editor.codeActionsOnSave": {
        "source.organizeImports": "explicit"
    }

or can be found in Settings:
Screenshot 2023-09-15 at 9 34 26 AM

Notebook Code Actions on Save behavior will also be updated soon (cc @Yoyokrazy )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-code-actions Editor inplace actions (Ctrl + .) feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan
Projects
None yet
Development

No branches or pull requests

6 participants