【问题标题】:VSCode extension to modify the files.exclude configurationVSCode 扩展修改 files.exclude 配置
【发布时间】:2020-02-18 06:37:39
【问题描述】:

目前我正在尝试编写一个扩展,允许我通过添加/删除/修改 files.exclude 配置元素中的条目并将其存储在工作区设置中来动态更改工作区过滤器。

运行这样的命令,例如修改基于字符串或数组的配置按预期工作:

const config = vscode.workspace.getConfiguration();
config.update('editor.fontSize', 14, false); -> works

但我就是想不通如何修改像files.exclude 这样的基于对象的配置。 我尝试了不同的方法,但总是得到一个错误,说我正在访问一个不存在的元素。

config.update('files.exclude.TestXYZ', false, false); -> doesn't work
config.update('TestXYZ', false, false); -> doesn't work

提前硬编码一个对象并将其用作配置的新值

let settings = { "*.html": true, "*.css": true };
config.update('files.exclude', settings, false); -> works, but isn't what I need

但为了编写可配置的工作区过滤器,我需要动态地从过滤器列表中添加/删除值。

除此之外(但不那么重要):我也无法以我可以使用的方式“读取”files.exclude 的当前值。我总是得到一个代理对象,我不是打字稿tbh中的专业人士。

最初的想法是读取配置,进行修改并将其保存回来,但在尝试了几个小时后,只要它有效,我就可以完全覆盖它们。

【问题讨论】:

标签: visual-studio-code vscode-extensions


【解决方案1】:

通过@Gama11 提供的有用链接,我能够达到我想要的结果:

const config = vscode.workspace.getConfiguration(); 
var excludeList: {[k: string]: boolean} = {}; 
excludeList[*.html] = true; 
excludeList[*.css] = true;
config.update('files.exclude', excludeList, false);

有了这个,我可以动态更改 excludeList 并相应地更新配置。

【讨论】:

    猜你喜欢
    • 2016-06-14
    • 1970-01-01
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 2021-06-21
    • 1970-01-01
    相关资源
    最近更新 更多