Updating VS Code user settings via an extension

寵の児 提交于 2019-12-06 06:59:52

Solved it. The code I posted was actually throwing an error, but the update method is asynchronous and therefore the error was getting swallowed. By using async/await on the function, I was able to see the error, which was something like:

'files.exclude.**/__tests__' is not a registered configuration.

Basically, I had to update the exclude configuration in its entirety, not an individual key under it because those keys are just part of the configuration value -- they aren't actual configuration keys themselves. The working solution:

async function hideTests() {
  const files = workspace.getConfiguration('files', ConfigurationTarget.Global)
  const exclude = files.get('exclude')
  testGlobs.forEach(g => exclude[g] = true)
  await files.update('exclude', exclude, ConfigurationTarget.Global)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!