Skip to content

3.6. VS Code Workspace

What are VS Code Workspaces?

VS Code Workspaces are powerful configurations that allow you to manage and work on multiple projects within Visual Studio Code efficiently. A workspace can include one or more folders that are related to a particular project or task. Workspaces in VS Code enable you to save your project's settings, debug configurations, and extensions separately from your global VS Code settings, providing a customized and consistent development environment across your team.

Why should you use VS Code Workspace?

Using a VS Code Workspace offers several benefits:

  • Shared Settings: Workspaces allow you to define common settings across all developers working on the project, ensuring consistency in coding conventions and reducing setup time for new contributors.
  • Productivity: They enable developers to quickly switch contexts between different projects, each with its own tailored settings and preferences, thus enhancing productivity and focus.
  • Customization: Workspaces provide the flexibility to customize the development environment according to the specific needs of a project without affecting global settings, making it easier to work on projects with different requirements.

How should you create and open your VS Code Workspace?

To create and open a VS Code Workspace:

  1. Create a Workspace: Open VS Code and go to File > Save Workspace As... to save your current folder as a workspace. Provide a name for your workspace file, which will have a .code-workspace extension.
  2. Add Folders: You can add multiple project folders to your workspace by going to File > Add Folder to Workspace... This is useful for grouping related projects.
  3. Open a Workspace: To open an existing workspace, go to File > Open Workspace... and select the .code-workspace file you wish to open.

Which configurations can you pass to your workspace configuration?

VS Code Workspace configurations support the same settings as user settings but apply only within the context of the workspace. These configurations can be specified in the .code-workspace file, allowing you to customize various aspects of your development environment. For example:

{
    "folders": [
        {
            "path": "."
        }
    ],
    "settings": {
        "editor.formatOnSave": true,
        "python.defaultInterpreterPath": ".venv/bin/python",
        "python.testing.pytestEnabled": true,
        "python.testing.pytestArgs": [
            "tests"
        ],
        "[python]": {
            "editor.codeActionsOnSave": {
                "source.organizeImports": true
            },
            "editor.defaultFormatter": "charliermarsh.ruff",
        }
    },
    "extensions": {
        "recommendations": [
            "charliermarsh.ruff",
            "dchanco.vsc-invoke",
            "ms-python.mypy-type-checker",
            "ms-python.python",
            "ms-python.vscode-pylance",
            "redhat.vscode-yaml"
        ]
    }
}

This configuration example sets up a project with:

  • Folders: Defines the project folders included in the workspace.
  • Settings: Customizes editor behavior, such as format on save, default Python interpreter path, and testing configurations specific to Python.
  • Extensions: Recommends extensions beneficial for the project, promoting consistency across the development team.

By tailoring workspace settings, you ensure that every team member has a consistent development environment, which can include specific code formatting rules, linter settings, and extensions that are automatically recommended upon opening the workspace.

How can you configure your VS Code User Settings to become more productive?

This article from the MLOps Community: How to configure VS Code for AI, ML and MLOps development in Python 🛠️️ provide a in-depth guide for configuring VS Code environments. It starts by listing extensions that augments your programming environment. Then, the article shares some settings and keybindings that enhances your development experience. Finally, it provides some tips and tricks to boost your coding efficiency with VS Code.

VS Code Workspace additional resources