question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`codeActionsOnSave` `"source.fixAll"` removes used imports

See original GitHub issue

Type: Bug

Having "source.fixAll" in my "editor.codeActionsOnSave" frequently deletes used (not unused) imports on save, especially if they’re unsorted. I haven’t found a reliable way to reproduce this yet. But if I remove "source.fixAll" from code actions, all is well.

// settings.json
"[python]": {
  "editor.codeActionsOnSave": [
    "source.fixAll",
    "source.organizeImports",
  ],
},

Extension version: 2022.12.0 VS Code version: Code 1.70.1 (6d9b74a70ca9c7733b29f0456fd8195364076dda, 2022-08-10T06:08:46.959Z) OS version: Darwin arm64 21.6.0 Modes: Remote OS version: Linux x64 3.10.0-1160.71.1.el7.x86_64

System Info
Item Value
CPUs Apple M1 Pro (10 x 24)
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
webgl: enabled
webgl2: enabled
Load (avg) 5, 5, 5
Memory (System) 16.00GB (0.08GB free)
Process Argv pmg --crash-reporter-id c13bf5eb-cd11-4709-908c-c293aee75f36
Screen Reader no
VM 0%
Item Value
Remote SSH: csd3
OS Linux x64 3.10.0-1160.71.1.el7.x86_64
CPUs Intel® Xeon® Gold 6142 CPU @ 2.60GHz (64 x 2600)
Memory (System) 187.36GB (161.14GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
wslgetstarted:30449410
cppdebug:30492333
pylanb8912cf:30529770
vsclangdc:30486549
c4g48928:30535728
hb751961:30543456
dsvsc012:30540252

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
karthiknadigcommented, Aug 13, 2022

That will likely be the way we ship various tool support in the extension. The reason we are doing this is to allow easier external tool support. Also, shipping these tools as separate extension allows us to bundle them (so no need to install), provide deeper integration with the tools. For example, in the isort extension, we do a --check run on all open files and report improper sort as error, the extension also provides a quick fix for such errors. Such integration is not easy in the core python extension, and requires Typescript knowledge, but in the isort extension all of that is achieved purely in python code.

We have extensions for black and pylint. we are currently working on flake8 and autopep8 for this milestone. We also have a template that allows you to build and ship your own tools as extension on your own.

Here is more context from Brett on why we are going this way: https://twitter.com/brettsky/status/1555632119312879616

0reactions
janoshcommented, Aug 25, 2022

@ericmeadows Of course you can disable it. Just remove "source.fixAll" from your "editor.codeActionsOnSave".

But I have to agree, in further testing it has been quite janky, occasionally deleting lines of code during formatting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to turn off automatic deletion of unused imports in VS ...
json (User and Workspace) for the following settings, delete this configuration or change it to false . "editor.codeActionsOnSave": { "source.
Read more >
Easily sort imports and remove unused declarations on each ...
All this time I was using VSCode formatting on save which triggers the selected default formatter (Prettier).
Read more >
JavaScript Programming with Visual Studio Code
codeActionsOnSave to an array of Code Actions to execute in order. Here are some source actions: "organizeImports" - Enables organize imports on save....
Read more >
How To Enable Linting on Save with Visual Studio Code and ...
In this tutorial, you will install ESLint, construct rules, and enable codeActionsOnSave in Visual Studio Code.
Read more >
Python in Visual Studio Code – August 2022 Release
Pylance now offers a code action for removing all unused imports when there is more than one library that is being imported but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found