Skip to content

Option to set project root for auto-import suggestions when workspace is opened at subfolder level #7524

Description

@roberfi

When working with a Python project where I have the workspace root set to a subfolder, VS Code's Python extension doesn't correctly handle auto-import suggestions for modules that should be imported relative to the actual project root and I don't see any way to configure it properly.

Project Structure

project/
├── foo/           # <- Workspace root (opened folder)
│   ├── .vscode/
│   │   └── settings.json
│   ├── __init__.py
│   ├── bar.py
│   └── baz.py
├── other_modules/
└── __init__.py

Expected Behavior

Auto-import should suggest imports like:

from foo.bar import function

Actual Behavior

Auto-import suggests imports like:

from bar import function  # Missing 'foo.' prefix

Settings Attempted

{
    "python.analysis.extraPaths": ["${workspaceFolder}/.."],
    "python.analysis.autoSearchPaths": true,
    "python.analysis.include": ["${workspaceFolder}/.."],
    "python.defaultInterpreterPath": "../.venv/bin/python"
}

Use Case

This is common in large projects where developers work primarily in sub-directories but need proper import resolution relative to the project root. Opening the parent directory as workspace root significantly impacts performance in large codebases.

Environment
VS Code version: 1.103.1
Python extension version: 2025.12.0
OS: Ubuntu 24.04

Metadata

Metadata

Assignees

Labels

ai-triage-respondedIndicate whether the AI triage agent has responded to this issue.enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions