mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2024-11-24 22:42:52 +01:00
Compare commits
2 Commits
519d80ed6e
...
fd860fd390
Author | SHA1 | Date | |
---|---|---|---|
fd860fd390 | |||
a1fab197b2 |
@ -3,12 +3,16 @@ package com.chylex.intellij.inspectionlens.editor
|
|||||||
import com.intellij.lang.annotation.HighlightSeverity
|
import com.intellij.lang.annotation.HighlightSeverity
|
||||||
import java.util.function.Predicate
|
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 {
|
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 {
|
object Global {
|
||||||
val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
||||||
|
|
||||||
|
fun test(severity: HighlightSeverity): Boolean {
|
||||||
|
return severity.myVal >= MINIMUM_SEVERITY
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
package com.chylex.intellij.inspectionlens.settings
|
package com.chylex.intellij.inspectionlens.settings
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.editor.LensSeverityFilter
|
||||||
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar
|
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar
|
||||||
import com.intellij.lang.annotation.HighlightSeverity
|
|
||||||
import com.intellij.openapi.components.service
|
import com.intellij.openapi.components.service
|
||||||
|
import com.intellij.openapi.editor.markup.TextAttributes
|
||||||
import com.intellij.openapi.options.BoundConfigurable
|
import com.intellij.openapi.options.BoundConfigurable
|
||||||
import com.intellij.openapi.options.ConfigurableWithId
|
import com.intellij.openapi.options.ConfigurableWithId
|
||||||
import com.intellij.openapi.ui.DialogPanel
|
import com.intellij.openapi.ui.DialogPanel
|
||||||
|
import com.intellij.ui.EditorTextFieldCellRenderer.SimpleRendererComponent
|
||||||
import com.intellij.ui.components.JBCheckBox
|
import com.intellij.ui.components.JBCheckBox
|
||||||
import com.intellij.ui.dsl.builder.Cell
|
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.bindSelected
|
||||||
import com.intellij.ui.dsl.builder.panel
|
import com.intellij.ui.dsl.builder.panel
|
||||||
|
|
||||||
class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), ConfigurableWithId {
|
class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), ConfigurableWithId {
|
||||||
companion object {
|
companion object {
|
||||||
const val ID = "InspectionLens"
|
const val ID = "InspectionLens"
|
||||||
|
|
||||||
private fun globalSeverities(): List<HighlightSeverity> {
|
|
||||||
return SeverityRegistrar.getSeverityRegistrar(null).allSeverities
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getId(): String {
|
override fun getId(): String {
|
||||||
@ -29,27 +29,39 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
|
|||||||
|
|
||||||
return panel {
|
return panel {
|
||||||
group("Enabled Severities") {
|
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 {
|
row {
|
||||||
checkBox(severity.displayCapitalizedName).bindSelectedToNotInSet(settings.disabledSeveritiesReal, severity.name)
|
val checkBox = checkBox(severity.name)
|
||||||
}
|
checkBox.bindSelectedToNotIn(settings.disabledSeverities, severity)
|
||||||
}
|
checkBox.gap(RightGap.COLUMNS)
|
||||||
|
|
||||||
val knownSeverityNames = knownSeverities.map { it.name }.toSet()
|
val exampleLabel = SimpleRendererComponent(null, null, true)
|
||||||
val noLongerKnownSeverityNames = settings.disabledSeveritiesReal.filterNot { it in knownSeverityNames }
|
exampleLabel.setText("Example", textAttributes, false)
|
||||||
|
exampleLabel.editor.contentComponent.setOpaque(false)
|
||||||
for (severityName in noLongerKnownSeverityNames) {
|
cell(exampleLabel)
|
||||||
row {
|
}.layout(RowLayout.PARENT_GRID)
|
||||||
checkBox("Unknown ($severityName)").bindSelectedToNotInSet(settings.disabledSeveritiesReal, severityName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) })
|
return bindSelected({ value !in set }, { if (it) set.remove(value) else set.add(value) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@ object LensSettings {
|
|||||||
get() = service<LensSettingsState>().state
|
get() = service<LensSettingsState>().state
|
||||||
|
|
||||||
fun createSeverityFilter(): LensSeverityFilter {
|
fun createSeverityFilter(): LensSeverityFilter {
|
||||||
return LensSeverityFilter(state.disabledSeveritiesReadOnly)
|
return LensSeverityFilter(state.disabledSeveritiesReadOnly.mapTo(HashSet(), StoredSeverity::id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,9 @@ import com.intellij.util.xmlb.annotations.XCollection
|
|||||||
class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State>(State()) {
|
class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State>(State()) {
|
||||||
class State : BaseState() {
|
class State : BaseState() {
|
||||||
@get:XCollection
|
@get:XCollection
|
||||||
private val disabledSeverities by stringSet()
|
val disabledSeverities by list<StoredSeverity>()
|
||||||
|
|
||||||
val disabledSeveritiesReadOnly: Set<String>
|
val disabledSeveritiesReadOnly: List<StoredSeverity>
|
||||||
get() = disabledSeverities
|
get() = disabledSeverities
|
||||||
|
|
||||||
@Transient
|
|
||||||
val disabledSeveritiesReal = ModificationTrackingCollection(disabledSeverities, ::incrementModificationCount)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() }
|
|
||||||
}
|
|
||||||
}
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user