Skip to content

Cannot inject grammar into already embedded languages #122

@NTaylorMullen

Description

@NTaylorMullen

I'm writing a language grammar for Razor and throughout Razor there are several locations where we call through to C#'s grammar to run their rules. However, after having attempted to write an injection grammar to handle cases when Razor weaves HTML into specific C# constructs aka:

image

It doesn't seem like injecting code into the source.cs grammar is sufficient. For my injection grammar I've written:

name: ASP.NET Razor C# Injection
scopeName: 'text.aspnetcorerazor.injection'
injectionSelector: 'L:source.cs'
patterns:
  - include: '#razor-template'

repository:
  razor-template:
    name: 'meta.structure.template.razor'
    begin: '(@)(?=\<)'
    beginCaptures:
      1: { patterns: [ include: 'text.aspnetcorerazor#transition' ] }
    patterns:
      - include: 'text.aspnetcorerazor#wellformed-html'
    end: '(?<=\>)'

Along side:
image

Which works fine in .cs files (haven't restricted where it can run yet):
image

However, when trying to make use of the injection in a Razor file in the embedded C#, it doesn't seem to apply:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions