Valip
Valip

Reputation: 4610

VSCode Intellisense shows wrong autocomplete modules

I have a few modules with the same structure and it seems that the VSCode Intellisense mixes them up.

This is a part of my project structure:

project
|-- daos
|   -- strategies
|      -- __init__.py
|      -- athena_strategy.py
|   -- __init__.py
|   -- db.py
|-- extractor
|   -- strategies
|      -- __init__.py
|      -- extractor_strategy.py
|   -- __init__.py
|   -- extractor.py

The problem is that the Intellisense is showing me the athena_strategy module instead of extractor_strategy when I'm trying to import strategies inside extractor.py: enter image description here

This is the settings.json file inside .vscode:

{
    "python.pythonPath": "/usr/bin/python3",
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.autoComplete.extraPaths": [
        "${workspaceFolder}/extractor",
        "${workspaceFolder}/daos",
        "${workspaceFolder}/ingester",
    ]
}

Is there any other configuration that I have to add in order to get the correct modules in imports?

Upvotes: 1

Views: 1117

Answers (1)

Jill Cheng
Jill Cheng

Reputation: 10344

When using python in VS Code, its "Intellisense" function is provided by the "python" extension and language service, and the "autocomplete" content displayed by different language services is different.

  1. When using "Jedi": ( "python.languageServer": "Jedi", in settings.json )

    enter image description here

  2. When using "Microsoft" or "Pylance":

    enter image description here

    It requires us to use "from extractor.strategies.", "autocomplete" will display what we need. Also, in order to make the code runnable, please add "import sys sys.path.append("./")" at the beginning of "extractor.py".

In addition, it is recommended that you use different file and folder names, and this good programming habit can avoid many problems.

Upvotes: 2

Related Questions