【问题标题】:vscode new language configuration not changing syntax colorsvscode 新语言配置不改变语法颜色
【发布时间】:2017-09-02 03:03:52
【问题描述】:

我正在尝试为 CPU12 汇编语言的 Visual Studio Code 中的语法高亮创建一种新语言。当我在新的 .asm 文件中使用新语言时,编辑器知道注释字符是(当我键入 ctrl-k ctrl-c 时,它会在一行中添加一个分号),但文本是白色而不是默认注释颜色绿色。我是否需要指定使用默认的 vscode 主题?如果有,在哪里?

package.json

{
    "name": "cpu12",
    "displayName": "cpu12",
    "description": "cpu12",
    "version": "0.0.1",
    "publisher": "https://github.com/me",
    "engines": {
        "vscode": "^1.15.0"
    },
    "categories": [
        "Languages"
    ],
    "contributes": {
        "languages": [{
            "id": "cpu12",
            "aliases": ["CPU12", "cpu12"],
            "extensions": [".asm",".inc"],
            "configuration": "./language-configuration.json"
        }],
        "grammars": [{
            "language": "cpu12",
            "scopeName": "source.cpu12",
            "path": "./syntaxes/cpu12.tmLanguage.json"
        }]
    }
}

语言配置.json

{
    "comments": {
        // symbol used for single line comment. Remove this entry if your language does not support line comments
        "lineComment": ";"
    },
    // symbols used as brackets
    "brackets": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"]
    ],
    // symbols that are auto closed when typing
    "autoClosingPairs": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
        ["\"", "\""],
        ["'", "'"]
    ],
    // symbols that that can be used to surround a selection
    "surroundingPairs": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
        ["\"", "\""],
        ["'", "'"]
    ]
}

(我的./syntaxes/cpu12.tmLanguage.json 是空的。)

【问题讨论】:

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


    【解决方案1】:

    问题实际上是因为./syntaxes/cpu12.tmLanguage.json 是空的。您需要在 .json 文件中指定如何为线 cmets 着色:

    ./syntaxes/cpu12.tmLanguage.json

    {
        "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
        "name": "cpu12",
        "scopeName": "source.cpu12",
        "patterns": [
            {
                "comment": "Line Comments -- Asterisk only works at beginning of line",
                "match": "((;|^\\*).*$)",
                "captures": {
                    "1" :{
                        "name": "comment.line.cpu12"
                    }
                }
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      相关资源
      最近更新 更多