Skip to content

Instantly share code, notes, and snippets.

@dkandalov
dkandalov / plugin.kts
Last active April 2, 2025 22:52
Mini-plugin with refactorings counter popup for the "47 refactorings in 45 minutes" talk
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.*
import com.intellij.openapi.util.Disposer
import com.intellij.ui.JBColor
import com.intellij.ui.awt.RelativePoint
import liveplugin.*
import java.awt.Point
var counter = 0
var balloon: Balloon? = null
@dkandalov
dkandalov / plugin.kts
Last active December 13, 2024 17:41
Mini-plugin to optimise imports in the background in all project Kotlin files
import com.intellij.codeInsight.actions.OptimizeImportsProcessor
import com.intellij.lang.Language
import com.intellij.psi.PsiFile import liveplugin.PluginUtil
import liveplugin.registerAction
registerAction("Background Optimize Imports") { event ->
val project = event.project ?: return@registerAction
val kotlinLanguage = Language.findLanguageByID("kotlin")!!
val psiFiles = PluginUtil.allPsiItemsIn(project)
.filterIsInstance<PsiFile>()
@dkandalov
dkandalov / plugin.kts
Last active December 13, 2024 17:00
Mini-plugin to demo how UselessCallOnNotNullInspection can be "forked" with LivePlugin
@file:Suppress("UnstableApiUsage")
@file:OptIn(UnsafeCastFunction::class)
import com.intellij.codeInspection.IntentionWrapper
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.util.TextRange
import liveplugin.implementation.registerInspectionIn
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAsReplacement
import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
@dkandalov
dkandalov / plugin.kts
Last active December 25, 2024 04:49
Mini-plugin to measure the duration of tests in IntelliJ IDEs (because test runners don't show the actual time)
import com.intellij.execution.ExecutionListener
import com.intellij.execution.ExecutionManager.Companion.EXECUTION_TOPIC
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import java.util.concurrent.ConcurrentHashMap
val startTimeByRunProfile = ConcurrentHashMap<String, Long>()
project!!.messageBus.connect(pluginDisposable)
.subscribe(EXECUTION_TOPIC, object : ExecutionListener {
import com.intellij.openapi.wm.impl.ProjectFrameHelper
import com.intellij.openapi.wm.impl.status.InfoAndProgressPanel
import liveplugin.getProperty
import liveplugin.invoke
import liveplugin.registerAction
import java.awt.KeyboardFocusManager
// https://youtrack.jetbrains.com/issue/IDEA-216058/Return-focus-from-Background-Tasks-window-to-IDE-via-keyboard
registerAction("Show Background Process Window", keyStroke = "meta shift B") {
val window = KeyboardFocusManager.getCurrentKeyboardFocusManager().focusedWindow
@file:Suppress("UnstableApiUsage")
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl
import liveplugin.registerAction
// Action to remove panel at the top of the editor, e.g. "Kotlin script is in beta" panel.
registerAction("Remove Top Editor Component", "ctrl meta H") { event ->
val project = event.project ?: return@registerAction
val editorManager = FileEditorManager.getInstance(project) as FileEditorManagerImpl
import com.intellij.diagnostic.IdeMessagePanel
import com.intellij.openapi.wm.WindowManager
import liveplugin.registerAction
registerAction("Show IDE Errors", "ctrl shift E") { event ->
val messagePanel = WindowManager.getInstance().allProjectFrames
.find { it.project == event.project }
?.statusBar?.getWidget(IdeMessagePanel.FATAL_ERROR) as IdeMessagePanel
messagePanel.openErrorsDialog(null)
}
@dkandalov
dkandalov / gist:af1fbd110cb4ebcc8b4236df82079f89
Created October 13, 2024 14:56
intellij-guide-socrates-be.md
# The Ultimate Guide to IntelliJ
#### tippy tappy
---
## https://gitlab.com/enverbral/socrates-hearts
---
## Overall ideas
- Learn one thing at a time (or whatever works for **you**!)
- [Slowification](https://www.amazon.com/Wiring-Winning-Organization-Slowification-Simplification/dp/1950508420)
@dkandalov
dkandalov / plugin.kts
Last active November 24, 2024 22:35
Mini-plugin for paragraph navigation in IntelliJ IDEs (to be use with https://github.com/dkandalov/live-plugin)
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorModificationUtil
import com.intellij.openapi.editor.IndentGuideDescriptor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.ScrollType.CENTER
import com.intellij.openapi.editor.impl.IndentsModelImpl
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory
import liveplugin.registerEditorAction
// See https://gist.github.com/dkandalov/6bd16ac80ee69739f9b81b665bb93768
@dkandalov
dkandalov / plugin.kts
Last active June 23, 2024 09:12
Mini-plugin for paragraph navigation in IntelliJ IDEs (to be use with https://github.com/dkandalov/live-plugin)
import com.intellij.openapi.command.executeCommand
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.EditorModificationUtil
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.ScrollType.CENTER_DOWN
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory
import liveplugin.editor
import liveplugin.registerAction
registerAction("Previous Paragraph", "alt shift COMMA") { event ->