mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2025-04-21 15:15:46 +02:00
parent
e28804ad5d
commit
a84bc72fd4
src/main/kotlin/com/chylex/intellij/inspectionlens
@ -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) {
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user