-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handlebars: error filter for html tags WEB-12338
- Loading branch information
1 parent
31edac7
commit 24127aa
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
38 changes: 38 additions & 0 deletions
38
src/com/dmarcotte/handlebars/inspections/HbErrorFilter.java
This file contains 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,38 @@ | ||
package com.dmarcotte.handlebars.inspections; | ||
|
||
|
||
import com.dmarcotte.handlebars.file.HbFileViewProvider; | ||
import com.intellij.codeInsight.highlighting.TemplateLanguageErrorFilter; | ||
import com.intellij.psi.FileViewProvider; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiWhiteSpace; | ||
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider; | ||
import com.intellij.psi.tree.TokenSet; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static com.dmarcotte.handlebars.parsing.HbTokenTypes.*; | ||
|
||
public class HbErrorFilter extends TemplateLanguageErrorFilter { | ||
|
||
private static final TokenSet START_TEMPLATE_TOKENS = TokenSet.create(OPEN, OPEN_PARTIAL, OPEN_BLOCK, OPEN_INVERSE); | ||
|
||
protected HbErrorFilter() { | ||
super(START_TEMPLATE_TOKENS, HbFileViewProvider.class, "HTML"); | ||
} | ||
|
||
|
||
protected boolean shouldIgnoreErrorAt(@NotNull FileViewProvider viewProvider, int offset) { | ||
if (super.shouldIgnoreErrorAt(viewProvider, offset)) return true; | ||
|
||
return hasWhitespacesInHtmlBetweenErrorAndOpenTokens(offset, (TemplateLanguageFileViewProvider)viewProvider); | ||
} | ||
|
||
private static boolean hasWhitespacesInHtmlBetweenErrorAndOpenTokens(int offset, TemplateLanguageFileViewProvider viewProvider) { | ||
PsiElement at = viewProvider.findElementAt(offset, viewProvider.getTemplateDataLanguage()); | ||
if (!(at instanceof PsiWhiteSpace)) return false; | ||
PsiElement elementAt = viewProvider.findElementAt(at.getTextRange().getEndOffset() + 1, viewProvider.getBaseLanguage()); | ||
if (elementAt != null && START_TEMPLATE_TOKENS.contains(elementAt.getNode().getElementType())) return true; | ||
|
||
return false; | ||
} | ||
} |
This file contains 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,3 @@ | ||
{{#each}} | ||
<input<EOLError></EOLError> | ||
{{/each}} |
This file contains 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,5 @@ | ||
<div class="" | ||
{{#each input.attributes}} | ||
{{@key}}="{{this}}" | ||
{{/each}} /> | ||
|
This file contains 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