1
0
mirror of https://github.com/chylex/IntelliJ-Inspection-Lens.git synced 2024-10-17 03:42:47 +02:00

Compare commits

..

2 Commits

Author SHA1 Message Date
fd860fd390
WIP 2024-06-14 08:42:44 +02:00
a1fab197b2
WIP 2024-06-14 08:24:54 +02:00
6 changed files with 64 additions and 44 deletions

View File

@ -3,12 +3,16 @@ package com.chylex.intellij.inspectionlens.editor
import com.intellij.lang.annotation.HighlightSeverity
import java.util.function.Predicate
class LensSeverityFilter(private val disabledSeverities: Set<String>) : Predicate<HighlightSeverity> {
class LensSeverityFilter(private val disabledSeverityIds: Set<String>) : Predicate<HighlightSeverity> {
override fun test(severity: HighlightSeverity): Boolean {
return severity.myVal >= MINIMUM_SEVERITY && severity.name !in disabledSeverities
return Global.test(severity) && severity.name !in disabledSeverityIds
}
companion object {
val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
object Global {
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
fun test(severity: HighlightSeverity): Boolean {
return severity.myVal >= MINIMUM_SEVERITY
}
}
}

View File

@ -1,23 +1,23 @@
package com.chylex.intellij.inspectionlens.settings
import com.chylex.intellij.inspectionlens.editor.LensSeverityFilter
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.options.BoundConfigurable
import com.intellij.openapi.options.ConfigurableWithId
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.EditorTextFieldCellRenderer.SimpleRendererComponent
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.RightGap
import com.intellij.ui.dsl.builder.RowLayout
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel
class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), ConfigurableWithId {
companion object {
const val ID = "InspectionLens"
private fun globalSeverities(): List<HighlightSeverity> {
return SeverityRegistrar.getSeverityRegistrar(null).allSeverities
}
}
override fun getId(): String {
@ -29,27 +29,39 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
return panel {
group("Enabled Severities") {
val knownSeverities = globalSeverities().sortedByDescending(HighlightSeverity::myVal)
val registrar = SeverityRegistrar.getSeverityRegistrar(null)
for (severity in knownSeverities) {
val knownSeverities = registrar.allSeverities
.filter(LensSeverityFilter.Global::test)
.map { StoredSeverity(it) to registrar.getHighlightInfoTypeBySeverity(it).attributesKey.defaultAttributes }
val knownSeverityIds = knownSeverities
.mapTo(HashSet()) { it.first.id }
val unknownSeverities = settings.disabledSeverities
.filterNot { it.id in knownSeverityIds }
.map { it to null as TextAttributes? }
val allSeverities = (knownSeverities + unknownSeverities)
.sortedByDescending { it.first.priority }
for ((severity, textAttributes) in allSeverities) {
row {
checkBox(severity.displayCapitalizedName).bindSelectedToNotInSet(settings.disabledSeveritiesReal, severity.name)
}
}
val knownSeverityNames = knownSeverities.map { it.name }.toSet()
val noLongerKnownSeverityNames = settings.disabledSeveritiesReal.filterNot { it in knownSeverityNames }
for (severityName in noLongerKnownSeverityNames) {
row {
checkBox("Unknown ($severityName)").bindSelectedToNotInSet(settings.disabledSeveritiesReal, severityName)
}
val checkBox = checkBox(severity.name)
checkBox.bindSelectedToNotIn(settings.disabledSeverities, severity)
checkBox.gap(RightGap.COLUMNS)
val exampleLabel = SimpleRendererComponent(null, null, true)
exampleLabel.setText("Example", textAttributes, false)
exampleLabel.editor.contentComponent.setOpaque(false)
cell(exampleLabel)
}.layout(RowLayout.PARENT_GRID)
}
}
}
}
private fun <T> Cell<JBCheckBox>.bindSelectedToNotInSet(set: ModificationTrackingCollection<T>, value: T): Cell<JBCheckBox> {
private fun <T> Cell<JBCheckBox>.bindSelectedToNotIn(set: MutableCollection<T>, value: T): Cell<JBCheckBox> {
return bindSelected({ value !in set }, { if (it) set.remove(value) else set.add(value) })
}
}

View File

@ -8,6 +8,6 @@ object LensSettings {
get() = service<LensSettingsState>().state
fun createSeverityFilter(): LensSeverityFilter {
return LensSeverityFilter(state.disabledSeveritiesReadOnly)
return LensSeverityFilter(state.disabledSeveritiesReadOnly.mapTo(HashSet(), StoredSeverity::id))
}
}

View File

@ -15,12 +15,9 @@ import com.intellij.util.xmlb.annotations.XCollection
class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State>(State()) {
class State : BaseState() {
@get:XCollection
private val disabledSeverities by stringSet()
val disabledSeverities by list<StoredSeverity>()
val disabledSeveritiesReadOnly: Set<String>
val disabledSeveritiesReadOnly: List<StoredSeverity>
get() = disabledSeverities
@Transient
val disabledSeveritiesReal = ModificationTrackingCollection(disabledSeverities, ::incrementModificationCount)
}
}

View File

@ -1,15 +0,0 @@
package com.chylex.intellij.inspectionlens.settings
class ModificationTrackingCollection<T>(private val collection: MutableCollection<T>, private val onModified: () -> Unit) : Iterable<T> {
override fun iterator(): Iterator<T> {
return collection.iterator()
}
fun add(element: T): Boolean {
return collection.add(element).also { if (it) onModified() }
}
fun remove(element: T): Boolean {
return collection.remove(element).also { if (it) onModified() }
}
}

View File

@ -0,0 +1,22 @@
package com.chylex.intellij.inspectionlens.settings
import com.intellij.configurationStore.Property
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.util.xmlb.annotations.Tag
@Tag("severity")
data class StoredSeverity(
@Property var id: String = "",
@Property var name: String = "",
@Property var priority: Int = 0,
) {
constructor(severity: HighlightSeverity) : this(id = severity.name, name = severity.displayCapitalizedName, priority = severity.myVal)
override fun equals(other: Any?): Boolean {
return other is StoredSeverity && id == other.id
}
override fun hashCode(): Int {
return id.hashCode()
}
}