读写配置
几乎每个项目都会有自己的配置管理,通过配置信息维护可定制的内容。 比如网络请求超时时间,最大线程数等等
初始配置
在 package.json 的 contributes 中添加:
json
{
"contributes": {
"configuration": {
"type": "object",
"title": "yuConfig Configuration",
"properties": {
"yuConfig.workTime": {
"type": "number",
"default": 25,
"description": "Time of work, in minutes."
}
}
}
}
}读配置信息
ts
const config = vscode.workspace.getConfiguration("yuConfig");
let workTime = config.get('workTime');
console.log("workTime:",workTime);写配置信息
ts
let config = vscode.workspace.getConfiguration("yuConfig");
await config.update("workTime", 100, true);
await ConfigurationLoader.LoadConfiguration()但是一般我们通过vscode设置里面去修改配置