mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2025-05-04 17:34:07 +02:00
parent
c1b52ec3a5
commit
624254fba3
src/main/kotlin/com/chylex/intellij/inspectionlens
@ -1,14 +1,15 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
|
||||||
internal class EditorLens private constructor(private var inlay: EditorLensInlay, private var lineBackground: EditorLensLineBackground) {
|
internal class EditorLens private constructor(private var inlay: EditorLensInlay, private var lineBackground: EditorLensLineBackground) {
|
||||||
fun update(info: HighlightInfo): Boolean {
|
fun update(info: HighlightInfo, settings: LensSettingsState): Boolean {
|
||||||
val editor = inlay.editor
|
val editor = inlay.editor
|
||||||
|
|
||||||
if (!inlay.tryUpdate(info)) {
|
if (!inlay.tryUpdate(info)) {
|
||||||
inlay = EditorLensInlay.show(editor, info) ?: return false
|
inlay = EditorLensInlay.show(editor, info, settings) ?: return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lineBackground.shouldRecreate(info)) {
|
if (lineBackground.shouldRecreate(info)) {
|
||||||
@ -27,8 +28,8 @@ internal class EditorLens private constructor(private var inlay: EditorLensInlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun show(editor: Editor, info: HighlightInfo): EditorLens? {
|
fun show(editor: Editor, info: HighlightInfo, settings: LensSettingsState): EditorLens? {
|
||||||
val inlay = EditorLensInlay.show(editor, info) ?: return null
|
val inlay = EditorLensInlay.show(editor, info, settings) ?: return null
|
||||||
val lineBackground = EditorLensLineBackground.show(editor, info)
|
val lineBackground = EditorLensLineBackground.show(editor, info)
|
||||||
return EditorLens(inlay, lineBackground)
|
return EditorLens(inlay, lineBackground)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.Inlay
|
import com.intellij.openapi.editor.Inlay
|
||||||
@ -25,12 +26,15 @@ internal value class EditorLensInlay(private val inlay: Inlay<LensRenderer>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun show(editor: Editor, info: HighlightInfo): EditorLensInlay? {
|
fun show(editor: Editor, info: HighlightInfo, settings: LensSettingsState): EditorLensInlay? {
|
||||||
val offset = getInlayHintOffset(info)
|
val offset = getInlayHintOffset(info)
|
||||||
val priority = getInlayHintPriority(editor, info)
|
val priority = getInlayHintPriority(editor, info)
|
||||||
|
val renderer = LensRenderer(info, settings)
|
||||||
|
|
||||||
val renderer = LensRenderer(info)
|
val properties = InlayProperties()
|
||||||
val properties = InlayProperties().relatesToPrecedingText(true).disableSoftWrapping(true).priority(priority)
|
.relatesToPrecedingText(true)
|
||||||
|
.disableSoftWrapping(true)
|
||||||
|
.priority(priority)
|
||||||
|
|
||||||
return editor.inlayModel.addAfterLineEndElement(offset, properties, renderer)?.let(::EditorLensInlay)
|
return editor.inlayModel.addAfterLineEndElement(offset, properties, renderer)?.let(::EditorLensInlay)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
|
||||||
|
import com.intellij.openapi.components.service
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.markup.RangeHighlighter
|
import com.intellij.openapi.editor.markup.RangeHighlighter
|
||||||
import com.intellij.openapi.util.Key
|
import com.intellij.openapi.util.Key
|
||||||
@ -26,6 +28,7 @@ class EditorLensManager private constructor(private val editor: Editor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val lenses = IdentityHashMap<RangeHighlighter, EditorLens>()
|
private val lenses = IdentityHashMap<RangeHighlighter, EditorLens>()
|
||||||
|
private val settings = service<LensSettingsState>()
|
||||||
|
|
||||||
private fun show(highlighterWithInfo: HighlighterWithInfo) {
|
private fun show(highlighterWithInfo: HighlighterWithInfo) {
|
||||||
val (highlighter, info) = highlighterWithInfo
|
val (highlighter, info) = highlighterWithInfo
|
||||||
@ -36,14 +39,14 @@ class EditorLensManager private constructor(private val editor: Editor) {
|
|||||||
|
|
||||||
val existingLens = lenses[highlighter]
|
val existingLens = lenses[highlighter]
|
||||||
if (existingLens != null) {
|
if (existingLens != null) {
|
||||||
if (existingLens.update(info)) {
|
if (existingLens.update(info, settings)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
existingLens.hide()
|
existingLens.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
val newLens = EditorLens.show(editor, info)
|
val newLens = EditorLens.show(editor, info, settings)
|
||||||
if (newLens != null) {
|
if (newLens != null) {
|
||||||
lenses[highlighter] = newLens
|
lenses[highlighter] = newLens
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import com.intellij.openapi.util.Key
|
|||||||
* Listens for inspection highlights and reports them to [EditorLensManager].
|
* Listens for inspection highlights and reports them to [EditorLensManager].
|
||||||
*/
|
*/
|
||||||
internal class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener {
|
internal class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener {
|
||||||
private val settingsService = service<LensSettingsState>()
|
private val settings = service<LensSettingsState>()
|
||||||
private val lensManagerDispatcher = EditorLensManagerDispatcher(EditorLensManager.getOrCreate(editor))
|
private val lensManagerDispatcher = EditorLensManagerDispatcher(EditorLensManager.getOrCreate(editor))
|
||||||
|
|
||||||
override fun afterAdded(highlighter: RangeHighlighterEx) {
|
override fun afterAdded(highlighter: RangeHighlighterEx) {
|
||||||
@ -55,7 +55,7 @@ internal class LensMarkupModelListener private constructor(editor: Editor) : Mar
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
|
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
|
||||||
return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { settingsService.severityFilter.test(it.severity) }
|
return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { settings.severityFilter.test(it.severity) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun runWithHighlighterIfValid(highlighter: RangeHighlighter, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) {
|
private inline fun runWithHighlighterIfValid(highlighter: RangeHighlighter, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.codeInsight.daemon.impl.HintRenderer
|
import com.intellij.codeInsight.daemon.impl.HintRenderer
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
@ -12,7 +13,8 @@ import java.awt.Rectangle
|
|||||||
/**
|
/**
|
||||||
* Renders the text of an inspection lens.
|
* Renders the text of an inspection lens.
|
||||||
*/
|
*/
|
||||||
class LensRenderer(info: HighlightInfo) : HintRenderer(null) {
|
class LensRenderer(info: HighlightInfo, settings: LensSettingsState) : HintRenderer(null) {
|
||||||
|
private val useEditorFont = settings.useEditorFont
|
||||||
private lateinit var severity: LensSeverity
|
private lateinit var severity: LensSeverity
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -34,7 +36,7 @@ class LensRenderer(info: HighlightInfo) : HintRenderer(null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun useEditorFont(): Boolean {
|
override fun useEditorFont(): Boolean {
|
||||||
return true
|
return useEditorFont
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
@ -89,6 +89,12 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
|
|||||||
checkBox("Other").bindSelected(settings::showUnknownSeverities)
|
checkBox("Other").bindSelected(settings::showUnknownSeverities)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group("Appearance") {
|
||||||
|
row {
|
||||||
|
checkBox("Use editor font").bindSelected(settings::useEditorFont)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
|
|||||||
val hiddenSeverities by map<String, StoredSeverity>()
|
val hiddenSeverities by map<String, StoredSeverity>()
|
||||||
|
|
||||||
var showUnknownSeverities by property(true)
|
var showUnknownSeverities by property(true)
|
||||||
|
var useEditorFont by property(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:Synchronized
|
@get:Synchronized
|
||||||
@ -27,6 +28,9 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
|
|||||||
var severityFilter = createSeverityFilter()
|
var severityFilter = createSeverityFilter()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
val useEditorFont
|
||||||
|
get() = state.useEditorFont
|
||||||
|
|
||||||
override fun loadState(state: State) {
|
override fun loadState(state: State) {
|
||||||
super.loadState(state)
|
super.loadState(state)
|
||||||
update()
|
update()
|
||||||
|
Loading…
Reference in New Issue
Block a user