1
0
mirror of https://github.com/chylex/IntelliJ-Inspection-Lens.git synced 2026-02-12 00:06:36 +01:00

7 Commits

12 changed files with 164 additions and 81 deletions

View File

@@ -6,7 +6,7 @@ plugins {
}
group = "com.chylex.intellij.inspectionlens"
version = "1.5.2"
version = "1.6.1"
repositories {
mavenCentral()
@@ -18,7 +18,7 @@ repositories {
dependencies {
intellijPlatform {
intellijIdeaUltimate("2024.2")
intellijIdeaUltimate("261.17801.55-EAP", useInstaller = false)
bundledPlugin("tanvd.grazi")
}
@@ -44,7 +44,7 @@ intellijPlatform {
}
kotlin {
jvmToolchain(17)
jvmToolchain(25)
compilerOptions {
freeCompilerArgs = listOf(

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

View File

@@ -2,7 +2,7 @@ rootProject.name = "InspectionLens"
pluginManagement {
plugins {
kotlin("jvm") version "1.9.24" // https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#bundled-stdlib-versions
id("org.jetbrains.intellij.platform") version "2.6.0" // https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
kotlin("jvm") version "2.3.0" // https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#bundled-stdlib-versions
id("org.jetbrains.intellij.platform") version "2.10.5" // https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
}
}

View File

@@ -2,11 +2,11 @@ package com.chylex.intellij.inspectionlens
import com.chylex.intellij.inspectionlens.editor.EditorLensFeatures
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.project.ProjectManager
import java.util.concurrent.atomic.AtomicBoolean
/**
* Handles installation and uninstallation of plugin features in editors.
@@ -16,27 +16,31 @@ internal object InspectionLens {
val LOG = logger<InspectionLens>()
var SHOW_LENSES = true
set(value) {
field = value
scheduleRefresh()
}
/**
* Installs lenses into [editor].
*/
fun install(editor: TextEditor) {
EditorLensFeatures.install(editor.editor, service<InspectionLensPluginDisposableService>().intersect(editor))
EditorLensFeatures.install(editor)
}
/**
* Installs lenses into all open editors.
*/
fun install() {
forEachOpenEditor(::install)
forEachOpenEditor(EditorLensFeatures::install)
}
/**
* Refreshes lenses in all open editors.
*/
private fun refresh() {
forEachOpenEditor {
EditorLensFeatures.refresh(it.editor)
}
forEachOpenEditor(EditorLensFeatures::refresh)
}
/**
@@ -52,31 +56,31 @@ internal object InspectionLens {
private inline fun forEachOpenEditor(action: (TextEditor) -> Unit) {
val projectManager = ProjectManager.getInstanceIfCreated() ?: return
for (project in projectManager.openProjects.filterNot { it.isDisposed }) {
for (editor in FileEditorManager.getInstance(project).allEditors.filterIsInstance<TextEditor>()) {
action(editor)
for (project in projectManager.openProjects) {
if (project.isDisposed) {
continue
}
for (editor in FileEditorManager.getInstance(project).allEditors) {
if (editor is TextEditor) {
action(editor)
}
}
}
}
private object Refresh {
private var needsRefresh = false
private object Refresh : Runnable {
private val needsRefresh = AtomicBoolean(false)
fun schedule() {
synchronized(this) {
if (!needsRefresh) {
needsRefresh = true
ApplicationManager.getApplication().invokeLater(this::run)
}
if (needsRefresh.compareAndSet(false, true)) {
ApplicationManager.getApplication().invokeLater(this)
}
}
private fun run() {
synchronized(this) {
if (needsRefresh) {
needsRefresh = false
refresh()
}
override fun run() {
if (needsRefresh.compareAndSet(true, false)) {
refresh()
}
}
}

View File

@@ -0,0 +1,22 @@
package com.chylex.intellij.inspectionlens
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.fileEditor.FileOpenedSyncListener
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.vfs.VirtualFile
/**
* Installs [InspectionLens] in opened editors.
*
* Used instead of [FileOpenedSyncListener], because [FileOpenedSyncListener] randomly fails to register during IDE startup.
*/
class InspectionLensFileEditorManagerListener : FileEditorManagerListener {
override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
for (editor in source.getEditors(file)) {
if (editor is TextEditor) {
InspectionLens.install(editor)
}
}
}
}

View File

@@ -1,21 +0,0 @@
package com.chylex.intellij.inspectionlens
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileOpenedSyncListener
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.fileEditor.ex.FileEditorWithProvider
import com.intellij.openapi.vfs.VirtualFile
/**
* Installs [InspectionLens] in newly opened editors.
*/
class InspectionLensFileOpenedListener : FileOpenedSyncListener {
override fun fileOpenedSync(source: FileEditorManager, file: VirtualFile, editorsWithProviders: List<FileEditorWithProvider>) {
for (editorWrapper in editorsWithProviders) {
val fileEditor = editorWrapper.fileEditor
if (fileEditor is TextEditor) {
InspectionLens.install(fileEditor)
}
}
}
}

View File

@@ -0,0 +1,25 @@
package com.chylex.intellij.inspectionlens.actions
import com.chylex.intellij.inspectionlens.InspectionLens
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.KeepPopupOnPerform
import com.intellij.openapi.project.DumbAwareToggleAction
class ToggleLensVisibilityAction : DumbAwareToggleAction() {
init {
templatePresentation.keepPopupOnPerform = KeepPopupOnPerform.IfRequested
}
override fun getActionUpdateThread(): ActionUpdateThread {
return ActionUpdateThread.BGT
}
override fun isSelected(e: AnActionEvent): Boolean {
return InspectionLens.SHOW_LENSES
}
override fun setSelected(e: AnActionEvent, state: Boolean) {
InspectionLens.SHOW_LENSES = state
}
}

View File

@@ -1,10 +1,13 @@
package com.chylex.intellij.inspectionlens.editor
import com.chylex.intellij.inspectionlens.InspectionLensPluginDisposableService
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.FoldingModelEx
import com.intellij.openapi.editor.ex.MarkupModelEx
import com.intellij.openapi.editor.impl.DocumentMarkupModel
import com.intellij.openapi.fileEditor.TextEditor
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.Key
@@ -36,21 +39,24 @@ internal class EditorLensFeatures private constructor(
companion object {
private val EDITOR_KEY = Key<EditorLensFeatures>(EditorLensFeatures::class.java.name)
fun install(editor: Editor, disposable: Disposable) {
fun install(owner: TextEditor) {
val editor = owner.editor
if (editor.getUserData(EDITOR_KEY) != null) {
return
}
val markupModel = DocumentMarkupModel.forDocument(editor.document, editor.project, false) as? MarkupModelEx ?: return
val foldingModel = editor.foldingModel as? FoldingModelEx
val disposable = service<InspectionLensPluginDisposableService>().intersect(owner)
val features = EditorLensFeatures(editor, markupModel, foldingModel, disposable)
editor.putUserData(EDITOR_KEY, features)
Disposer.register(disposable) { editor.putUserData(EDITOR_KEY, null) }
}
fun refresh(editor: Editor) {
editor.getUserData(EDITOR_KEY)?.refresh()
fun refresh(owner: TextEditor) {
owner.editor.getUserData(EDITOR_KEY)?.refresh()
}
}
}

View File

@@ -15,8 +15,11 @@ internal class EditorLensManager(private val editor: Editor) {
private val settings = service<LensSettingsState>()
private fun show(highlighterWithInfo: HighlighterWithInfo) {
val (highlighter, info) = highlighterWithInfo
if (editor.isDisposed) {
return
}
val (highlighter, info) = highlighterWithInfo
if (!highlighter.isValid) {
return
}

View File

@@ -1,8 +1,9 @@
package com.chylex.intellij.inspectionlens.editor
import com.chylex.intellij.inspectionlens.InspectionLens
import com.chylex.intellij.inspectionlens.settings.LensSettingsState
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil
import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil.isFileLevelOrGutterAnnotation
import com.intellij.openapi.components.service
import com.intellij.openapi.editor.ex.RangeHighlighterEx
import com.intellij.openapi.editor.impl.event.MarkupModelListener
@@ -22,43 +23,30 @@ internal class LensMarkupModelListener(private val lensManagerDispatcher: Editor
showIfValid(highlighter)
}
override fun beforeRemoved(highlighter: RangeHighlighterEx) {
if (getFilteredHighlightInfo(highlighter) != null) {
lensManagerDispatcher.hide(highlighter)
fun showAllValid(highlighters: Array<RangeHighlighter>) {
if (InspectionLens.SHOW_LENSES) {
highlighters.forEach(::showIfValid)
}
}
private fun showIfValid(highlighter: RangeHighlighter) {
runWithHighlighterIfValid(highlighter, lensManagerDispatcher::show, ::showAsynchronously)
}
private fun showAsynchronously(highlighterWithInfo: HighlighterWithInfo.Async) {
highlighterWithInfo.requestDescription {
if (highlighterWithInfo.highlighter.isValid && highlighterWithInfo.hasDescription) {
lensManagerDispatcher.show(highlighterWithInfo)
}
if (!InspectionLens.SHOW_LENSES) {
return
}
}
fun showAllValid(highlighters: Array<RangeHighlighter>) {
highlighters.forEach(::showIfValid)
}
val info = highlighter.takeIf { it.isValid }?.let(::getFilteredHighlightInfo)
if (info == null || isFileLevelOrGutterAnnotation(info)) {
return
}
fun hideAll() {
lensManagerDispatcher.hideAll()
val highlighterWithInfo = HighlighterWithInfo.from(highlighter, info)
processHighlighterWithInfo(highlighterWithInfo, lensManagerDispatcher::show, ::showAsynchronously)
}
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
return HighlightInfo.fromRangeHighlighter(highlighter)?.takeIf { settings.severityFilter.test(it.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 && !UpdateHighlightersUtil.isFileLevelOrGutterAnnotation(info)) {
processHighlighterWithInfo(HighlighterWithInfo.from(highlighter, info), actionForImmediate, actionForAsync)
}
}
private inline fun processHighlighterWithInfo(highlighterWithInfo: HighlighterWithInfo, actionForImmediate: (HighlighterWithInfo) -> Unit, actionForAsync: (HighlighterWithInfo.Async) -> Unit) {
if (highlighterWithInfo is HighlighterWithInfo.Async) {
actionForAsync(highlighterWithInfo)
@@ -67,4 +55,22 @@ internal class LensMarkupModelListener(private val lensManagerDispatcher: Editor
actionForImmediate(highlighterWithInfo)
}
}
private fun showAsynchronously(highlighterWithInfo: HighlighterWithInfo.Async) {
highlighterWithInfo.requestDescription {
if (highlighterWithInfo.highlighter.isValid && highlighterWithInfo.hasDescription) {
lensManagerDispatcher.show(highlighterWithInfo)
}
}
}
override fun beforeRemoved(highlighter: RangeHighlighterEx) {
if (getFilteredHighlightInfo(highlighter) != null) {
lensManagerDispatcher.hide(highlighter)
}
}
fun hideAll() {
lensManagerDispatcher.hideAll()
}
}

View File

@@ -14,6 +14,10 @@ internal value class EditorLensLineBackground(private val highlighter: RangeHigh
get() = !highlighter.isValid
fun onFoldRegionsChanged(editor: Editor, severity: LensSeverity) {
if (isInvalid) {
return
}
if (highlighter is RangeHighlighterEx) {
highlighter.textAttributes = getAttributes(editor, highlighter.startOffset, highlighter.endOffset, severity)
}

View File

@@ -14,17 +14,34 @@
]]></description>
<change-notes><![CDATA[
<b>Version 1.6.1</b>
<ul>
<li>Fixed exception caused by accessing disposed editors.</li>
<li>Fixed exception caused by accessing disposed line background highlighters.</li>
</ul>
<br>
<b>Version 1.6.0</b>
<ul>
<li>Added action to <b>View | Show Inspection Lenses</b> that temporarily toggles visibility of all inspections.</li>
<li>File-wide inspections no longer appear.</li>
<li>Fixed quick fix popup disappearing when the floating toolbar is enabled.</li>
<li>Clicking an inspection now only shows relevant quick fixes (not supported for ReSharper-based languages, which use a non-standard popup).</li>
<li>Tried to work around an issue where the IDE randomly fails to load the plugin.</li>
</ul>
<br>
<b>Version 1.5.2</b>
<ul>
<li>Added option to change maximum description length.</li>
<li>Added button to <b>Settings | Tools | Inspection Lens</b> that resets all settings to default.</li>
</ul>
<br>
<b>Version 1.5.1</b>
<ul>
<li>Added option to change the behavior of clicking on inspections.</li>
<li>Fixed broken quick fixes in Rider and CLion Nova.</li>
<li>Fixed hover underline not rendering correctly with some combinations of high DPI and line height settings.</li>
</ul>
<br>
<b>Version 1.5</b>
<ul>
<li>Added possibility to left-click an inspection to show quick fixes.</li>
@@ -34,51 +51,62 @@
<li>Improved descriptions of Kotlin compiler inspections.</li>
<li>Fixed visual artifacts in Rendered Doc comments.</li>
</ul>
<br>
<b>Version 1.4.1</b>
<ul>
<li>Fixed warnings in usage of IntelliJ SDK.</li>
</ul>
<br>
<b>Version 1.4</b>
<ul>
<li>Added configuration of visible severities to <b>Settings | Tools | Inspection Lens</b>.</li>
</ul>
<br>
<b>Version 1.3.3</b>
<ul>
<li>Partially reverted fix for inspections that include HTML in their description due to breaking inspections with angled brackets.</li>
<li>Fixed plugin not working when installed on JetBrains Gateway Client.</li>
</ul>
<br>
<b>Version 1.3.2</b>
<ul>
<li>Fixed inspections randomly not disappearing.</li>
</ul>
<br>
<b>Version 1.3.1</b>
<ul>
<li>Updated minimum version to IntelliJ 2023.3 due to breaking API changes.</li>
</ul>
<br>
<b>Version 1.3.0</b>
<ul>
<li>Added background colors to lines containing inspections. (<a href="https://github.com/chylex/IntelliJ-Inspection-Lens/pull/15">PR #15</a> by <a href="https://github.com/synopss">synopss</a>)</li>
</ul>
<br>
<b>Version 1.2.0</b>
<ul>
<li>Support for IntelliJ 2023.2 EAP.</li>
<li>Added distinct colors for typos and Grazie inspections.</li>
</ul>
<br>
<b>Version 1.1.2</b>
<ul>
<li>Added plugin icon.</li>
<li>Updated minimum version to IntelliJ 2023.1 due to deprecated APIs.</li>
</ul>
<br>
<b>Version 1.1.1</b>
<ul>
<li>Multiple inspections at the same place in the document are now ordered by severity.</li>
<li>Improved performance of processing inspections which do not contain HTML.</li>
</ul>
<br>
<b>Version 1.1.0</b>
<ul>
<li>Fixed showing inspections that include HTML in their description. (<a href="https://github.com/chylex/IntelliJ-Inspection-Lens/pull/3">PR #3</a> by <a href="https://github.com/KostkaBrukowa">KostkaBrukowa</a>)</li>
<li>Fixed exception when asynchronous inspections run on a non-EDT thread.</li>
</ul>
<br>
<b>Version 1.0.0</b>
<ul>
<li>Initial version with support for IntelliJ 2022.2 and newer.</li>
@@ -96,11 +124,17 @@
parentId="tools" />
</extensions>
<actions>
<action id="chylex.InspectionLens.ToggleLensVisibility" class="com.chylex.intellij.inspectionlens.actions.ToggleLensVisibilityAction" text="Show Inspection Lenses">
<add-to-group group-id="ViewMenu" anchor="after" relative-to-action="EditorResetFontSizeGlobal" />
</action>
</actions>
<applicationListeners>
<listener class="com.chylex.intellij.inspectionlens.InspectionLensPluginListener" topic="com.intellij.ide.plugins.DynamicPluginListener" />
</applicationListeners>
<projectListeners>
<listener class="com.chylex.intellij.inspectionlens.InspectionLensFileOpenedListener" topic="com.intellij.openapi.fileEditor.FileOpenedSyncListener" />
<listener class="com.chylex.intellij.inspectionlens.InspectionLensFileEditorManagerListener" topic="com.intellij.openapi.fileEditor.FileEditorManagerListener" />
</projectListeners>
</idea-plugin>