diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt index c59c10d..1f44d70 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.util.Key * Listens for inspection highlights and reports them to [EditorLensManager]. */ internal class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener { + private val settingsService = service<LensSettingsState>() private val lensManagerDispatcher = EditorLensManagerDispatcher(EditorLensManager.getOrCreate(editor)) override fun afterAdded(highlighter: RangeHighlighterEx) { @@ -53,20 +54,19 @@ internal class LensMarkupModelListener private constructor(editor: Editor) : Mar lensManagerDispatcher.hideAll() } + private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? { + return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { settingsService.severityFilter.test(it.severity) } + } + + private inline fun runWithHighlighterIfValid(highlighter: RangeHighlighter, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) { + val info = highlighter.takeIf { it.isValid }?.let(::getFilteredHighlightInfo) + if (info != null) { + processHighlighterWithInfo(HighlighterWithInfo.from(highlighter, info), actionForImmediate, actionForAsync) + } + } + companion object { private val EDITOR_KEY = Key<LensMarkupModelListener>(LensMarkupModelListener::class.java.name) - private val SETTINGS_SERVICE = service<LensSettingsState>() - - private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? { - return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { SETTINGS_SERVICE.severityFilter.test(it.severity) } - } - - private inline fun runWithHighlighterIfValid(highlighter: RangeHighlighter, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) { - val info = highlighter.takeIf { it.isValid }?.let(::getFilteredHighlightInfo) - if (info != null) { - processHighlighterWithInfo(HighlighterWithInfo.from(highlighter, info), actionForImmediate, actionForAsync) - } - } private inline fun processHighlighterWithInfo(highlighterWithInfo: HighlighterWithInfo, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) { if (highlighterWithInfo is HighlighterWithInfo.Async) { diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt index 1176180..850e524 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt @@ -25,10 +25,6 @@ import java.awt.Cursor class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), ConfigurableWithId { companion object { const val ID = "InspectionLens" - - private fun getTextAttributes(registrar: SeverityRegistrar, severity: HighlightSeverity): TextAttributes? { - return registrar.getHighlightInfoTypeBySeverity(severity).attributesKey.defaultAttributes - } } private data class DisplayedSeverity( @@ -42,7 +38,7 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config ) : this( id = severity.name, severity = StoredSeverity(severity), - textAttributes = getTextAttributes(registrar, severity) + textAttributes = registrar.getHighlightInfoTypeBySeverity(severity).attributesKey.defaultAttributes ) }