Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code and subfolder-specific settings

Tags:

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.

like image 805
kytwb Avatar asked Nov 21 '17 04:11

kytwb


People also ask

How do I change the directory in VS Code?

The File > Add Folder to Workspace command brings up an Open Folder dialog to select the new folder. Once a root folder is added, the Explorer will show the new folder as a root in the File Explorer. You can right-click on any of the root folders and use the context menu to add or remove folders.

Where are VS Code preferences stored?

Depending on your platform, the user settings file is located here: Windows: %APPDATA%\Code\User\settings. json. macOS: $HOME/Library/Application Support/Code/User/settings.

How do I select a workspace folder in Visual Studio Code?

The easiest way to open a workspace is using the File menu and selecting one of the available folder entries for opening. Alternatively if you launch VS Code from a terminal, you can pass the path to a folder as the first argument to the code command for opening.


2 Answers

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. :)

like image 120
Diogo Avatar answered Sep 24 '22 08:09

Diogo


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.

like image 45
Álvaro González Avatar answered Sep 23 '22 08:09

Álvaro González