-
-
Notifications
You must be signed in to change notification settings - Fork 160
Add language support for HEEx #3696
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
Open
mwnciau
wants to merge
12
commits into
KronicDeth:main
Choose a base branch
from
mwnciau:heex-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,385
−0
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6943242
Add basic support for HEEx copied from EEx
mwnciau 25b3e90
Add support for HEEx relative components in HTML
mwnciau 3edc6e1
Add HTML inspection suppressor for HEEx to ignore warning for HEEx co…
mwnciau f921780
Add parsing of HEEx braces to HEEx BNF
mwnciau 23a6b42
Fix injection of outer elements into HTML sections of HEEx templates
mwnciau 5c1836d
Add custom highlighter supporting tags beginning with "."
mwnciau 585a5d2
Disable HEEx brace interpolation within script and style tags
mwnciau fa14638
Add back in all the HTML functionality to our custom HTML language
mwnciau ce6141e
Add an OuterLanguageRangePatcher for HeexHTML to fix issues with the …
mwnciau 4069793
Remove custom HeexHTML language and instead override the default Html…
mwnciau 6cb611f
Fix edge case where components beginning with "Script" or "Style" wer…
mwnciau f078f88
Add custom highlighter for HTML in HEEx templates that uses the HEEx …
mwnciau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| // CANNOT be called `Parser` because ` | ||
| parserClass="org.elixir_lang.heex.Parser" | ||
| parserUtilClass="org.elixir_lang.heex.HEExParserUtil" | ||
|
|
||
| extends="com.intellij.extapi.psi.ASTWrapperPsiElement" | ||
|
|
||
| psiClassPrefix="HEEx" | ||
| psiImplClassSuffix="Impl" | ||
| psiPackage="org.elixir_lang.heex.psi" | ||
| psiImplPackage="org.elixir_lang.heex.psi.impl" | ||
|
|
||
| elementTypeHolderClass="org.elixir_lang.heex.psi.Types" | ||
| elementTypeClass="org.elixir_lang.heex.psi.ElementType" | ||
| tokenTypeClass="org.elixir_lang.heex.psi.TokenType" | ||
|
|
||
| tokens = [ | ||
| CLOSING = "%>" | ||
| COMMENT = "Comment" | ||
| COMMENT_MARKER = "#" | ||
| DATA = "Data" | ||
| EMPTY_MARKER = "Empty Marker" | ||
| EQUALS_MARKER = "=" | ||
| ELIXIR = "Elixir" | ||
| ESCAPED_OPENING = "<%%" | ||
| FORWARD_SLASH_MARKER = "/" | ||
| OPENING = "<%" | ||
| PIPE_MARKER = "|" | ||
| ] | ||
| } | ||
|
|
||
| private heexFile ::= (DATA | ESCAPED_OPENING | tag | braces)* | ||
| tag ::= OPENING (commentBody | elixirBody) CLOSING | ||
| { pin = 1 } | ||
| braces ::= BRACE_OPENING EQUALS_MARKER ELIXIR BRACE_CLOSING | ||
|
|
||
| private commentBody ::= COMMENT_MARKER COMMENT? | ||
| { pin = 1 } | ||
| private elixirBody ::= elixirMarker? ELIXIR? | ||
| private elixirMarker ::= EMPTY_MARKER | EQUALS_MARKER | FORWARD_SLASH_MARKER | PIPE_MARKER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package org.elixir_lang.heex.lexer; | ||
|
|
||
| import com.intellij.psi.TokenType; | ||
| import com.intellij.psi.tree.IElementType; | ||
| import kotlinx.html.SCRIPT;import org.elixir_lang.heex.psi.Types; | ||
|
|
||
| %% | ||
|
|
||
| // public instead of package-local to make testing easier. | ||
| %public | ||
| %class Flex | ||
| %implements com.intellij.lexer.FlexLexer | ||
| %unicode | ||
| %ignorecase | ||
| %function advance | ||
| %type IElementType | ||
| %eof{ return; | ||
| %eof} | ||
|
|
||
| %{ | ||
| private int openBraceCount = 0; | ||
|
|
||
| private void handleInState(int nextLexicalState) { | ||
| yypushback(yylength()); | ||
| yybegin(nextLexicalState); | ||
| } | ||
| %} | ||
|
|
||
| OPENING = "<%" | ||
| CLOSING = "%>" | ||
|
|
||
| BRACE_OPENING = "{" | ||
| BRACE_CLOSING = "}" | ||
|
|
||
| COMMENT_MARKER = "#" | ||
| EQUALS_MARKER = "=" | ||
| // See https://github.com/elixir-lang/elixir/pull/6281 | ||
| FORWARD_SLASH_MARKER = "/" | ||
| PIPE_MARKER = "|" | ||
| ESCAPED_OPENING = "<%%" | ||
| PROCEDURAL_OPENING = {OPENING} " " | ||
|
|
||
| WHITE_SPACE = [\ \t\f\r\n]+ | ||
| ANY = [^] | ||
|
|
||
| START_SCRIPT_TAG = "<script" | ||
| END_SCRIPT_TAG = "</script>" | ||
| START_STYLE_TAG = "<style" | ||
| END_STYLE_TAG = "</style>" | ||
|
|
||
| %state WHITESPACE_MAYBE | ||
| %state COMMENT | ||
| %state ELIXIR | ||
| %state MARKER_MAYBE | ||
| %state BEGIN_MATCHED_BRACES, MATCHED_BRACES | ||
| %state STYLE_TAG,SCRIPT_TAG | ||
|
|
||
| %% | ||
|
|
||
| <YYINITIAL> { | ||
| {BRACE_OPENING} { yybegin(BEGIN_MATCHED_BRACES); | ||
| return Types.BRACE_OPENING; } | ||
| {START_SCRIPT_TAG} { yybegin(SCRIPT_TAG); return Types.DATA; } | ||
| {START_STYLE_TAG} { yybegin(STYLE_TAG); return Types.DATA; } | ||
| } | ||
|
|
||
| <SCRIPT_TAG> { | ||
| {END_SCRIPT_TAG} { yybegin(YYINITIAL); return Types.DATA; } | ||
| } | ||
|
|
||
| <STYLE_TAG> { | ||
| {END_STYLE_TAG} { yybegin(YYINITIAL); return Types.DATA; } | ||
| } | ||
|
|
||
| <YYINITIAL,SCRIPT_TAG,STYLE_TAG> { | ||
| {ESCAPED_OPENING} { return Types.ESCAPED_OPENING; } | ||
| {OPENING} { yybegin(MARKER_MAYBE); | ||
| return Types.OPENING; } | ||
| {ANY} { return Types.DATA; } | ||
| } | ||
|
|
||
| <MARKER_MAYBE> { | ||
| {COMMENT_MARKER} { yybegin(COMMENT); | ||
| return Types.COMMENT_MARKER; } | ||
| {EQUALS_MARKER} { yybegin(ELIXIR); | ||
| return Types.EQUALS_MARKER; } | ||
| {FORWARD_SLASH_MARKER} { yybegin(ELIXIR); | ||
| return Types.FORWARD_SLASH_MARKER; } | ||
| {PIPE_MARKER} { yybegin(ELIXIR); | ||
| return Types.PIPE_MARKER; } | ||
| {ANY} { handleInState(ELIXIR); | ||
| return Types.EMPTY_MARKER; } | ||
| } | ||
|
|
||
| <BEGIN_MATCHED_BRACES> { | ||
| // We pretend there is an equals marker so it looks like a <%= tag to the Elixir parser | ||
| {ANY} { handleInState(MATCHED_BRACES); | ||
| return Types.EQUALS_MARKER; } | ||
| } | ||
|
|
||
| <MATCHED_BRACES> { | ||
| {BRACE_OPENING} { openBraceCount++; | ||
| return Types.ELIXIR; } | ||
| {BRACE_CLOSING} { | ||
| if (openBraceCount > 0) { | ||
| openBraceCount--; | ||
| return Types.ELIXIR; | ||
| } else { | ||
| yybegin(YYINITIAL); | ||
| return Types.BRACE_CLOSING; | ||
| } | ||
| } | ||
| {ANY} { return Types.ELIXIR; } | ||
| } | ||
|
|
||
| <COMMENT, ELIXIR> { | ||
| {CLOSING} { yybegin(WHITESPACE_MAYBE); | ||
| return Types.CLOSING; } | ||
| } | ||
|
|
||
| <COMMENT> { | ||
| {ANY} { return Types.COMMENT; } | ||
| } | ||
|
|
||
| <ELIXIR> { | ||
| {ANY} { return Types.ELIXIR; } | ||
| } | ||
|
|
||
| <WHITESPACE_MAYBE> { | ||
| // Only completely whitespace before a procedural tag counts as whitespace | ||
| {WHITE_SPACE} / {PROCEDURAL_OPENING} { yybegin(YYINITIAL); | ||
| return TokenType.WHITE_SPACE; } | ||
| {ANY} { handleInState(YYINITIAL); } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.elixir_lang | ||
|
|
||
| import com.intellij.psi.ResolveState | ||
| import org.elixir_lang.psi.call.Call | ||
|
|
||
| object HEEx { | ||
| fun isFunctionFrom(call: Call, state: ResolveState): Boolean = | ||
| call.functionName()?.let { functionName -> | ||
| when (functionName) { | ||
| FUNCTION_FROM_FILE_ARITY_RANGE.name -> | ||
| call.resolvedFinalArity() in FUNCTION_FROM_FILE_ARITY_RANGE.arityRange && | ||
| resolvesToHEEx(call, state) | ||
| FUNCTION_FROM_STRING_ARITY_RANGE.name -> | ||
| call.resolvedFinalArity() in FUNCTION_FROM_STRING_ARITY_RANGE.arityRange && | ||
| resolvesToHEEx(call, state) | ||
| else -> false | ||
| } | ||
| } ?: false | ||
|
|
||
| private fun resolvesToHEEx(call: Call, state: ResolveState): Boolean = | ||
| resolvesToModularName(call, state, "HEEx") | ||
|
|
||
| // function_from_file(kind, name, file, args \\ [], options \\ []) | ||
| val FUNCTION_FROM_FILE_ARITY_RANGE = NameArityRange("function_from_file", 3..5) | ||
| // function_from_string(kind, name, source, args \\ [], options \\ []) | ||
| val FUNCTION_FROM_STRING_ARITY_RANGE = NameArityRange("function_from_string", 3..5) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package org.elixir_lang.heex; | ||
|
|
||
|
|
||
| import com.intellij.psi.tree.IElementType; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| // See https://github.com/JetBrains/intellij-plugins/blob/500f42337a87f463e0340f43e2411266fcfa9c5f/handlebars/src/com/dmarcotte/handlebars/parsing/HbElementType.java | ||
| public class ElementType extends IElementType { | ||
| public ElementType(@NotNull String debugName) { | ||
| super(debugName, HeexLanguage.INSTANCE); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.elixir_lang.heex; | ||
|
|
||
| import com.intellij.extapi.psi.PsiFileBase; | ||
| import com.intellij.openapi.fileTypes.FileType; | ||
| import com.intellij.psi.FileViewProvider; | ||
| import org.elixir_lang.heex.file.Type; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| public class File extends PsiFileBase { | ||
| public File(@NotNull FileViewProvider fileViewProvider) { | ||
| super(fileViewProvider, HeexLanguage.INSTANCE); | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public FileType getFileType() { | ||
| return Type.INSTANCE; | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public String toString() { | ||
| return "HTML Embedded Elixir File"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.elixir_lang.heex; | ||
|
|
||
| import com.intellij.lang.parser.GeneratedParserUtilBase; | ||
|
|
||
| public class HEExParserUtil extends GeneratedParserUtilBase { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.elixir_lang.heex; | ||
|
|
||
| import com.intellij.openapi.fileTypes.FileTypes; | ||
| import com.intellij.openapi.fileTypes.LanguageFileType; | ||
| import com.intellij.psi.templateLanguages.TemplateLanguage; | ||
| import org.jetbrains.annotations.Contract; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| // See https://github.com/JetBrains/intellij-plugins/blob/500f42337a87f463e0340f43e2411266fcfa9c5f/handlebars/src/com/dmarcotte/handlebars/HbLanguage.java | ||
| public class HeexLanguage extends com.intellij.lang.Language implements TemplateLanguage { | ||
| public static final HeexLanguage INSTANCE = new HeexLanguage(); | ||
|
|
||
| protected HeexLanguage(@Nullable com.intellij.lang.Language baseLanguage, | ||
| @NotNull String ID, | ||
| @NotNull String... mimeTypes) { | ||
| super(baseLanguage, ID, mimeTypes); | ||
| } | ||
|
|
||
| public HeexLanguage() { | ||
| super("HEEx"); | ||
| } | ||
|
|
||
| @Contract(pure = true) | ||
| public static LanguageFileType defaultTemplateLanguageFileType() { | ||
| return FileTypes.PLAIN_TEXT; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.