简体   繁体   中英

Visual Studio Code is not suggesting relative imports

For some reason, if I have a variable inside my project, Vscode stopped suggesting imports when i press Ctrl + Space .

For example, I have a class in types.py :

class StepStatus(ExtendedEnum):
    RUNNING = "RUNNING"
    ERROR = "ERROR"
    OK = "OK"

At the same level, another file called runner.py , but if try to auto import this variable it raises no suggestions : 在此处输入图像描述

But if I manually import the StepStatus variable it exists:

在此处输入图像描述

There is my vscode settings.json content:

{
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        },
    },
    "isort.args": [
        "--profile",
        "black"
    ],
    "python.analysis.extraPaths": [
        "${workspaceFolder}"
    ],
    "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "Material Theme High Contrast",
    "window.zoomLevel": 1,
    "terminal.integrated.inheritEnv": false
}

I already tried to reinstall Vscode, reinstall Pylance extension, delete cache but nothing works. The auto import suggestions only works for the default libraries such as json, typing, datetime...

If there is no StepStatus class in your script, how does IntelliSense prompt?

So I guess you have the following code under your types.py script

class StepStatus(Enum):
    EMPTY = "empty"
    PARTLY_OK = "partly_ok"
    OK = "ok"
    ERROR = "error"

Then intellisense will be provided when you type StepStatus in the runner.py script in the same directory:

在此处输入图像描述

Enter or select, it will be imported automatically

在此处输入图像描述

Type . and smart suggestions also work

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM