PanAeon / vscode-tmgrammar-test

Test helpers for VSCode textmate grammars

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

endCaptures doesn't apply scope

DecimalTurn opened this issue · comments

I seem to have an issue where beginCaptures works as intended, but can't seem to make endCaptures work.

I made a minimum reproducible example in this branch: https://github.com/DecimalTurn/vscode-vba/tree/endCaptures-Issue which ran the following workflow (See Test section).

In this example, the grammar is specified like this:

{
    "name": "Visual Basic for Applications",
    "scopeName": "source.vba",
    "fileTypes": [
        ".bas"
    ],
    "patterns": [
        {
            "include": "#metadata"
        }
    ],
    "repository": {
        "metadata": {
            "name": "metadata.vba",
            "begin": "(?i)^\\s*(BEGIN)\\b",
            "beginCaptures": {
                "1": {
                    "name": "keyword.metadata.vba"
                }
            },
            "end": "(?i)^\\s*(END)\\b",
            "endCaptures\"": {
                "1": {
                    "name": "keyword.metadata.vba"
                }
            }
        }
    }
}

This means that both BEGIN and END should have the keyword.metadata.vba scope. However, when running the snap command, that's not what I get:

> vscode-tmgrammar-snap -g ./out/vba.tmGrammar.json "syntaxes/tests/demo/*.bas"

Generating snapshot syntaxes/tests/demo/demo.bas.snap
===================================
Content of metadata.bas.snap:
>' SYNTAX TEST "source.vba" "metadata"
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.vba
>
>BEGIN
#^^^^^ source.vba metadata.vba keyword.metadata.vba
>' <----- keyword.metadata.vba
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.vba metadata.vba
>END
#^^^ source.vba metadata.vba
>' <--- keyword.metadata.vba
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.vba

Here, BEGIN has the required scope, but END is missing keyword.metadata.vba.

When working with VS code directly to debug, it works as shown in this screenshot:

image

Note that I tried multiple variations of the regex pattern and tried to use match 0th and 2nd as well, but still no luck.

On linux with VS Code 1.82.0, I can reproduce the buggy behavior using your branch:

image

Maybe this could be a bug (regression) in VS code?

Typo in the code. See serkonda7/vscode-vba#92 (comment)

Well, I guess I fell victim of the leniency of yaml's syntax before converting to json. I see now that endCaptures" isn't considered a syntax error even in the json version, but I'm wondering if it would be a good idea to include some sort of test that checks the syntax of the .tmGrammar.json file is actually valid.

@PanAeon I could always make a separate issue for this if you think that's something that you'd like to see added eventually.