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

feat(angular): add angular syntax highlighting #4

Merged
merged 2 commits into from
Nov 6, 2023
Merged

Conversation

fvsch
Copy link
Member

@fvsch fvsch commented Nov 3, 2023

This PR adds TextMate grammars for syntaxes used by Angular, based on the latest syntaxes from https://github.com/angular/vscode-ng-language-service, including the Angular 17 control flow syntax.

Apparently there is no Angular templating language, only Angular-specific grammars for syntaxes embedded in other languages, especially in TypeScript (provides highlighting for template strings in TypeScript files) and in HTML. This PR adds 5 JSON grammars.

In my tests, when plugged into the StackBlitz classic editor, this leads to most projects (including non-Angular projects) fetching those 5 JSON grammars, as long as the project has a TypeScript or HTML file.

I’m a bit wary of those extra requests for all projects, but maybe that's an issue that we want to address separately.

grammars/grammars.json Outdated Show resolved Hide resolved
grammars/angular/syntaxes/template.json Show resolved Hide resolved
@fvsch
Copy link
Member Author

fvsch commented Nov 6, 2023

Tested with the Angular control flow syntax and other Angular template syntax highlighting in a random HTML file (not an Angular project). It's not ideal but it's not awful either. I can live with it.

angular-control-flow-syntax-in-html

Copy link
Contributor

@SamVerschueren SamVerschueren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work 💪 !

@fvsch fvsch merged commit aef6285 into main Nov 6, 2023
6 checks passed
@fvsch fvsch deleted the fvsch/angular-17 branch November 6, 2023 13:36
atscott added a commit to atscott/vscode-ng-language-service that referenced this pull request Nov 6, 2023
Template scopes do not need to be injected directly to source.ts.
Instead, template scopes apply when inline templates have been matched
in TS files and are included as patterns under that match.

The Angular template syntaxes _could_ be directly injected into TS like
they are now. This would apply them to any embedded `text.html` in a TS file.
This change applies Angular template grammars only to embedded HTML
matched by the inline template grammar (strings under `template:` of a
decorator).

`injectTo` applies only to the top-level file language and not embedded
labguages. So our `injectTo` `text.html` will not automatically apply to
inline templates simply by setting the `contentName` and language.

It would also be nice to further limit our grammars to apply only to
files that we know are Angular templates rather than injecting to every
to-level `.html` file.
In the future we might want to explore _not_ injecting into all top-level
`html` and then using `injectionSelector` to control from there. This
approach makes it difficult for environments that support
many frameworks/languages (stackblitz/textmate#4).

We might be able to create an "angular" language for `.component.html` and `.ng.html` files and use
our grammars only for those extensions rather than injecting them into
any and all `html`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants