diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLens.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLens.kt index 485791c..e05bacc 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLens.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLens.kt @@ -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) } diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensInlay.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensInlay.kt index 3adb149..5c31c38 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensInlay.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensInlay.kt @@ -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) } diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensManager.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensManager.kt index fc20759..bddce15 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensManager.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/EditorLensManager.kt @@ -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 } diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt index 1f44d70..d2c5573 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensMarkupModelListener.kt @@ -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) { diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensRenderer.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensRenderer.kt index 1f58467..114f9c5 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensRenderer.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/editor/LensRenderer.kt @@ -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 { diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt index 850e524..5c9760f 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensApplicationConfigurable.kt @@ -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) + } + } } } diff --git a/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensSettingsState.kt b/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensSettingsState.kt index c376aa2..6a625ac 100644 --- a/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensSettingsState.kt +++ b/src/main/kotlin/com/chylex/intellij/inspectionlens/settings/LensSettingsState.kt @@ -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()