2

私は、文書作成ツールで使用するルール用に独自の構文強調表示拡張機能を作成しようとしています。

私はそれのほとんどを正常に動作させることができましたが、コメントをスコープインスペクターに認識させることができません。

競合を排除するために tmLanguage ファイルから他のすべての作業コードを削除したところ、次のようになりました。

ote-rules.tmLanguage.json

{
    "scopeName": "source.ote-rules",
    "patterns": [{
        "include": "#expression"
    }],
    "repository": {
        "expression": {
            "patterns": [
                {
                    "include": "#comments-ote"
                }
            ]
        },
        "comments-ote": {
            "patterns": [{
                    "include": "#comments-block"
                },
                {
                    "include": "#comments-line"
                }
            ],
            "comments-line": {
                "match": "\\/\\/.*?$",
                "name": "comment.line.double-slash.ote-rules"
            },
            "comments-block": {
                "begin": "\\/\\*",
                "end": "\\*\\/",
                "beginCaptures":{
                    "0":{"name":"punctuation.definition.comment.ote-rules"}
                },
                "endCaptures":{
                    "0":{"name":"punctuation.definition.comment.ote-rules"}
                }
            }
        }
    }
}

照合しようとしているファイルはプレーン テキスト ファイル (*.txt拡張子) であり、コメントは 2 つのスラッシュを含む行コメントか、および で始まり、それぞれ終わるブロック コメント/*です*/

テストテキストファイル.txt

// just some comment text 
  // indented comment
//
// left the above line empty apart from slashes
/*
inline block comment 
*/

スコープ インスペクターで上記のテキストを見ると、source.ote-rules からのものであることが認識されますが、トークンの種類が「その他」として表示されます。

スコープがその他として表示されているスコープ インスペクター出力のスクリーンショット

rubular.com で正規表現を確認しましたが、それらは私が示したサンプルで動作しているように見えます。

4

1 に答える 1

2

問題は、参照に含まれるパターン#が に直接含まれている必要"repository"があるのに、それらを にネストしたこと"comments-ote"です。単にそれらが見つからないだけです。

また、おそらく"comments-block"スコープ名を付けて、"name": "comment.block.ote-rules".

{
    "scopeName": "source.ote-rules",
    "patterns": [
        {
            "include": "#expression"
        }
    ],
    "repository": {
        "expression": {
            "patterns": [
                {
                    "include": "#comments-ote"
                }
            ]
        },
        "comments-ote": {
            "patterns": [
                {
                    "include": "#comments-block"
                },
                {
                    "include": "#comments-line"
                }
            ]
        },
        "comments-line": {
            "match": "\\/\\/.*?$",
            "name": "comment.line.double-slash.ote-rules"
        },
        "comments-block": {
            "begin": "\\/\\*",
            "end": "\\*\\/",
            "beginCaptures": {
                "0": {
                    "name": "punctuation.definition.comment.ote-rules"
                }
            },
            "endCaptures": {
                "0": {
                    "name": "punctuation.definition.comment.ote-rules"
                }
            },
            "name": "comment.block.ote-rules"
        }
    }
}

注: を使用する必要はありません。"include"パターンを 内で直接指定することもできます"patterns"

"comments-ote": {
    "patterns": [
        {
            "match": "\\/\\/.*?$",
            "name": "comment.line.double-slash.ote-rules"
        },
        {
            "begin": "\\/\\*",
            "end": "\\*\\/",
            "beginCaptures": {
                "0": {
                    "name": "punctuation.definition.comment.ote-rules"
                }
            },
            "endCaptures": {
                "0": {
                    "name": "punctuation.definition.comment.ote-rules"
                }
            },
            "name": "comment.block.ote-rules"
        }
    ]
}
于 2020-06-25T19:44:42.710 に答える