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 |
@ -1,7 +1,7 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.settings.LensSettings
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.lang.annotation.HighlightSeverity
|
|
||||||
import com.intellij.openapi.Disposable
|
import com.intellij.openapi.Disposable
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.ex.MarkupModelEx
|
import com.intellij.openapi.editor.ex.MarkupModelEx
|
||||||
@ -17,6 +17,7 @@ import com.intellij.openapi.util.Key
|
|||||||
*/
|
*/
|
||||||
internal class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener {
|
internal class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener {
|
||||||
private val lensManagerDispatcher = EditorLensManagerDispatcher(EditorLensManager.getOrCreate(editor))
|
private val lensManagerDispatcher = EditorLensManagerDispatcher(EditorLensManager.getOrCreate(editor))
|
||||||
|
private val severityFilter = LensSettings.createSeverityFilter()
|
||||||
|
|
||||||
override fun afterAdded(highlighter: RangeHighlighterEx) {
|
override fun afterAdded(highlighter: RangeHighlighterEx) {
|
||||||
showIfValid(highlighter)
|
showIfValid(highlighter)
|
||||||
@ -48,20 +49,23 @@ internal class LensMarkupModelListener private constructor(editor: Editor) : Mar
|
|||||||
highlighters.forEach(::showIfValid)
|
highlighters.forEach(::showIfValid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
|
||||||
|
return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { severityFilter.test(it.severity) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun runWithHighlighterIfValid(highlighter: RangeHighlighter, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) {
|
||||||
|
val info = getHighlightInfoIfValid(highlighter)
|
||||||
|
if (info != null) {
|
||||||
|
processHighlighterWithInfo(HighlighterWithInfo.from(highlighter, info), actionForImmediate, actionForAsync)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getHighlightInfoIfValid(highlighter: RangeHighlighter): HighlightInfo? {
|
||||||
|
return highlighter.takeIf { it.isValid }?.let(::getFilteredHighlightInfo)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val EDITOR_KEY = Key<LensMarkupModelListener>(LensMarkupModelListener::class.java.name)
|
private val EDITOR_KEY = Key<LensMarkupModelListener>(LensMarkupModelListener::class.java.name)
|
||||||
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
|
||||||
|
|
||||||
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
|
|
||||||
return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { it.severity.myVal >= MINIMUM_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) {
|
private inline fun processHighlighterWithInfo(highlighterWithInfo: HighlighterWithInfo, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) {
|
||||||
if (highlighterWithInfo is HighlighterWithInfo.Async) {
|
if (highlighterWithInfo is HighlighterWithInfo.Async) {
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
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> {
|
||||||
|
override fun test(severity: HighlightSeverity): Boolean {
|
||||||
|
return severity.myVal >= MINIMUM_SEVERITY && severity.name !in disabledSeverities
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.chylex.intellij.inspectionlens.settings
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.daemon.impl.SeverityRegistrar
|
||||||
|
import com.intellij.lang.annotation.HighlightSeverity
|
||||||
|
import com.intellij.openapi.components.service
|
||||||
|
import com.intellij.openapi.options.BoundConfigurable
|
||||||
|
import com.intellij.openapi.options.ConfigurableWithId
|
||||||
|
import com.intellij.openapi.ui.DialogPanel
|
||||||
|
import com.intellij.ui.components.JBCheckBox
|
||||||
|
import com.intellij.ui.dsl.builder.Cell
|
||||||
|
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 {
|
||||||
|
return ID
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createPanel(): DialogPanel {
|
||||||
|
val settings = service<LensSettingsState>().state
|
||||||
|
|
||||||
|
return panel {
|
||||||
|
group("Enabled Severities") {
|
||||||
|
val knownSeverities = globalSeverities().sortedByDescending(HighlightSeverity::myVal)
|
||||||
|
|
||||||
|
for (severity in knownSeverities) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) })
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.chylex.intellij.inspectionlens.settings
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.editor.LensSeverityFilter
|
||||||
|
import com.intellij.openapi.components.service
|
||||||
|
|
||||||
|
object LensSettings {
|
||||||
|
private val state
|
||||||
|
get() = service<LensSettingsState>().state
|
||||||
|
|
||||||
|
fun createSeverityFilter(): LensSeverityFilter {
|
||||||
|
return LensSeverityFilter(state.disabledSeveritiesReadOnly)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.chylex.intellij.inspectionlens.settings
|
||||||
|
|
||||||
|
import com.intellij.openapi.components.BaseState
|
||||||
|
import com.intellij.openapi.components.SettingsCategory
|
||||||
|
import com.intellij.openapi.components.SimplePersistentStateComponent
|
||||||
|
import com.intellij.openapi.components.State
|
||||||
|
import com.intellij.openapi.components.Storage
|
||||||
|
import com.intellij.util.xmlb.annotations.XCollection
|
||||||
|
|
||||||
|
@State(
|
||||||
|
name = LensApplicationConfigurable.ID,
|
||||||
|
storages = [ Storage("chylex.inspectionLens.xml") ],
|
||||||
|
category = SettingsCategory.UI
|
||||||
|
)
|
||||||
|
class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State>(State()) {
|
||||||
|
class State : BaseState() {
|
||||||
|
@get:XCollection
|
||||||
|
private val disabledSeverities by stringSet()
|
||||||
|
|
||||||
|
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() }
|
||||||
|
}
|
||||||
|
}
|
@ -63,6 +63,14 @@
|
|||||||
<depends>com.intellij.modules.platform</depends>
|
<depends>com.intellij.modules.platform</depends>
|
||||||
<depends optional="true" config-file="compatibility/InspectionLens-Grazie.xml">tanvd.grazi</depends>
|
<depends optional="true" config-file="compatibility/InspectionLens-Grazie.xml">tanvd.grazi</depends>
|
||||||
|
|
||||||
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<applicationService serviceImplementation="com.chylex.intellij.inspectionlens.settings.LensSettingsState" />
|
||||||
|
<applicationConfigurable id="com.chylex.intellij.inspectionlens.settings.LensApplicationConfigurable"
|
||||||
|
instance="com.chylex.intellij.inspectionlens.settings.LensApplicationConfigurable"
|
||||||
|
displayName="Inspection Lens"
|
||||||
|
parentId="tools" />
|
||||||
|
</extensions>
|
||||||
|
|
||||||
<applicationListeners>
|
<applicationListeners>
|
||||||
<listener class="com.chylex.intellij.inspectionlens.InspectionLensPluginListener" topic="com.intellij.ide.plugins.DynamicPluginListener" />
|
<listener class="com.chylex.intellij.inspectionlens.InspectionLensPluginListener" topic="com.intellij.ide.plugins.DynamicPluginListener" />
|
||||||
</applicationListeners>
|
</applicationListeners>
|
||||||
|
Loading…
Reference in New Issue
Block a user