Visual Studio 代码和子文件夹特定设置

Visual Studio Code and subfolder-specific settings

我的工作区根目录是一个 git 存储库,其中包含几个文件和几个 git 子模块。每个子模块都有自己的 .vscode/settings.json。我期待 VSCode 根据我正在工作的 submodule/subfolder 调整其设置,但它没有按预期工作。

可能吗? 我认为如果您使用多根工作区(自 1.18 起支持)是可能的,但在我的情况下,我想保留该单根工作区。

我也找不到合适的答案,我确实找到了 "hacky" 解决方法。我有以下项目结构:

.
├── 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

我最终做的是忽略项目根目录中的 apps 目录,然后将两个应用程序添加到工作区。

所以 ./.vscode/settings.json 看起来像这样:

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

househunter.code-workspace 文件如下:

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

这是我在编辑器上看到的:

而且确实在关注子项目settings.json。这远不是一个很好的解决方案,但目前是我发现实现这一目标的唯一方法——我也很乐意看到有人为此记录一个合适的解决方案。 :)

在撰写本文时,该功能尚未实现。 2017 年 8 月 17 日提交的程序问题跟踪器中有一个功能请求:Monolithic structure, multiple project settings #32693

同时,如果您非常需要它,则必须按照 中所述滥用多根工作区。