-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
[grammars] Pluggable syntax highlight engine for templating languages between backticks `` #2793
Comments
See #2000 and all linked issues. |
And write the your html code in dev/template.html |
@larskris Thanks for your comment. I've already taken this into consideration. But I have been using it in that way, indeed getting the html code support, but I feel that when a template isn't bigger than 20-30 lines, it's less time consuming to switch between the files and leave it in one file. This also adds to better reasoning about it. |
With TextMate grammars you can also inject syntax coloring rules. (http://blog.macromates.com/2012/injection-grammars-project-variables/). Would you be interested in expressing your coloring rules as Text mate inject rules? |
@aeschli sorry to be so slow in the follow up, but anything that could give me syntax highlighting (as a first step) and/or autocompletion between backticks '`' would be awesome. |
Hello, I am interested in this feature as well, as this along with the fact of having no way to easily use Gulp, is one of the main reason for me to use some proprietary solutions right now. |
Any news on this matter? |
You can now contribute injection grammars using the regular 'grammar' contribution point: "grammars": [
{
"scopeName": "source.todo",
"path": "./syntaxes/todo.json",
"injectTo": [ "source.js", "source.ts" ]
}, Check out https://github.com/Microsoft/vscode-textmate/blob/master/test-cases/first-mate/fixtures/todo.json for an example of an injection grammar. We don't have much experience with this type of grammars, but we hope they can provide a solution for language additions such as highlighting Angular templates. Feedback is highly welcome. |
I just got a chance to review the May update with the above stated "TextMate grammar injections". Out of the box at least, in my ts files HTML syntax highlight/completion is not available inside of backticks. I'm wanting to use this for Angular2 component templates. Can someone help me understand the configuration necessary to use "TextMate grammar injections" make this happen? |
@tolgabalci Can you share your injection grammar? |
@aeschli I'm sorry, but I'm not familiar with TextMate Grammer Injections. It's just that it was stated to help resolve syntax highlight/completion of HTML inside of backticks, so I'm trying to figure out how. Or should this issue not be closed? I don't mind taking on some work, if you can lead me in the right direction. |
I think #5961 is a full duplicate of this and can perhaps be closed as such. @aeschli would it be possible to extend the injection grammar syntax so template strings can be marked as a grammar as a whole, automatically matching the backticks and excluding the interpolations? Matching a full ES6 template with TextMate grammar is not trivial. Ideally, we'd be able to do something like (handwaving)
which would treat embedded CSS from http://styled-components.com as such, adding syntax highlighting and code completion, and replacing interpolations with the literal |
@aeschli or anyone, is there somewhere I can ask about extending the injection grammar like I propose above? |
@wmertens We were basically just providing the injection grammar capabilities that TextMate has. We want to stay compatible to that, having our own variant of TextMate is not what we aim for. None of us has serious experience with authoring an injection grammar. So, I'm guessing here. From what I understand your problem is that you don't want to repeat the rules for JavaScript expressions that can appear in the string literal. Any chance you can bring them in with an include |
@aeschli hmmm, the problem is that the interpolation can happen at any
time, and is not part of the injected grammar. So complex grammars lose
their parsing state at each interpolation, or maybe they need to be
extended that at every position, an interpolation can happen. Insanity.
If the template string can be stitched together before giving it to the
injected grammar, that makes grammar reuse easy.
|
Something similar happens with styled-jsx, i.e.
And also with markdown-in-js, i.e.
|
I've shamelessly copied from the atom-typescript issue.
To illustrate this, please look at a followup which contains a screenshot
The issue
Since backticks `` are ment for template formats, it would be nice to have a way to define syntax highlighting between them.
For example Angular2 implements templates in TypeScript as following:
Atom
The text was updated successfully, but these errors were encountered: