-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suppress error highlighting if error intersects template string argument
- Loading branch information
Showing
6 changed files
with
100 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
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/intellij/StyledComponents/InterpolationArgumentsErrorFilter.kt
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,36 @@ | ||
package com.intellij.StyledComponents | ||
|
||
import com.intellij.codeInsight.daemon.impl.HighlightInfo | ||
import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter | ||
import com.intellij.codeInsight.highlighting.HighlightErrorFilter | ||
import com.intellij.lang.annotation.HighlightSeverity | ||
import com.intellij.psi.PsiErrorElement | ||
import com.intellij.psi.PsiFile | ||
|
||
class InterpolationArgumentsErrorFilter : HighlightErrorFilter(), HighlightInfoFilter { | ||
override fun shouldHighlightErrorElement(element: PsiErrorElement): Boolean { | ||
val acceptedRanges = element.containingFile.getUserData(INJECTED_FILE_RANGES_KEY) | ||
if (acceptedRanges == null) { | ||
return true | ||
} | ||
return acceptedRanges.any { range -> range.contains(element.textRange) } | ||
} | ||
|
||
override fun accept(highlightInfo: HighlightInfo, file: PsiFile?): Boolean { | ||
val acceptedRanges = file?.getUserData(INJECTED_FILE_RANGES_KEY) | ||
if (acceptedRanges == null) { | ||
return true | ||
} | ||
if (highlightInfo.severity === HighlightSeverity.WARNING | ||
|| highlightInfo.severity === HighlightSeverity.WEAK_WARNING | ||
|| highlightInfo.severity === HighlightSeverity.ERROR) { | ||
return acceptedRanges.any { range -> | ||
highlightInfo.startOffset > range.startOffset | ||
&& highlightInfo.endOffset < range.endOffset | ||
} | ||
} | ||
return true | ||
} | ||
|
||
} | ||
|
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
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
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,43 @@ | ||
import com.intellij.psi.css.inspections.invalid.CssInvalidPropertyValueInspection | ||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase | ||
|
||
class HighlightingTest : LightCodeInsightFixtureTestCase() { | ||
|
||
fun testWithoutArguments_ErrorsHighlighted() { | ||
myFixture.enableInspections(CssInvalidPropertyValueInspection::class.java) | ||
doTest("var someCss = css`div {\n" + | ||
" color:<error descr=\"a term expected\"> </error>{}\n" + | ||
"<error descr=\"Unexpected terms\">}</error>;`") | ||
} | ||
|
||
fun testErrorSurroundsInterpolationArgument_NotHighlighted() { | ||
myFixture.enableInspections(CssInvalidPropertyValueInspection::class.java) | ||
doTest("var someCss = css`\n" + | ||
"//should not highlight\n" + | ||
"withArgument{\n" + | ||
" border: 5px \${foobar} red;\n" + | ||
"},\n" + | ||
"//should highlight\n" + | ||
"withoutArgument {\n" + | ||
" border: 5px<error> foobar-not-acceptable red</error>;\n" + | ||
"};;`") | ||
} | ||
|
||
fun testErrorAdjacentToInterpolationArgument_NotHighlighted() { | ||
doTest("var styledSomething = styled.something`\n" + | ||
" perspective: 1000px;\n" + | ||
" \${value}\n" + | ||
" \${anotherValue}\n" + | ||
"`\n" + | ||
"const Triangle = styled.span`\n" + | ||
" \${({ right }) => (right ? 'right: 0;' : 'left: 0;')}\n" + | ||
"`") | ||
} | ||
|
||
private fun doTest(expected: String) { | ||
myFixture.setCaresAboutInjection(false) | ||
myFixture.configureByText("dummy.es6", expected) | ||
myFixture.testHighlighting(true, false, true) | ||
} | ||
|
||
} |
Binary file not shown.