27

Visual Studio Code is never able to populate the 'Quick Fix' contextual drop down, only displaying 'No Code Actions Available'

Python extension is installed, along with python3.7.3 and flake8, pep8.

Christopher Mauney
  • 459
  • 1
  • 5
  • 10

6 Answers6

16

The Python extension for VS Code currently doesn't offer any quick fixes.

Brett Cannon
  • 14,438
  • 3
  • 45
  • 40
  • Is it..?? It's a disappointment. I am transitioning from atom to VS code... I am missing this feature – Bhanu Tez Jun 15 '19 at 23:26
  • @BhanuTez you will need to be more specific about what quick fixes you're after. And when you know which one(s) you specifically want, please either upvote a preexisting issue or open a new one at https://github.com/microsoft/vscode-python. – Brett Cannon Jun 18 '19 at 00:05
  • In Atom we have "beautify" extension that is supporting almost all languages. When I want to beautify my python. I can simply press ctrl+Alt+B this will beautify my python code(basically any code) according to pep8(even flake8 as well). This feature is missing in vs code. – Bhanu Tez Jun 18 '19 at 00:28
  • @BhanuTez actually the Python extension has that via [formatter support](https://code.visualstudio.com/docs/python/editing#_formatting). – Brett Cannon Jun 18 '19 at 23:13
  • How to disable Peek Problem in VS Code? – Galapagos Oct 29 '19 at 20:15
4

Solution for 2021.

I got the same issue with Python for VSCode 1.54.2.

I solved it by installing the Pylance extension and making it the default Python language server (a message should pop up just after the installation asking if you want to make it the default Python language server). Now everything works flawlessly.

albertgumi
  • 322
  • 1
  • 4
  • 13
  • 2
    As helpful as it is, this answer needs extra elaboration. For one, does it have unintended side effects to people accustomed with the usual Python extension? Anything else people would need to expect other than "working flawlessly"? – Nuclear03020704 Apr 23 '21 at 06:07
  • Unfortunately, Pylance does not work with VS Codium (="Visual Studio without tracking"). Also see https://github.com/microsoft/pylance-release/issues/791 – Stefan Feb 15 '23 at 15:04
  • this worked for me, though i had to go into settings and change the default Python language server manually. – dimani128 Aug 27 '23 at 00:55
3

Python extension started to support Quick Fix. First, function adding imports is supported.

Python in Visual Studio Code – November 2019 Release | Python

However

Python extension ver.2020.1.58038 and 2020.1.57204 have bug that it doesn't display Quick Fix.

Solution

Plan A: Use old version of Python extension

1.

If you haven't install Python extension, install it once.

2.

Install ver.2019.11.50794 or 2019.11.49689 by following steps in below answer.

vs code - rollback extension/install specific extension version - Stack Overflow

Plan B: Use Insiders version of Python extension

1.

Install Visual Studio Code - Insiders.

Download Visual Studio Code Insiders

2.

Install Python extension once, then click [Reload Required] button.

3.

Open Settings editor. (Ctrl + ,)

4.

Search by keyword: "Insiders Channel", then change pulldown to "daily" or "weekly", and save Settings. Then, Visual Studio Code start to download Insider version of Python extension. (Below status bar displays progress)

5.

When popup message "Please reload Visual Studio Code to use the insiders build of the Python extension." is displayed, click [Reload] button.

Requirement

Don't forget that there are two requirement to use Quick Fix feature.

  • Use Microsoft Python Language Server
  • Enable linting

Use Microsoft Python Language Server

Set python.jediEnabled to false in your settings.json file.

Enable linting

1.

Open Command Palette. (View > Command Palette... or F1 or Ctrl + Shift + P)

2.

Run "Python: Enable Linting" command.

3.

Select "On" in the drop-down menu.

cf. Editing Python Code in Visual Studio Code

Yukihiko Shinoda
  • 805
  • 2
  • 8
  • 21
1

I also recently tried the Sourcery VSCode Python Refactoring Extension to provide more refactorings that helps eliminate the errors in some cases implementing the line in question more clearly.

Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71
0

Having spent ages reading many articles on this, I've slightly improved my position. The right mouse button never comes up with anything, but I can press Ctrl + a full stop (period if you're in the US) to bring up suggested imports - sometimes.

I have Pylance installed in VS Code (so do you probably), which should be the default linter, but just in case I forced this in VS Code Settings:

// Defines type of the language server (should default to Pylance if installed anyway)
    "python.languageServer": "Pylance",
    

The comments are mine. But then I read the notes on PyLance, and it seems you have to enable this setting by adding these lines:

 // Offer auto-import completions.
    "python.analysis.autoImportCompletions": true,

Having said all of this, the feature has now stopped working again! I've left this in just in case a) it gives anyone any ideas or b) I get it working again and can come back to edit this answer.

Andy Brown
  • 5,309
  • 4
  • 34
  • 39
0

For import quick fixes, there is a solution.

Use the following VsCode Extension which work just as expected.

https://marketplace.visualstudio.com/items?itemName=Bar.python-import-helper

Greg7000
  • 297
  • 3
  • 15