如何将额外的语法突出显示到现有语言中?

发布于 2025-01-25 18:01:16 字数 1018 浏览 5 评论 0原文

我想添加一些额外的语言功能,例如javascript中的液体语言支持:

var firstName = "<% User.firstName %>";
var lastName = "<% User.firstName %>";

我浏览了一些浏览,我在VSCODE存储库中找到了此文件夹:https://github.com/microsoft/microsoft/vscode/tree/tree/main /扩展/javascript

基本上是JavaScript TMlanguage语法规则,因此我有这个想法创建一个新的JavaScript文件格式(.pjs)并应用相同的TMLAGUAGE文件并添加这些新规则:

    "pk-liquid-expression": {
        "begin": "<%",
        "beginCaptures": {
            "0": {
                "name": "storage.type.primitive.java"
            }
        },
        "end": "%>",
        "endCaptures": {
            "0": {
                "name": "storage.type.primitive.java"
            }
        },
        "name": "storage.type.primitive.java"
    },

这有效,并且这有效,并且有效,并且 有效,并且有效,并且它有效,并且可以使用。但是,现在我的PJS文件没有任何语言功能,例如错误和警告。

我认为我的解决方案不是很远见,所以可以只编辑当前的JavaScript TMlanguage规则并添加这些新令牌吗?

谢谢。

I want to add some extra language features, such as liquid language support inside JavaScript:

var firstName = "<% User.firstName %>";
var lastName = "<% User.firstName %>";

I browsed around a bit and I found this folder in the vscode repository: https://github.com/microsoft/vscode/tree/main/extensions/javascript

It's basically the JavaScript tmLanguage grammar rules, so I had this idea to create a new javascript file format (.pjs) and apply the same tmLanguage file as well as add these new rules:

    "pk-liquid-expression": {
        "begin": "<%",
        "beginCaptures": {
            "0": {
                "name": "storage.type.primitive.java"
            }
        },
        "end": "%>",
        "endCaptures": {
            "0": {
                "name": "storage.type.primitive.java"
            }
        },
        "name": "storage.type.primitive.java"
    },

And this worked, however now my pjs files don't have any of the language features such as errors and warnings.

I think my solution is not very forward-thinking however, so is it possible to just edit the current JavaScript tmLanguage rules and add these new tokens?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2025-02-01 18:01:16

一种解决方案是 indect 语言“进入JavaScript语言定义。这样做的主要步骤是定义语法以注入和创建一个定义何时注入您的语法的选择器:

{
  "contributes": {
    "grammars": [
      {
        "path": "./syntaxes/injection.json",
        "scopeName": "todo-comment.injection",
        "injectTo": ["source.js"]
      }
    ]
  }
}

另请参阅:如何在VSCODE中正确注入语法扩展(因此起作用)?

One solution is to inject the "liquid language" into the Javascript language definition. Main steps for that is to define a grammar to inject and creating a selector which defines when to inject your grammar:

{
  "contributes": {
    "grammars": [
      {
        "path": "./syntaxes/injection.json",
        "scopeName": "todo-comment.injection",
        "injectTo": ["source.js"]
      }
    ]
  }
}

See also: How to properly inject grammar extension in vscode (so it works)?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文