Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code quick-fix & python

Tags:

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.

like image 477
Christopher Mauney Avatar asked Apr 08 '19 21:04

Christopher Mauney


People also ask

What is Ctrl K in Vscode?

To launch the Define Keybinding widget, press Ctrl+K Ctrl+K. The widget listens for key presses and renders the serialized JSON representation in the text box and below it, the keys that VS Code has detected under your current keyboard layout.

What is Ctrl Shift P in Vscode?

You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.


2 Answers

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

like image 83
Brett Cannon Avatar answered Nov 11 '22 05:11

Brett Cannon


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

like image 24
Yukihiko Shinoda Avatar answered Nov 11 '22 05:11

Yukihiko Shinoda