如何为 VSCode (tmlanguage.json) 自定义此语法荧光笔的主题? [英] How to customize the theme of this syntax highlighter for VSCode (tmlanguage.json)?

查看:16
本文介绍了如何为 VSCode (tmlanguage.json) 自定义此语法荧光笔的主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个关于 VSCode 语法突出显示 tmLanguage.json 的问题,到目前为止我在浏览 google 和 VSCode 文档(和 textmate 文档)时无法轻松找到这些问题.所有这些都适用于

样式是:

<代码>{$schema":https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",名称":MyScript",模式":[{包括":#terms"},{包括":#标点符号"},{包括":#strings"},{包括":#numbers"}],存储库":{条款":{模式":[{名称":entity.name.type.language.myscript",匹配":([a-z][a-z0-9]*(?:-[a-z0-9]+)*)";},{名称":entity.name.type.language.parens.myscript",开始":([a-z][a-z0-9]*(?:-[a-z0-9]+)*)\\(",结束":\\)",模式":[{包括":#terms"},{包括":#strings"},{包括":#numbers"}]}]},数字":{模式":[{名称":constant.numeric.integer.myscript",匹配":\\b(\\d+)\\b"},{名称":constant.numeric.decimal.myscript",匹配":\\b(\\d+\\.\\d+)\\b";}]},标点符号":{模式":[{name":punctuation.separator.parameter.myscript",匹配":,"},{名称":punctuation.curly.open.myscript",匹配":\\{";},{名称":punctuation.curly.close.myscript",匹配":\\}"}]},字符串":{名称":string.myscript",开始":\\<",结束":\\",模式":[{名称":constant.character.escape.myscript",匹配":\\\\."},{名称":punctuation.term.myscript",开始":\\{",开始捕获":{0":{名称":meta.brace.curly.myscript"}},结束":\\}",endCaptures":{0":{名称":meta.brace.curly.myscript"}},模式":[{包括":#terms"},{包括":#numbers"},{包括":#strings"}]}]}},范围名称":source.myscript"}

根据我的默认 GitHub 主题,我通过选择 entity.name.type 获得了绿松石色.我不希望自定义主题,我只是希望它映射到主题中的一组给定颜色.我想:

  • 黑色代表实体";(条款)
  • 蓝色代表字符串"
  • 绿色代表数字"
  • 标点符号为灰色

我一直在修补一段时间,试图让 大括号不是红色的,但我一直无法弄清楚.还有another(123)周围的括号,它们也应该是灰色的.

我不知道其他语言是如何定义它们的样式的,比如 JSON(我想要的蓝色):

或其他 JSON:

红色的逗号也应该是灰色的.

解决方案

要指定自定义配置,请使用 this 在 package.json 中:

贡献":{配置默认值":{[降价]":{editor.wordWrap":开",editor.quickSuggestions":false}},

I have a few questions about VSCode Syntax Highlighting tmLanguage.json that I haven't been able to find easily so far in browsing google and the VSCode docs (and textmate docs). All of these apply to building your own language extension (I used yo code to generate the project). Most of them are about my specific use case.

  1. How do you specify custom settings that the user can then override? I would like to specify word wrapping as a togglable option for my script.
  2. How do you pick some scope so the colors are what you'd like?
  3. How do I get the parentheses to be styled properly?

Here is what I have.

The styles are:

{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "MyScript",
  "patterns": [
    {
      "include": "#terms"
    },
    {
      "include": "#punctuations"
    },
    {
      "include": "#strings"
    },
    {
      "include": "#numbers"
    }
  ],
  "repository": {
    "terms": {
      "patterns": [
        {
          "name": "entity.name.type.language.myscript",
          "match": "([a-z][a-z0-9]*(?:-[a-z0-9]+)*)"
        },
        {
          "name": "entity.name.type.language.parens.myscript",
          "begin": "([a-z][a-z0-9]*(?:-[a-z0-9]+)*)\\(",
          "end": "\\)",
          "patterns": [
            {
              "includes": "#terms"
            },
            {
              "includes": "#strings"
            },
            {
              "includes": "#numbers"
            }
          ]
        }
      ]
    },
    "numbers": {
      "patterns": [
        {
          "name": "constant.numeric.integer.myscript",
          "match": "\\b(\\d+)\\b"
        },
        {
          "name": "constant.numeric.decimal.myscript",
          "match": "\\b(\\d+\\.\\d+)\\b"
        }
      ]
    },
    "punctuations": {
      "patterns": [
        {
          "name": "punctuation.separator.parameter.myscript",
          "match": ","
        },
        {
          "name": "punctuation.curly.open.myscript",
          "match": "\\{"
        },
        {
          "name": "punctuation.curly.close.myscript",
          "match": "\\}"
        }
      ]
    },
    "strings": {
      "name": "string.myscript",
      "begin": "\\<",
      "end": "\\>",
      "patterns": [
        {
          "name": "constant.character.escape.myscript",
          "match": "\\\\."
        },
        {
          "name": "punctuation.term.myscript",
          "begin": "\\{",
          "beginCaptures": {
            "0": {
              "name": "meta.brace.curly.myscript"
            }
          },
          "end": "\\}",
          "endCaptures": {
            "0": {
              "name": "meta.brace.curly.myscript"
            }
          },
          "patterns": [
            {
              "include": "#terms"
            },
            {
              "include": "#numbers"
            },
            {
              "include": "#strings"
            }
          ]
        }
      ]
    }
  },
  "scopeName": "source.myscript"
}

I got that turquoise color by picking entity.name.type, given my default GitHub theme. I don't expect to customize the theme, I just want it to map to a given set of colors within a theme. I would like:

  • black for the "entities" (terms)
  • blue for the "strings"
  • green for the "numbers"
  • gray for the punctuation

I have been tinkering for a while trying to get the <text {term}> curly brackets to not be red, but I haven't been able to figure it out. Also the parentheses around another(123), they should be gray too.

I am not able to tell how the other languages defined their styles, like JSON (the blue I want):

Or other JSON:

The comma in the red should also be gray as well.

解决方案

To specify custom configuration, use this in package.json:

"contributes": {
"configurationDefaults": {
  "[markdown]": {
    "editor.wordWrap": "on",
    "editor.quickSuggestions": false
  }
},

这篇关于如何为 VSCode (tmlanguage.json) 自定义此语法荧光笔的主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆