简体   繁体   English

VSCode Python 语言扩展

[英]VSCode Python Language Extension

I'm trying to create a VSCode extension for Ribosome .py.dna files我试图创建一个VSCode扩展核糖体.py.dna文件

Basically, .py.dna is identical to python, except that lines that start with .基本上, .py.dna与 python 相同,除了以. should have comment syntax highlighting.应该有注释语法高亮。

So far, this is what I have for my tmLanguage.json :到目前为止,这是我的tmLanguage.json

{
    "name": "RibosomePython",
    "patterns": [
        {
            "include": "#dots"
        }
    ],
    "repository": {
        "dots": {
            "name": "comment.dna",
            "begin": "\\.",
            "end": "$"
        }
    },
    "scopeName": "source.python.dna"
}

This works, in that lines starting with .这有效,在以. have python comment syntax highlighting.有 python 注释语法突出显示。 But now I'm not sure how to tell VSCode to have the real Python grammar highlight everything else.但是现在我不知道如何告诉 VSCode 让真正的 Python 语法突出显示其他所有内容。 How can I do this?我怎样才能做到这一点?

My package.json looks like:我的package.json看起来像:

{
    "name": "ribosome-dna",
    "displayName": "Ribosome DNA",
    "description": "Ribosome DNA Syntax Highlighting",
    "version": "0.0.1",
    "publisher": "rpgillespie",
    "engines": {
        "vscode": "^1.17.0"
    },
    "categories": [
        "Languages"
    ],
    "contributes": {
        "languages": [{
            "id": "dna",
            "aliases": ["DNA"],
            "extensions": [".py.dna"],
            "configuration": "./language-configuration.json"
        }],
        "grammars": [
            {
                "language": "dna",
                "scopeName": "source.python.dna",
                "path": "./syntaxes/dna.tmLanguage.json"
            }
        ]
    }
}

Note I was able to get it to work the way I wanted by copying and modifying python's grammar but this seems like overkill.注意我能够通过复制和修改 python 的语法让它以我想要的方式工作,但这似乎有点矫枉过正。

Edit:编辑:

For the curious, finished extension published here .对于在此处发布的好奇的已完成扩展。

Just add "include": "source.python" to your patterns :只需将"include": "source.python"到您的patterns

{
    "name": "RibosomePython",
    "patterns": [
        {
            "include": "#dots"
        },
        {
            "include": "source.python"
        }
    ],
    "repository": {
        "dots": {
            "name": "comment.dna",
            "begin": "\\.",
            "end": "$"
        }
    },
    "scopeName": "source.python.dna"
}

This feature is called injection grammar .此功能称为注入语法 VSCode added support for this in response to #2793 . VSCode 响应#2793添加了对此的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM