user926721
user926721

Reputation:

Visual Studio Code and subfolder-specific settings

My workspace root is a git repository containing couple of files and several git submodules. Each submodule have their own .vscode/settings.json. I was expecting VSCode to adjust its settings based on which submodule/subfolder I'm working in but it's not working as expected.

Is it possible? I think it's possible if you use a multi-root workspace (which is supported since 1.18), but in my case I'd like to keep that single-root workspace.

Upvotes: 46

Views: 25162

Answers (3)

sivakumar nuka
sivakumar nuka

Reputation: 11

Try adding sub folder to workspace and change the tasks.json file File -> Add Folder to Workspace -> Select SubFolder

In the SubFolder tasks.json Modify your settings.

Upvotes: 1

Álvaro González
Álvaro González

Reputation: 146573

At the time of writing the feature is just not implemented. There's a feature request in the program's issue tracker filed on 17 August 2017: Monolithic structure, multiple project settings #32693.

Meanwhile, if you need it badly you have to abuse multi-root workspaces as described in Diogo's answer.

Upvotes: 12

Diogo
Diogo

Reputation: 1029

I also couldn't find a decent answer for this, I did find an "hacky" workaround. I have the following project structure:

.
├── apps
│   ├── api
│   │   ├── Dockerfile
│   │   ├── .gitignore
│   │   ├── hhapi
│   │   ├── manage.py
│   │   ├── .pylintrc
│   │   ├── requirements.txt
│   │   ├── venv
│   │   └── .vscode
│   └── crawler
│       ├── crawler-crontab
│       ├── Dockerfile
│       ├── .gitignore
│       ├── hhcrawler
│       ├── .pylintrc
│       ├── requirements.txt
│       ├── .scrapy
│       ├── scrapy.cfg
│       ├── venv
│       └── .vscode
├── docker-compose.development.yml
├── docker-compose.production.yml
├── .gitignore
├── .gitlab-ci.yml
├── househunter.code-workspace
└── .vscode
    └── settings.json

What I ended up doing was ignoring the apps directory on the project root and then add both apps to the workspace.

So the ./.vscode/settings.json looks like this:

{
    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true,
        "apps": true
      },
}

And the househunter.code-workspace file like so:

{
    "folders": [
        {
            "path": "apps/api"
        },
        {
            "path": "apps/crawler"
        },
        {
            "name": "root",
            "path": "."
        }
    ],
    "settings": {}
}

This is what I see on the editor:

project structure on visual studio code explorer

And it is indeed following the subprojects settings.json. This is far from being a great solution, but for the time being was the only way I found to achieve this - I'd also love to see someone document a proper solution for this. :)

Upvotes: 45

Related Questions