【问题标题】:Can I set editor.tokenColorCustomizations inside a VSCode extension?我可以在 VSCode 扩展中设置 editor.tokenColorCustomizations 吗?
【发布时间】:2020-06-13 04:42:51
【问题描述】:

我正在为我在工作中使用的专有语言开发语言支持插件。我们经常访问深度嵌套对象的属性,例如This.isa.Really.Long.Variable.Name.ActualValue 所以代码变得非常密集。我的想法是将 TextMate 范围应用于最后一个点之前的所有内容,并将颜色更改为部分透明的白色,使其淡入背景。

我已经成功地在我的编辑器设置中添加了一条规则来更改我创建的 TextMate 范围的颜色。

"editor.tokenColorCustomizations": {
  "textMateRules": [{
    "scope": "support.variable.long.myLang",
    "settings": {
      "foreground": "#ffffff90",
      "fontStyle": "italic"
    }
  }]
}

但是,将此规则添加到我的扩展程序中的“configurationDefaults”不起作用,它会警告“未知的编辑器配置设置”。我可以设置其他编辑器设置就好了。

有没有办法做到这一点? 或者是否已经有一个通常与淡出文本相关的 TextMate 范围? 或者任何其他方式来淡入/隐藏 VScode 中的部分行?

【问题讨论】:

  • 我认为您不能在语言扩展中添加颜色。您在其中定义范围,然后主题引擎使用备用范围对其进行着色。

标签: visual-studio-code vscode-settings vscode-extensions


【解决方案1】:

应该有可能,这里我给你一个我的扩展的例子,为我的新范围定义颜色。工作正常。

"contributes": {
    "configurationDefaults": {
      "editor.tokenColorCustomizations": {
        "textMateRules": [
          {
            "scope": "my-extension.constants",
            "settings": {
              "foreground": "#b180a9"
            }
          },
          {
            "scope": "my-extension.variables",
            "settings": {
              "foreground": "#2ebe82"
            }
          },
          {
            "scope": "my-extension.translations",
            "settings": {
              "foreground": "#64a1f1"
            }
          },
          {
            "scope": "my-extension.store",
            "settings": {
              "foreground": "#b3b6b9"
            }
          }
        ]
      }
    }
  }

【讨论】:

  • 这是否会覆盖用户可能拥有的其他"editor.tokenColorCustomizations"?换句话说,设置"editor.tokenColorCustomizations" 是完全替换还是新的textMateRules 合并?
  • 它们合并,但如果范围重复,则以用户设置中配置的为准。
猜你喜欢
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 2019-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
  • 1970-01-01
相关资源
最近更新 更多