1

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

包.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的是空的。)

4

1 回答 1

2

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

./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"
                }
            }
        }
    ]
}
于 2017-09-19T14:32:45.673 回答