Skip to content

templ-go/templ-jetbrains

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ee8eb7a · Feb 17, 2025

History

62 Commits
Feb 10, 2025
Nov 8, 2023
Oct 27, 2023
Nov 2, 2023
Feb 10, 2024
Feb 17, 2025
Mar 22, 2024
Feb 17, 2025
Aug 30, 2024
Jun 17, 2024
Mar 22, 2024
Feb 17, 2025
Oct 27, 2023
Oct 27, 2023
Oct 27, 2023

Repository files navigation

Templ Jetbrains

Support for the Templ Programming Language

Features

  • Basic LSP Support
  • HTML editing support

Prerequisites

Tasks

bundle-vscode

Directory: ./grammars

zip -rqq ../tm-bundle.zip *
mv ../tm-bundle.zip ../src/main/resources/

Fix PSI parsing and lexing issues

This project uses Grammar-Kit for code generating the parser and lexer. A good starting point to understand how this works is following the Grammar-Kit documentation and the official Custom Language Support Tutorial. Another useful thing to know is that the HTML support is implemented with TemplFileViewProvider implementing the TemplateLanguageFileViewProvider following the custom templating language plugin tutorial. We use HTML_FRAGMENT Lexer tokens for the HTML parts of the templ files.

If this plugin does not parse Templ files correctly, a good starting point is to look at the output of "View PSI Structure of Current File..."-action to see how the file is parsed. If the Lexical token is incorrect at the point of the parsing error, you need to fix the lexer.

  1. Edit the _TemplLexer.flex file. You might find the JFlex manual useful.
  2. Run JFlex Generator action to generate the _TemplLexer.java file.
  3. Start the IDE with the Run Plugin configuration to see if the lexer works as expected. You can also run the lexer test and preferably add a new test case for the bug.

If the lexer token is correct, you need to modify the grammar which generates the parser code.

  1. Edit the TemplParser.bnf file.
  2. Run the Generate Parser Code action to generate the parser code. This also generates the PSI classes but does not remove the old ones, so you might want to remove the ./src/main/gen/com/templ/templ/psi directory before running this action.
  3. Start the IDE with the Run Plugin configuration to see if the parser works as expected. You can also run the parser test and preferably add a new test case for the bug.