mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2024-11-26 01:42:52 +01:00
Compare commits
5 Commits
44f2fa5c16
...
443b2b9a2d
Author | SHA1 | Date | |
---|---|---|---|
443b2b9a2d | |||
e96961e10a | |||
7432c57e95 | |||
0f49339ca2 | |||
13f3002366 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,8 +1,5 @@
|
|||||||
/.idea/*
|
/.idea/*
|
||||||
!/.idea/compiler.xml
|
!/.idea/runConfigurations
|
||||||
!/.idea/encodings.xml
|
|
||||||
!/.idea/gradle.xml
|
|
||||||
!/.idea/vcs.xml
|
|
||||||
|
|
||||||
/.gradle/
|
/.gradle/
|
||||||
/build/
|
/build/
|
||||||
|
5
.idea/.gitignore
vendored
5
.idea/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="11" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
|
||||||
<file url="PROJECT" charset="UTF-8" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
|
||||||
<component name="GradleSettings">
|
|
||||||
<option name="linkedExternalProjectsSettings">
|
|
||||||
<GradleProjectSettings>
|
|
||||||
<option name="delegatedBuild" value="true" />
|
|
||||||
<option name="testRunner" value="GRADLE" />
|
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="modules">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</GradleProjectSettings>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GitSharedSettings">
|
|
||||||
<option name="FORCE_PUSH_PROHIBITED_PATTERNS">
|
|
||||||
<list />
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.chylex.intellij.inspectionlens"
|
group = "com.chylex.intellij.inspectionlens"
|
||||||
version = "1.1.2"
|
version = "1.2.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@ -18,9 +18,15 @@ dependencies {
|
|||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.9.0")
|
testImplementation("org.junit.jupiter:junit-jupiter:5.9.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvmToolchain(17)
|
||||||
|
}
|
||||||
|
|
||||||
intellij {
|
intellij {
|
||||||
version.set("2023.1")
|
version.set("2023.1")
|
||||||
updateSinceUntilBuild.set(false)
|
updateSinceUntilBuild.set(false)
|
||||||
|
|
||||||
|
plugins.add("tanvd.grazi")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.patchPluginXml {
|
tasks.patchPluginXml {
|
||||||
@ -36,8 +42,7 @@ tasks.test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<KotlinCompile> {
|
tasks.withType<KotlinCompile> {
|
||||||
kotlinOptions.jvmTarget = "17"
|
|
||||||
kotlinOptions.freeCompilerArgs = listOf(
|
kotlinOptions.freeCompilerArgs = listOf(
|
||||||
"-Xjvm-default=enable"
|
"-Xjvm-default=all"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.chylex.intellij.inspectionlens
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.editor.EditorInlayLensManager
|
||||||
|
import com.chylex.intellij.inspectionlens.editor.LensMarkupModelListener
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||||
|
import com.intellij.openapi.fileEditor.TextEditor
|
||||||
|
import com.intellij.openapi.project.ProjectManager
|
||||||
|
import com.intellij.openapi.rd.createLifetime
|
||||||
|
import com.intellij.openapi.rd.createNestedDisposable
|
||||||
|
import com.jetbrains.rd.util.lifetime.intersect
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles installation and uninstallation of plugin features in editors.
|
||||||
|
*/
|
||||||
|
internal object InspectionLens {
|
||||||
|
const val PLUGIN_ID = "com.chylex.intellij.inspectionlens"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs lenses into [editor].
|
||||||
|
*/
|
||||||
|
fun install(editor: TextEditor) {
|
||||||
|
LensMarkupModelListener.register(editor.editor, createEditorDisposable(editor))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs lenses into all open editors.
|
||||||
|
*/
|
||||||
|
fun install() {
|
||||||
|
forEachOpenEditor(::install)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uninstalls lenses from all open editors.
|
||||||
|
*/
|
||||||
|
fun uninstall() {
|
||||||
|
forEachOpenEditor {
|
||||||
|
EditorInlayLensManager.remove(it.editor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refreshes lenses in all open editors.
|
||||||
|
*/
|
||||||
|
fun refresh() {
|
||||||
|
forEachOpenEditor {
|
||||||
|
LensMarkupModelListener.refresh(it.editor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a [Disposable] that will be disposed when either the [TextEditor] is disposed or the plugin is unloaded.
|
||||||
|
*/
|
||||||
|
private fun createEditorDisposable(textEditor: TextEditor): Disposable {
|
||||||
|
val pluginLifetime = ApplicationManager.getApplication().getService(InspectionLensPluginDisposableService::class.java).createLifetime()
|
||||||
|
val editorLifetime = textEditor.createLifetime()
|
||||||
|
return pluginLifetime.intersect(editorLifetime).createNestedDisposable()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes [action] on all open editors.
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.chylex.intellij.inspectionlens
|
package com.chylex.intellij.inspectionlens
|
||||||
|
|
||||||
import com.chylex.intellij.inspectionlens.editor.LensMarkupModelListener
|
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||||
import com.intellij.openapi.fileEditor.FileOpenedSyncListener
|
import com.intellij.openapi.fileEditor.FileOpenedSyncListener
|
||||||
import com.intellij.openapi.fileEditor.TextEditor
|
import com.intellij.openapi.fileEditor.TextEditor
|
||||||
@ -8,14 +7,14 @@ import com.intellij.openapi.fileEditor.ex.FileEditorWithProvider
|
|||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for newly opened editors, and installs a [LensMarkupModelListener] on them.
|
* Installs [InspectionLens] in newly opened editors.
|
||||||
*/
|
*/
|
||||||
class InspectionLensFileOpenedListener : FileOpenedSyncListener {
|
class InspectionLensFileOpenedListener : FileOpenedSyncListener {
|
||||||
override fun fileOpenedSync(source: FileEditorManager, file: VirtualFile, editorsWithProviders: List<FileEditorWithProvider>) {
|
override fun fileOpenedSync(source: FileEditorManager, file: VirtualFile, editorsWithProviders: List<FileEditorWithProvider>) {
|
||||||
for (editorWrapper in editorsWithProviders) {
|
for (editorWrapper in editorsWithProviders) {
|
||||||
val fileEditor = editorWrapper.fileEditor
|
val fileEditor = editorWrapper.fileEditor
|
||||||
if (fileEditor is TextEditor) {
|
if (fileEditor is TextEditor) {
|
||||||
LensMarkupModelListener.install(fileEditor)
|
InspectionLens.install(fileEditor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,21 @@
|
|||||||
package com.chylex.intellij.inspectionlens
|
package com.chylex.intellij.inspectionlens
|
||||||
|
|
||||||
import com.chylex.intellij.inspectionlens.editor.EditorInlayLensManager
|
|
||||||
import com.chylex.intellij.inspectionlens.editor.LensMarkupModelListener
|
|
||||||
import com.intellij.ide.plugins.DynamicPluginListener
|
import com.intellij.ide.plugins.DynamicPluginListener
|
||||||
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
|
||||||
import com.intellij.openapi.fileEditor.TextEditor
|
|
||||||
import com.intellij.openapi.project.ProjectManager
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles dynamic plugin loading.
|
* Installs [InspectionLens] in open editors when the plugin is loaded, and uninstalls it when the plugin is unloaded.
|
||||||
*
|
|
||||||
* On load, it installs the [LensMarkupModelListener] to all open editors.
|
|
||||||
* On unload, it removes all lenses from all open editors.
|
|
||||||
*/
|
*/
|
||||||
class InspectionLensPluginListener : DynamicPluginListener {
|
class InspectionLensPluginListener : DynamicPluginListener {
|
||||||
companion object {
|
|
||||||
private const val PLUGIN_ID = "com.chylex.intellij.inspectionlens"
|
|
||||||
|
|
||||||
private inline fun ProjectManager.forEachEditor(action: (TextEditor) -> Unit) {
|
|
||||||
for (project in this.openProjects.filterNot { it.isDisposed }) {
|
|
||||||
val fileEditorManager = FileEditorManager.getInstance(project)
|
|
||||||
|
|
||||||
for (editor in fileEditorManager.allEditors.filterIsInstance<TextEditor>()) {
|
|
||||||
action(editor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun pluginLoaded(pluginDescriptor: IdeaPluginDescriptor) {
|
override fun pluginLoaded(pluginDescriptor: IdeaPluginDescriptor) {
|
||||||
if (pluginDescriptor.pluginId.idString == PLUGIN_ID) {
|
if (pluginDescriptor.pluginId.idString == InspectionLens.PLUGIN_ID) {
|
||||||
ProjectManager.getInstanceIfCreated()?.forEachEditor(LensMarkupModelListener.Companion::install)
|
InspectionLens.install()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforePluginUnload(pluginDescriptor: IdeaPluginDescriptor, isUpdate: Boolean) {
|
override fun beforePluginUnload(pluginDescriptor: IdeaPluginDescriptor, isUpdate: Boolean) {
|
||||||
if (pluginDescriptor.pluginId.idString == PLUGIN_ID) {
|
if (pluginDescriptor.pluginId.idString == InspectionLens.PLUGIN_ID) {
|
||||||
ProjectManager.getInstanceIfCreated()?.forEachEditor {
|
InspectionLens.uninstall()
|
||||||
EditorInlayLensManager.remove(it.editor)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.chylex.intellij.inspectionlens.compatibility
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.editor.LensSeverity
|
||||||
|
import com.intellij.grazie.ide.TextProblemSeverities
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.startup.ProjectActivity
|
||||||
|
|
||||||
|
class GrazieSupport : ProjectActivity {
|
||||||
|
override suspend fun execute(project: Project) {
|
||||||
|
LensSeverity.registerMapping(TextProblemSeverities.GRAMMAR_ERROR, LensSeverity.ERROR)
|
||||||
|
LensSeverity.registerMapping(TextProblemSeverities.STYLE_ERROR, LensSeverity.GRAZIE)
|
||||||
|
LensSeverity.registerMapping(TextProblemSeverities.STYLE_WARNING, LensSeverity.GRAZIE)
|
||||||
|
LensSeverity.registerMapping(TextProblemSeverities.STYLE_SUGGESTION, LensSeverity.GRAZIE)
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ import com.intellij.openapi.util.Key
|
|||||||
*/
|
*/
|
||||||
class EditorInlayLensManager private constructor(private val editor: Editor) {
|
class EditorInlayLensManager private constructor(private val editor: Editor) {
|
||||||
companion object {
|
companion object {
|
||||||
private val KEY = Key<EditorInlayLensManager>(EditorInlayLensManager::class.java.name)
|
private val EDITOR_KEY = Key<EditorInlayLensManager>(EditorInlayLensManager::class.java.name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Highest allowed severity for the purposes of sorting multiple highlights at the same offset.
|
* Highest allowed severity for the purposes of sorting multiple highlights at the same offset.
|
||||||
@ -22,14 +22,14 @@ class EditorInlayLensManager private constructor(private val editor: Editor) {
|
|||||||
private const val MAXIMUM_POSITION = ((Int.MAX_VALUE / MAXIMUM_SEVERITY) * 2) - 1
|
private const val MAXIMUM_POSITION = ((Int.MAX_VALUE / MAXIMUM_SEVERITY) * 2) - 1
|
||||||
|
|
||||||
fun getOrCreate(editor: Editor): EditorInlayLensManager {
|
fun getOrCreate(editor: Editor): EditorInlayLensManager {
|
||||||
return editor.getUserData(KEY) ?: EditorInlayLensManager(editor).also { editor.putUserData(KEY, it) }
|
return editor.getUserData(EDITOR_KEY) ?: EditorInlayLensManager(editor).also { editor.putUserData(EDITOR_KEY, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun remove(editor: Editor) {
|
fun remove(editor: Editor) {
|
||||||
val manager = editor.getUserData(KEY)
|
val manager = editor.getUserData(EDITOR_KEY)
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
manager.hideAll()
|
manager.hideAll()
|
||||||
editor.putUserData(KEY, null)
|
editor.putUserData(EDITOR_KEY, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,9 +82,11 @@ class EditorInlayLensManager private constructor(private val editor: Editor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun hideAll() {
|
fun hideAll() {
|
||||||
|
if (inlays.isNotEmpty()) {
|
||||||
executeInInlayBatchMode(inlays.size) { inlays.values.forEach(Inlay<*>::dispose) }
|
executeInInlayBatchMode(inlays.size) { inlays.values.forEach(Inlay<*>::dispose) }
|
||||||
inlays.clear()
|
inlays.clear()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getInlayHintPriority(info: HighlightInfo): Int {
|
private fun getInlayHintPriority(info: HighlightInfo): Int {
|
||||||
val startOffset = info.actualStartOffset
|
val startOffset = info.actualStartOffset
|
||||||
|
@ -1,25 +1,22 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
import com.chylex.intellij.inspectionlens.InspectionLensPluginDisposableService
|
|
||||||
import com.chylex.intellij.inspectionlens.utils.DebouncingInvokeOnDispatchThread
|
import com.chylex.intellij.inspectionlens.utils.DebouncingInvokeOnDispatchThread
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.lang.annotation.HighlightSeverity
|
import com.intellij.lang.annotation.HighlightSeverity
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
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
|
||||||
import com.intellij.openapi.editor.ex.RangeHighlighterEx
|
import com.intellij.openapi.editor.ex.RangeHighlighterEx
|
||||||
import com.intellij.openapi.editor.impl.DocumentMarkupModel
|
import com.intellij.openapi.editor.impl.DocumentMarkupModel
|
||||||
import com.intellij.openapi.editor.impl.event.MarkupModelListener
|
import com.intellij.openapi.editor.impl.event.MarkupModelListener
|
||||||
import com.intellij.openapi.editor.markup.RangeHighlighter
|
import com.intellij.openapi.editor.markup.RangeHighlighter
|
||||||
import com.intellij.openapi.fileEditor.TextEditor
|
import com.intellij.openapi.util.Disposer
|
||||||
import com.intellij.openapi.rd.createLifetime
|
import com.intellij.openapi.util.Key
|
||||||
import com.intellij.openapi.rd.createNestedDisposable
|
|
||||||
import com.jetbrains.rd.util.lifetime.intersect
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for inspection highlights and reports them to [EditorInlayLensManager].
|
* Listens for inspection highlights and reports them to [EditorInlayLensManager].
|
||||||
*/
|
*/
|
||||||
class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener {
|
internal class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelListener {
|
||||||
private val lens = EditorInlayLensManager.getOrCreate(editor)
|
private val lens = EditorInlayLensManager.getOrCreate(editor)
|
||||||
|
|
||||||
private val showOnDispatchThread = DebouncingInvokeOnDispatchThread(lens::showAll)
|
private val showOnDispatchThread = DebouncingInvokeOnDispatchThread(lens::showAll)
|
||||||
@ -51,7 +48,12 @@ class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showAllValid(highlighters: Array<RangeHighlighter>) {
|
||||||
|
highlighters.forEach(::showIfValid)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private val EDITOR_KEY = Key<LensMarkupModelListener>(LensMarkupModelListener::class.java.name)
|
||||||
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
private val MINIMUM_SEVERITY = HighlightSeverity.TEXT_ATTRIBUTES.myVal + 1
|
||||||
|
|
||||||
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
|
private fun getFilteredHighlightInfo(highlighter: RangeHighlighter): HighlightInfo? {
|
||||||
@ -74,25 +76,36 @@ class LensMarkupModelListener private constructor(editor: Editor) : MarkupModelL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getMarkupModel(editor: Editor): MarkupModelEx? {
|
||||||
|
return DocumentMarkupModel.forDocument(editor.document, editor.project, false) as? MarkupModelEx
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches a new [LensMarkupModelListener] to the document model of the provided [TextEditor], and reports all existing inspection highlights to [EditorInlayLensManager].
|
* Attaches a new [LensMarkupModelListener] to the [Editor], and reports all existing inspection highlights to [EditorInlayLensManager].
|
||||||
*
|
|
||||||
* The [LensMarkupModelListener] will be disposed when either the [TextEditor] is disposed, or via [InspectionLensPluginDisposableService] when the plugin is unloaded.
|
|
||||||
*/
|
*/
|
||||||
fun install(textEditor: TextEditor) {
|
fun register(editor: Editor, disposable: Disposable) {
|
||||||
val editor = textEditor.editor
|
if (editor.getUserData(EDITOR_KEY) != null) {
|
||||||
val markupModel = DocumentMarkupModel.forDocument(editor.document, editor.project, false)
|
return
|
||||||
if (markupModel is MarkupModelEx) {
|
}
|
||||||
val pluginLifetime = ApplicationManager.getApplication().getService(InspectionLensPluginDisposableService::class.java).createLifetime()
|
|
||||||
val editorLifetime = textEditor.createLifetime()
|
|
||||||
|
|
||||||
|
val markupModel = getMarkupModel(editor) ?: return
|
||||||
val listener = LensMarkupModelListener(editor)
|
val listener = LensMarkupModelListener(editor)
|
||||||
markupModel.addMarkupModelListener(pluginLifetime.intersect(editorLifetime).createNestedDisposable(), listener)
|
|
||||||
|
|
||||||
for (highlighter in markupModel.allHighlighters) {
|
editor.putUserData(EDITOR_KEY, listener)
|
||||||
listener.showIfValid(highlighter)
|
Disposer.register(disposable) { editor.putUserData(EDITOR_KEY, null) }
|
||||||
}
|
|
||||||
|
markupModel.addMarkupModelListener(disposable, listener)
|
||||||
|
listener.showAllValid(markupModel.allHighlighters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recreates all inspection highlights in the [Editor].
|
||||||
|
*/
|
||||||
|
fun refresh(editor: Editor) {
|
||||||
|
val listener = editor.getUserData(EDITOR_KEY) ?: return
|
||||||
|
val markupModel = getMarkupModel(editor) ?: return
|
||||||
|
|
||||||
|
listener.showAllValid(markupModel.allHighlighters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package com.chylex.intellij.inspectionlens.editor
|
package com.chylex.intellij.inspectionlens.editor
|
||||||
|
|
||||||
|
import com.chylex.intellij.inspectionlens.InspectionLens
|
||||||
|
import com.chylex.intellij.inspectionlens.utils.DebouncingInvokeOnDispatchThread
|
||||||
import com.intellij.lang.annotation.HighlightSeverity
|
import com.intellij.lang.annotation.HighlightSeverity
|
||||||
|
import com.intellij.spellchecker.SpellCheckerSeveritiesProvider
|
||||||
import com.intellij.ui.ColorUtil
|
import com.intellij.ui.ColorUtil
|
||||||
import com.intellij.ui.JBColor
|
import com.intellij.ui.JBColor
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
|
import java.util.Collections
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines properties of inspection lenses based on severity.
|
* Determines properties of inspection lenses based on severity.
|
||||||
@ -15,6 +19,8 @@ enum class LensSeverity(baseColor: Color, lightThemeDarkening: Int, darkThemeBri
|
|||||||
WARNING (Color(190, 145, 23), lightThemeDarkening = 4, darkThemeBrightening = 1),
|
WARNING (Color(190, 145, 23), lightThemeDarkening = 4, darkThemeBrightening = 1),
|
||||||
WEAK_WARNING (Color(117, 109, 86), lightThemeDarkening = 3, darkThemeBrightening = 3),
|
WEAK_WARNING (Color(117, 109, 86), lightThemeDarkening = 3, darkThemeBrightening = 3),
|
||||||
SERVER_PROBLEM (Color(176, 97, 0), lightThemeDarkening = 4, darkThemeBrightening = 2),
|
SERVER_PROBLEM (Color(176, 97, 0), lightThemeDarkening = 4, darkThemeBrightening = 2),
|
||||||
|
GRAZIE (Color( 53, 146, 196), lightThemeDarkening = 2, darkThemeBrightening = 1),
|
||||||
|
TYPO (Color( 73, 156, 84), lightThemeDarkening = 3, darkThemeBrightening = 1),
|
||||||
OTHER (Color(128, 128, 128), lightThemeDarkening = 1, darkThemeBrightening = 2);
|
OTHER (Color(128, 128, 128), lightThemeDarkening = 1, darkThemeBrightening = 2);
|
||||||
|
|
||||||
val colorAttributes: LensSeverityTextAttributes
|
val colorAttributes: LensSeverityTextAttributes
|
||||||
@ -28,12 +34,30 @@ enum class LensSeverity(baseColor: Color, lightThemeDarkening: Int, darkThemeBri
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun from(severity: HighlightSeverity) = when (severity) {
|
private val mapping = Collections.synchronizedMap(mapOf(
|
||||||
HighlightSeverity.ERROR -> ERROR
|
HighlightSeverity.ERROR to ERROR,
|
||||||
HighlightSeverity.WARNING -> WARNING
|
HighlightSeverity.WARNING to WARNING,
|
||||||
HighlightSeverity.WEAK_WARNING -> WEAK_WARNING
|
HighlightSeverity.WEAK_WARNING to WEAK_WARNING,
|
||||||
HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING -> SERVER_PROBLEM
|
HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING to SERVER_PROBLEM,
|
||||||
else -> OTHER
|
SpellCheckerSeveritiesProvider.TYPO to TYPO,
|
||||||
|
))
|
||||||
|
|
||||||
|
private val refreshLater = DebouncingInvokeOnDispatchThread<Unit> { InspectionLens.refresh() }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a mapping from a [HighlightSeverity] to a [LensSeverity], and refreshes all open editors.
|
||||||
|
*/
|
||||||
|
internal fun registerMapping(severity: HighlightSeverity, lensSeverity: LensSeverity) {
|
||||||
|
if (mapping.put(severity, lensSeverity) != lensSeverity) {
|
||||||
|
refreshLater.enqueue(Unit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the [LensSeverity] associated with the [HighlightSeverity], or [OTHER] if there no explicit mapping is found.
|
||||||
|
*/
|
||||||
|
fun from(severity: HighlightSeverity): LensSeverity {
|
||||||
|
return mapping.getOrDefault(severity, OTHER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
<idea-plugin>
|
||||||
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<postStartupActivity implementation="com.chylex.intellij.inspectionlens.compatibility.GrazieSupport" />
|
||||||
|
</extensions>
|
||||||
|
</idea-plugin>
|
@ -17,6 +17,11 @@
|
|||||||
]]></description>
|
]]></description>
|
||||||
|
|
||||||
<change-notes><![CDATA[
|
<change-notes><![CDATA[
|
||||||
|
<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>
|
||||||
<b>Version 1.1.2</b>
|
<b>Version 1.1.2</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Added plugin icon.</li>
|
<li>Added plugin icon.</li>
|
||||||
@ -39,6 +44,7 @@
|
|||||||
]]></change-notes>
|
]]></change-notes>
|
||||||
|
|
||||||
<depends>com.intellij.modules.platform</depends>
|
<depends>com.intellij.modules.platform</depends>
|
||||||
|
<depends optional="true" config-file="compatibility/InspectionLens-Grazie.xml">tanvd.grazi</depends>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
<applicationService serviceImplementation="com.chylex.intellij.inspectionlens.InspectionLensPluginDisposableService" />
|
<applicationService serviceImplementation="com.chylex.intellij.inspectionlens.InspectionLensPluginDisposableService" />
|
||||||
|
Loading…
Reference in New Issue
Block a user