Visual Studio Code Language Extension Inherit Existing

不打扰是莪最后的温柔 提交于 2019-12-11 12:54:40

问题


In Visual Studio Code it is relatively easy to add your own Language Extension just by providing a grammar file, e.g. via JSON.

I want to provide a syntax file for a particular script language I use. The script language is embedded in ARM Assembly source code, which there already exists a plugin for. So I basically want to extend the ARM Extension by my script language. Is that currently possible?

This would IMO be the way to go in my case, because if I just copy the existing extension (Which is MIT licenced) I would de-facto create a hard-fork, which I do not intend to do.


回答1:


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. 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:

your_syntax_extension.json

{
  "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>

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"
]


来源:https://stackoverflow.com/questions/51434014/visual-studio-code-language-extension-inherit-existing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!