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

Token Type Analyzer: use Razor Tokenizer for razor files #8042

Open
antonioaversa opened this issue Sep 21, 2023 · 0 comments
Open

Token Type Analyzer: use Razor Tokenizer for razor files #8042

antonioaversa opened this issue Sep 21, 2023 · 0 comments
Labels
Area: C# C# rules related issues. Type: Improvement Making existing code better.

Comments

@antonioaversa
Copy link
Contributor

antonioaversa commented Sep 21, 2023

In the current approach (not yet merged to master), the token type analyzer currently maps back tokens from the generated source to the razor source.

This approach is an effective first baby step to provide quick support for Razor syntax highlighting, but comes with some limitations:

  • depends on location mapping, which is based on line directives and affected by several bugs
  • only works for C# tokens: HTML tokens and Razor tokens (e.g. @using, @page, @* etc.) are not supported

The alternative, and the goal of this task, is to have a Razor-specific implementation of the TokenTypeAnalyzer that uses RazorSyntaxTree.

See razor unit tests on tokenization (some examples here) for some examples of its use.

That would generate all types of tokens, since Razor tokens embed C# ones: see here.

Disadvantages:

  • requires new parsing (or at least tokenization - can we have the second without paying the cost of full parsing? Probably not...)
  • requires maintenance every time a new version of C# and/or Razor is released, that introduces new tokens
@antonioaversa antonioaversa added Type: Improvement Making existing code better. Area: C# C# rules related issues. labels Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: Improvement Making existing code better.
Projects
None yet
Development

No branches or pull requests

1 participant