Fix muted usage highlighter test by ignoring irrelevant highlighting
UsageHighlightingTestGenerated.testImplicitReturnExpressionsInLambdasNoHightlighting
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ fun some(a: Int, b: Int) {
|
|||||||
if (b > 100) {
|
if (b > 100) {
|
||||||
101 + j
|
101 + j
|
||||||
} else {
|
} else {
|
||||||
<info descr="null">~102</info> * j
|
~102 * j
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return@run false
|
return@run false
|
||||||
|
|||||||
@@ -7,16 +7,20 @@ package org.jetbrains.kotlin.idea.highlighter
|
|||||||
|
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
||||||
import com.intellij.codeInsight.highlighting.actions.HighlightUsagesAction
|
import com.intellij.codeInsight.highlighting.HighlightUsagesHandler
|
||||||
|
import com.intellij.openapi.editor.colors.EditorColors
|
||||||
|
import com.intellij.openapi.editor.colors.EditorColorsManager
|
||||||
|
import com.intellij.openapi.editor.markup.RangeHighlighter
|
||||||
|
import com.intellij.openapi.editor.markup.TextAttributes
|
||||||
import com.intellij.testFramework.ExpectedHighlightingData
|
import com.intellij.testFramework.ExpectedHighlightingData
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.extractMarkerOffset
|
import org.jetbrains.kotlin.idea.test.extractMarkerOffset
|
||||||
|
|
||||||
abstract class AbstractUsageHighlightingTest: KotlinLightCodeInsightFixtureTestCase() {
|
abstract class AbstractUsageHighlightingTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
companion object {
|
companion object {
|
||||||
// Not standard <caret> to leave it in text after configureByFile and remove manually after collecting highlighting information
|
// Not standard <caret> to leave it in text after configureByFile and remove manually after collecting highlighting information
|
||||||
val CARET_TAG = "~"
|
const val CARET_TAG = "~"
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun doTest(filePath: String) {
|
protected fun doTest(filePath: String) {
|
||||||
@@ -29,24 +33,37 @@ abstract class AbstractUsageHighlightingTest: KotlinLightCodeInsightFixtureTestC
|
|||||||
assert(caret != -1) { "Caret marker '$CARET_TAG' expected" }
|
assert(caret != -1) { "Caret marker '$CARET_TAG' expected" }
|
||||||
editor.caretModel.moveToOffset(caret)
|
editor.caretModel.moveToOffset(caret)
|
||||||
|
|
||||||
myFixture.testAction(HighlightUsagesAction())
|
HighlightUsagesHandler.invoke(project, editor, myFixture.file)
|
||||||
val highlighters = myFixture.editor.markupModel.allHighlighters
|
val highlighters = myFixture.editor.markupModel.allHighlighters
|
||||||
|
|
||||||
val infos = highlighters.map { highlighter ->
|
val infos = highlighters
|
||||||
var startOffset = highlighter.startOffset
|
.filter { isUsageHighlighting(it) }
|
||||||
var endOffset = highlighter.endOffset
|
.map { highlighter ->
|
||||||
|
var startOffset = highlighter.startOffset
|
||||||
|
var endOffset = highlighter.endOffset
|
||||||
|
|
||||||
if (startOffset > caret) startOffset += CARET_TAG.length
|
if (startOffset > caret) startOffset += CARET_TAG.length
|
||||||
if (endOffset > caret) endOffset += CARET_TAG.length
|
if (endOffset > caret) endOffset += CARET_TAG.length
|
||||||
|
|
||||||
HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION).range(startOffset, endOffset).create()
|
HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION)
|
||||||
}
|
.range(startOffset, endOffset)
|
||||||
|
.create()
|
||||||
|
}
|
||||||
|
|
||||||
data.checkResult(infos, StringBuilder(document.text).insert(caret, CARET_TAG).toString())
|
data.checkResult(infos, StringBuilder(document.text).insert(caret, CARET_TAG).toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isUsageHighlighting(info: RangeHighlighter): Boolean {
|
||||||
|
val globalScheme = EditorColorsManager.getInstance().globalScheme
|
||||||
|
|
||||||
|
val readAttributes: TextAttributes =
|
||||||
|
globalScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)
|
||||||
|
val writeAttributes: TextAttributes =
|
||||||
|
globalScheme.getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES)
|
||||||
|
|
||||||
override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE
|
return info.textAttributes == readAttributes || info.textAttributes == writeAttributes
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProjectDescriptor(): KotlinLightProjectDescriptor = KotlinLightProjectDescriptor.INSTANCE
|
||||||
override fun getTestDataPath() = ""
|
override fun getTestDataPath() = ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user