【问题标题】:VS code api how to support customizable variables in settings?VS code api如何在设置中支持可自定义的变量?
【发布时间】:2018-04-18 01:54:03
【问题描述】:

我目前正在使用 typescript 为 VS 代码编写扩展。

该扩展正在尝试为类似 C 的语言创建精美的 cmets,以提高可读性和代码结构,如下所示

目前我将 cmets 对齐为 90 个字符,但我希望允许用户定义他们想要的任何对齐方式,并允许自定义填充字符

如何获取在 settings.json 中声明的设置变量?

编辑:

代码:

const config = vscode.workspace.getConfiguration('settings');
vscode.window.showInformationMessage(config.has('maximum').toString());

尽管包含

,但返回 false
"configuration": {
    "maximum":
    {
        "type": ["integer"],
        "default": 40,
        "description": "The level of alignment, how far the titles will extend horizontally"
    }
}

在 package.json 文件的贡献部分。我已经查看了在线文档和源代码,但我不清楚如何读取用户设置值。

应该修改哪个JSON文件,getConfiguration()需要给什么参数? API没有明确解释taht函数的参数是什么

【问题讨论】:

    标签: typescript visual-studio-code text-editor vscode-extensions


    【解决方案1】:
    // launch.json configuration
    const config = workspace.getConfiguration('launch', vscode.window.activeTextEditor.document.uri);
    
    // retrieve values
    const values = config.get('configurations');
    

    https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 2019-06-03
      • 2010-12-01
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多