mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2024-11-25 07:42:58 +01:00
Compare commits
1 Commits
fd860fd390
...
519d80ed6e
Author | SHA1 | Date | |
---|---|---|---|
519d80ed6e |
@ -3,16 +3,12 @@ package com.chylex.intellij.inspectionlens.editor
|
||||
import com.intellij.lang.annotation.HighlightSeverity
|
||||
import java.util.function.Predicate
|
||||
|
||||
class LensSeverityFilter(private val disabledSeverityIds: Set<String>) : Predicate<HighlightSeverity> {
|
||||
class LensSeverityFilter(private val disabledSeverities: Set<String>) : Predicate<HighlightSeverity> {
|
||||
override fun test(severity: HighlightSeverity): Boolean {
|
||||
return Global.test(severity) && severity.name !in disabledSeverityIds
|
||||
return severity.myVal >= MINIMUM_SEVERITY && severity.name !in disabledSeverities
|
||||
}
|
||||
|
||||
object Global {
|
||||
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
||||
|
||||
fun test(severity: HighlightSeverity): Boolean {
|
||||
return severity.myVal >= MINIMUM_SEVERITY
|
||||
}
|
||||
companion object {
|
||||
val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
||||
}
|
||||
}
|
||||
|
@ -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,39 +29,27 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
|
||||
|
||||
return panel {
|
||||
group("Enabled Severities") {
|
||||
val registrar = SeverityRegistrar.getSeverityRegistrar(null)
|
||||
val knownSeverities = globalSeverities().sortedByDescending(HighlightSeverity::myVal)
|
||||
|
||||
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) {
|
||||
for (severity in knownSeverities) {
|
||||
row {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> Cell<JBCheckBox>.bindSelectedToNotIn(set: MutableCollection<T>, value: T): Cell<JBCheckBox> {
|
||||
private fun <T> Cell<JBCheckBox>.bindSelectedToNotInSet(set: ModificationTrackingCollection<T>, value: T): Cell<JBCheckBox> {
|
||||
return bindSelected({ value !in set }, { if (it) set.remove(value) else set.add(value) })
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ object LensSettings {
|
||||
get() = service<LensSettingsState>().state
|
||||
|
||||
fun createSeverityFilter(): LensSeverityFilter {
|
||||
return LensSeverityFilter(state.disabledSeveritiesReadOnly.mapTo(HashSet(), StoredSeverity::id))
|
||||
return LensSeverityFilter(state.disabledSeveritiesReadOnly)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,12 @@ import com.intellij.util.xmlb.annotations.XCollection
|
||||
class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State>(State()) {
|
||||
class State : BaseState() {
|
||||
@get:XCollection
|
||||
val disabledSeverities by list<StoredSeverity>()
|
||||
private val disabledSeverities by stringSet()
|
||||
|
||||
val disabledSeveritiesReadOnly: List<StoredSeverity>
|
||||
val disabledSeveritiesReadOnly: Set<String>
|
||||
get() = disabledSeverities
|
||||
|
||||
@Transient
|
||||
val disabledSeveritiesReal = ModificationTrackingCollection(disabledSeverities, ::incrementModificationCount)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
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() }
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user