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 com.intellij.lang.annotation.HighlightSeverity
|
||||||
import java.util.function.Predicate
|
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 {
|
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 {
|
companion object {
|
||||||
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
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,39 +29,27 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
|
|||||||
|
|
||||||
return panel {
|
return panel {
|
||||||
group("Enabled Severities") {
|
group("Enabled Severities") {
|
||||||
val registrar = SeverityRegistrar.getSeverityRegistrar(null)
|
val knownSeverities = globalSeverities().sortedByDescending(HighlightSeverity::myVal)
|
||||||
|
|
||||||
val knownSeverities = registrar.allSeverities
|
for (severity in knownSeverities) {
|
||||||
.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 {
|
||||||
val checkBox = checkBox(severity.name)
|
checkBox(severity.displayCapitalizedName).bindSelectedToNotInSet(settings.disabledSeveritiesReal, severity.name)
|
||||||
checkBox.bindSelectedToNotIn(settings.disabledSeverities, severity)
|
}
|
||||||
checkBox.gap(RightGap.COLUMNS)
|
}
|
||||||
|
|
||||||
val exampleLabel = SimpleRendererComponent(null, null, true)
|
val knownSeverityNames = knownSeverities.map { it.name }.toSet()
|
||||||
exampleLabel.setText("Example", textAttributes, false)
|
val noLongerKnownSeverityNames = settings.disabledSeveritiesReal.filterNot { it in knownSeverityNames }
|
||||||
exampleLabel.editor.contentComponent.setOpaque(false)
|
|
||||||
cell(exampleLabel)
|
for (severityName in noLongerKnownSeverityNames) {
|
||||||
}.layout(RowLayout.PARENT_GRID)
|
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) })
|
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.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 LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State>(State()) {
|
||||||
class State : BaseState() {
|
class State : BaseState() {
|
||||||
@get:XCollection
|
@get:XCollection
|
||||||
val disabledSeverities by list<StoredSeverity>()
|
private val disabledSeverities by stringSet()
|
||||||
|
|
||||||
val disabledSeveritiesReadOnly: List<StoredSeverity>
|
val disabledSeveritiesReadOnly: Set<String>
|
||||||
get() = disabledSeverities
|
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