Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not get external grammar injections to work #6858

Closed
alexdima opened this issue May 25, 2016 · 11 comments
Closed

Could not get external grammar injections to work #6858

alexdima opened this issue May 25, 2016 · 11 comments
Assignees
Milestone

Comments

@alexdima
Copy link
Member

Testing #6693

Modified $\extensions\typescript\package.json, added to the grammars section:

{
    "injectTo": ["source.ts"],
    "scopeName": "text.todo",
    "path": "./syntaxes/todo.json"
}

Added $\extensions\typescript\syntaxes\todo.json:

{
    "fileTypes": [],
    "injectionSelector": "comment, text.plain",
    "name": "TODO",
    "patterns": [
        {
            "match": "\\b(TODO|FIXME|CHANGED)\\b",
            "name": "storage.type.class.${1:/downcase}"
        },
        {
            "captures": {
                "1": {
                    "name": "markup.underline.link.radar"
                }
            },
            "match": "<(ra?dar:/(?:/problem|)/(?:[&0-9]+))>",
            "name": "storage.type.class.radar"
        }
    ],
    "scopeName": "text.todo"
}

I don't see it being picked up in TypeScript comments (inspecting the tokens also did not show it being picked up):
image

@alexdima alexdima added this to the May 2016 milestone May 25, 2016
@aeschli
Copy link
Contributor

aeschli commented May 26, 2016

At the moment injects are only applied to tokens generated by begin/end rules.
I'm investigating if that's a bug or not.

@aeschli
Copy link
Contributor

aeschli commented May 26, 2016

To verify, inject against the string scope in typescript.

@aeschli aeschli assigned alexdima and unassigned aeschli May 26, 2016
@kumarharsh
Copy link
Contributor

@aeschli - i'm trying to get this working for a graphql plugin, but can't get it to work. It's unclear to me what you mean by

injects are only applied to tokens generated by begin/end rules.

does that mean that the injected grammar will only work when the begin and end properties are specified on the top level?

also,

inject against the string scope in typescript
I tried injecting agains the string scope (by setting the injectionSelector to string.graphql, but nothing seems to change. Is there any resource I can refer to learn more about injection grammar?

If it helps, this is my config:

/* package.json */
  "grammars": [
      {
        "language": "graphql",
        "path": "./syntaxes/graphql.json",
        "scopeName": "source.graphql"
      },
      {
        "scopeName": "text.mxyzptlk",
        "path": "./syntaxes/gql-query.json",
        "injectTo": [
          "source.graphql"
        ]
      }
    ],
/* gql-todo.json */
{
    "fileTypes": [],
    "injectionSelector": "comment.graphql",
    "name": "TODO",
    "patterns": [
        {
            "match": "\\b(TODO|FIXME|CHANGED)\\b",
            "name": "storage.type.class.${1:/downcase}"
        },
        {
            "captures": {
                "1": {
                    "name": "markup.underline.link.radar"
                }
            },
            "match": "<(ra?dar:/(?:/problem|)/(?:[&0-9]+))>",
            "name": "storage.type.class.radar"
        }
    ],
    "scopeName": "text.mxyzptlk"
}

@mjbvz
Copy link
Collaborator

mjbvz commented Nov 15, 2016

@aeschli I also gave this a try recently and was unable to get it working. Are there any example extensions that have a grammar with injectTo working? Thanks.

@wholroyd
Copy link

@aeschli It seems like the behavior in 1.8.0-inside is following the begin/end injection. This needs to be expanded somehow to allow the injection to happen on the entire document. Take for example a YAML document using the Jinja templating language - the first value in the document could be a Jinja comment and not necessarily part of the YAML syntax.

@aeschli
Copy link
Contributor

aeschli commented Nov 22, 2016

@wholroyd We're using the text mate injection mechanism. Are you saying we lack a feature of it, or are you saying the injection mechanism (restricted to begin/end rules) is too limited?

@wholroyd
Copy link

@aeschli The later half

@kumarharsh
Copy link
Contributor

kumarharsh commented Dec 7, 2016

@aeschli running into same problems with graphql-for-vscode plugin. The regex to match starting of the Relay.QL/gql is not powerful enough on its own. It also needs info about the scope of the matching (it should not apply the rules if it's matching within a string, for example).

@wholroyd
Copy link

@aeschli - I guess the biggest issue I have, which I have not figured out over a couple months of playing with it on the weekends here and there - is how to inject a language syntax regardless of where it is present in the other language's file or syntax structure. How would I inject at the document level instead of within established language patterns? If I have `{{ something }}`` present anywhere in a file, regardless of the language colorized the way I want, how would I go about doing that?

@aeschli
Copy link
Contributor

aeschli commented Mar 20, 2017

You can choose a very open selector such as 'source.ts', but unfortunately injected rules will only be looked at when inside a begin/end rule.

@kumarharsh
Copy link
Contributor

I suppose you can put something equally open like "begin": ".*" and "end": ".*" for begin and end rules in the injected grammar?

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants