Visual Studio Code 语言扩展继承现有 [英] Visual Studio Code Language Extension Inherit Existing

查看:33
本文介绍了Visual Studio Code 语言扩展继承现有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio Code 中,只需提供一个语法文件即可添加您自己的语言扩展相对容易,例如通过 JSON.

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

我想为我使用的特定脚本语言提供一个语法文件.脚本语言嵌入在 ARM 汇编源代码中,已经存在一个插件.所以我基本上想通过我的脚本语言来扩展 ARM 扩展.目前有可能吗?

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?

在我的情况下,这将是 IMO 的方法,因为如果我只是复制现有的扩展(这是 MIT 许可的),我实际上会创建一个硬分叉,我不打算这样做.

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.注射

您可以通过将以下内容添加到您的 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"
]

这篇关于Visual Studio Code 语言扩展继承现有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆