且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Visual Studio Code 语言扩展继承现有

更新时间:2022-06-05 01:49:37

1.注射

您可以通过将以下内容添加到您的 package.json 中,将您的语言扩展注入到父作用域的作用域中:

1. Injection

You can inject your language extension to the scope of the parent scope by adding the following to your package.json:

"contributes": {
    "grammars": [
        {
            "scopeName": "source.asm.x86_64.your_syntax_extension",
            "path": "./syntaxes/your_syntax_extension.json",
            "injectTo": [ "source.asm.x86_64" ]
        }
    ]
}

2.包括

如果您的语言扩展使用自定义文件类型,或者您想要覆盖某些父作用域的语法定义,您可以编写自己的定义并包含父作用域.您可以使用以下任一格式:

2. Include

If your language extension uses a custom file-type or you want to override some of the parent scope's syntax definitions, you can write you own definition and include the parent scope. You can use either of the following formats:

{
  "fileTypes": [
    "myExtension"
  ],
  "name": "Your Syntax Extension",
  "patterns": [
    {
      "include": "source.asm.x86_64"
    }
  ],
  "scopeName": "source.asm.x86_64.your_syntax_extension"
}

your_syntax_extension.tmLanguage

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>fileTypes</key>
    <array>
        <string>myExtension</string>
    </array>
    <key>name</key>
    <string>Your Syntax Extension</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>source.asm.x86_64</string>
        </dict>
    </array>
    <key>scopeName</key>
    <string>source.asm.x86_64.your_syntax_extension</string>
</dict>
</plist>

在这两种情况下,您可能都希望将扩展包作为依赖项包含在内.为此,请将其唯一标识符添加到您的 package.json:

In both cases, you might want to include the extended package as a dependency. To do so, add its unique identifier to your package.json:

"extensionDependencies": [
    "13xforever.language-x86-64-assembly"
]