1
0
mirror of https://github.com/chylex/IntelliJ-Inspection-Lens.git synced 2025-04-25 09:15:48 +02:00

Add option to use UI font for lenses

Closes 
This commit is contained in:
chylex 2024-08-12 14:06:59 +02:00
parent c1b52ec3a5
commit 624254fba3
Signed by: chylex
SSH Key Fingerprint: SHA256:WqM8X/1DDn11LbYM0H5wsqZUjbcKxVsic37L+ERcF4o
7 changed files with 33 additions and 13 deletions

View File

@ -1,14 +1,15 @@
package com.chylex.intellij.inspectionlens.editor
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.openapi.editor.Editor
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
if (!inlay.tryUpdate(info)) {
inlay = EditorLensInlay.show(editor, info) ?: return false
inlay = EditorLensInlay.show(editor, info, settings) ?: return false
}
if (lineBackground.shouldRecreate(info)) {
@ -27,8 +28,8 @@ internal class EditorLens private constructor(private var inlay: EditorLensInlay
}
companion object {
fun show(editor: Editor, info: HighlightInfo): EditorLens? {
val inlay = EditorLensInlay.show(editor, info) ?: return null
fun show(editor: Editor, info: HighlightInfo, settings: LensSettingsState): EditorLens? {
val inlay = EditorLensInlay.show(editor, info, settings) ?: return null
val lineBackground = EditorLensLineBackground.show(editor, info)
return EditorLens(inlay, lineBackground)
}

View File

@ -1,5 +1,6 @@
package com.chylex.intellij.inspectionlens.editor
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.Inlay
@ -25,12 +26,15 @@ internal value class EditorLensInlay(private val inlay: Inlay<LensRenderer>) {
}
companion object {
fun show(editor: Editor, info: HighlightInfo): EditorLensInlay? {
fun show(editor: Editor, info: HighlightInfo, settings: LensSettingsState): EditorLensInlay? {
val offset = getInlayHintOffset(info)
val priority = getInlayHintPriority(editor, info)
val renderer = LensRenderer(info, settings)
val renderer = LensRenderer(info)
val properties = InlayProperties().relatesToPrecedingText(true).disableSoftWrapping(true).priority(priority)
val properties = InlayProperties()
.relatesToPrecedingText(true)
.disableSoftWrapping(true)
.priority(priority)
return editor.inlayModel.addAfterLineEndElement(offset, properties, renderer)?.let(::EditorLensInlay)
}

View File

@ -1,5 +1,7 @@
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.markup.RangeHighlighter
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 settings = service<LensSettingsState>()
private fun show(highlighterWithInfo: HighlighterWithInfo) {
val (highlighter, info) = highlighterWithInfo
@ -36,14 +39,14 @@ class EditorLensManager private constructor(private val editor: Editor) {
val existingLens = lenses[highlighter]
if (existingLens != null) {
if (existingLens.update(info)) {
if (existingLens.update(info, settings)) {
return
}
existingLens.hide()
}
val newLens = EditorLens.show(editor, info)
val newLens = EditorLens.show(editor, info, settings)
if (newLens != null) {
lenses[highlighter] = newLens
}

View File

@ -17,7 +17,7 @@ import com.intellij.openapi.util.Key
* Listens for inspection highlights and reports them to [EditorLensManager].
*/
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))
override fun afterAdded(highlighter: RangeHighlighterEx) {
@ -55,7 +55,7 @@ internal class LensMarkupModelListener private constructor(editor: Editor) : Mar
}
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) {

View File

@ -1,5 +1,6 @@
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.HintRenderer
import com.intellij.openapi.editor.Editor
@ -12,7 +13,8 @@ import java.awt.Rectangle
/**
* 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
init {
@ -34,7 +36,7 @@ class LensRenderer(info: HighlightInfo) : HintRenderer(null) {
}
override fun useEditorFont(): Boolean {
return true
return useEditorFont
}
private companion object {

View File

@ -89,6 +89,12 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
checkBox("Other").bindSelected(settings::showUnknownSeverities)
}
}
group("Appearance") {
row {
checkBox("Use editor font").bindSelected(settings::useEditorFont)
}
}
}
}

View File

@ -20,6 +20,7 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
val hiddenSeverities by map<String, StoredSeverity>()
var showUnknownSeverities by property(true)
var useEditorFont by property(true)
}
@get:Synchronized
@ -27,6 +28,9 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
var severityFilter = createSeverityFilter()
private set
val useEditorFont
get() = state.useEditorFont
override fun loadState(state: State) {
super.loadState(state)
update()