Skip to content
cccskills
FreePublished on GitHub

modcommand-migration

Use this skill to migrate IntelliJ quick-fixes and intentions to the ModCommand API. It helps assess which actions can convert, choose the right base class, adapt supported UI choices, and preserve behavior while following the new execution and preview model.

OriginalShow the original description

Convert LocalQuickFix or IntentionAction to the ModCommand API.

JetBrains/intellij-community20,664 stars(GitHub 20,664 + cccskills 0)

Run score Not tested

See how to install

Good for

  • Migrating a LocalQuickFix to ModCommand
  • Converting an IntentionAction
  • Replacing a supported chooser or confirmation UI
  • Reviewing preview and batch behavior after migration

Files included (4)

  • SKILL.md14.6 KB
  • references/capabilities.md7.8 KB
  • references/psi-updater.md11.6 KB
  • references/recipes.md9.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

<!-- Generated by community/.ai/render-guides.mjs; edit community/.agents/skills/modcommand-migration/SKILL.md -->

Migrating quick-fixes and intentions to the ModCommand API

Two APIs coexist in this repo, and they are not two styles of the same thing — they have opposite execution models:

LocalQuickFix / IntentionActionModCommandQuickFix / ModCommandAction
when it runswrite action on EDTbackground read action
what it doesmutates physical PSI directlyreturns a ModCommand describing the effect; something else executes it
PSI it seesphysicalnon-physical copies
capabilityanything (dialogs, project model, refactoring engines, Editor)only what the sealed ModCommand hierarchy models
intention previewhand-writtenderived from the returned command

So this is not a mechanical rename. A ModCommandQuickFix cannot show arbitrary UI, and it has no Editor. That constraint is the whole point: because the command is a declarative, serializable record, non-IDE clients can execute it.

Why bother: no write action on EDT means no freeze/slow-op report from the action; preview comes for free; and it is a hard requirement for clients that only speak ModCommand — LSP code actions accept only ModCommandQuickFix (LSP-670), Next Edit Suggestions only ModCommandAction (SCL-21364), plus Qodana and Fleet.

Step 1 — Triage before you touch anything

Not every fix can be converted. Decide this first. Read the fix's applyFix/invoke body and everything it calls, and sort it into one of three buckets.

Convert directly

Everything it does is PSI editing plus editor state that ModPsiUpdater models:

  • edits PSI in its own file, or in several files
  • moves the caret, changes the selection, adds highlighting
  • starts a live template
  • starts the standard Rename UI — replace direct VariableInplaceRenamer or PsiElementRenameHandler.invoke calls with updater.rename. The executor delegates to registered Renamers, so the result may be an inline rename or a rename dialog depending on the symbol, language, and context
  • shows an information/error message
  • changes an inspection option

Convert, but rewrite the UI

The fix shows UI, but the UI is only picking something. These have declarative equivalents — and the result is usually shorter than the original, with a working preview:

Original UIReplacement
popup/list choosing an element or a variantModCommand.chooseAction + ModCommand.psiUpdateStep
MemberChooserModCommand.chooseMultipleMembers (backed by ModEditOptions)
yes/no or "this will break X, continue?" confirmationModCommand.showConflicts with a single conflict
a form editing optionsModEditOptions

Return chooseAction also when the list has zero or one option. The platform handles these cases, see recipe 7 in references/recipes.md.

Do not convert

Leave these as LocalQuickFix. Trying to force them through the ModCommand API wastes a session:

  • a custom dialog with input — text fields, trees, checkbox matrices, its own preview pane. The standard Rename UI is the exception because ModStartRename models it explicitly
  • project model / Gradle / Maven / SDK / language-level configuration
  • refactoring engines without a corresponding ModCommand — SafeDeleteProcessor, full change-signature, extract-method. Standard rename is modeled by ModStartRename; the narrow 'suggested refactoring' case is available via ModPsiUpdater.trackDeclaration
  • launching external programs

Optionally give such a fix a reduced ModCommand path for headless clients by implementing LocalQuickFixWithModCommandFallback (community/platform/analysis-api/src/com/intellij/modcommand/LocalQuickFixWithModCommandFallback.java) — getFallbackModCommandAction() may skip the advanced behaviour.

A converted fix almost never needs a custom preview. If you find yourself writing generatePreview, first check whether the auto-generated one is actually wrong.

Step 2 — Pick the target base class

You haveConditionConvert to
LocalQuickFixbody only needs descriptor.getStartElement() — editing several files is still fine here, via updater.getWritablePsiUpdateModCommandQuickFix → applyFix(project, element, updater)
LocalQuickFixneeds the whole descriptor, composes commands with andThen, or must showConflicts before editingModCommandQuickFix → perform(project, descriptor): ModCommand
LocalQuickFixstores PsiElement / SmartPsiElementPointer fieldsPsiUpdateModCommandAction<E> (see below)
BatchQuickFixModCommandBatchQuickFix → perform(project, List<ProblemDescriptor>)
IntentionAction, LocalQuickFixAndIntentionActionOnPsiElementsimplePsiUpdateModCommandAction<E> → invoke(context, element, updater)
IntentionAction, LocalQuickFixAndIntentionActionOnPsiElementneeds the physical element, or builds the command itselfPsiBasedModCommandAction<E> → perform(context, element)
anything elseraw ModCommandAction

Only the base class choice depends on how the fix is anchored. Nothing in this table restricts you to one file — every psiUpdate-based base gets a ModPsiUpdater, so cross-file edits are available from all of them (recipe 5 in references/recipes.md).

Kotlin plugin has its own bases: KotlinModCommandQuickFix<ELEMENT>, KotlinApplicableModCommandAction, KotlinPsiUpdateModCommandAction.

PsiUpdateModCommandAction<E> has two constructors, and picking the wrong one is a common mistake:

  • super(element) — bind to a concrete element (the equivalent of a fix that stored a pointer). The element is passed back to getPresentation/invoke already checked for validity and writability.
  • super(SomeElement.class) — find an element of that class under the caret. For registered intentionAction extensions with a no-arg constructor.

Binding to several elements is still your job: keep the extra ones in fields as smart pointers and check their validity yourself.

Register an action as a quick-fix with the builder API, which takes a ModCommandAction directly:

holder.problem(element, message).fix(new MyFix(otherElement)).register();

LocalQuickFix.from(ModCommandAction) is the explicit adapter where you need a LocalQuickFix value. (ModCommandAction.asIntention() is the intention-side counterpart.)

Step 3 — Mechanical edits

  1. Change the supertype.
  2. Add the new method; move the old body into it.
  3. Replace descriptor.getStartElement() with element. descriptor.getPsiElement() needs a check first — it is not a synonym. For a descriptor registered with a start and end element, ProblemDescriptorBase.getPsiElement() returns their common parent, which can be a higher element than getStartElement(). PsiUpdateModCommandQuickFix anchors on getStartElement(), so substituting blindly silently changes which element the fix operates on. If the fix genuinely needs getPsiElement(), extend ModCommandQuickFix instead and call ModCommand.psiUpdate(descriptor.getPsiElement(), ...) yourself.
  4. Delete startInWriteAction, getElementToMakeWritable, getFileModifierForPreview, generatePreview, and every @SafeFieldForPreview. They are final or redundant on the new bases.
  5. Review branches on isOnTheFly and isPhysical; do not delete them blindly. If isOnTheFly only guards navigation or highlighting, call updater.highlight/moveCaretTo unconditionally — batch execution drops those commands for you. Writable PSI is always non-physical, so remove preview-only physicality branches after keeping the behaviour that should now always run. Preserve or rewrite branches that affect PSI edits, availability, search scope, or other semantics. To test for a synthetic element use instanceof SyntheticElement; for a factory-created one, use element.getContainingFile() instanceof DummyHolder.
  6. Presentation:
    • on ModCommandQuickFix / PsiUpdateModCommandQuickFix, getName() and getFamilyName() work as before, and marker interfaces (HighPriorityAction, LowPriorityAction) still apply;
    • on a ModCommandAction, all of it moves into getPresentation(): return null where isAvailable() returned false, otherwise Presentation.of(text) with .withPriority(...) (replacing the marker interfaces), .withFixAllOption(this) (replacing IntentionActionWithFixAllOption), .withHighlighting(...), .withIcon(...). Drop any setText()/myText field — the presentation is computed per context.

Step 4 — Rules inside psiUpdate

Full detail in references/psi-updater.md. The rules that break code most often:

  • Every element you get is a non-physical copy. Call updater.getWritable(x) for anything in another file, and get all writable copies before writing anything — getWritable throws IllegalStateException once that file's copy has been modified.
  • No write actions. Delete WriteCommandAction, CommandProcessor, preparePsiElementForWrite. The engine handles it. Note this does not extend to PsiDocumentManager.commitDocument — see the document bullet below.
  • Do not start your own progress. perform/invoke already runs in a background read action under a progress, so a wrapper like runWriteActionWithCancellableProgressInDispatchThread around a long loop just goes away; keep the cancellation by calling ProgressManager.checkCanceled() in the loop.
  • No Editor, FileEditorManager or DataContext. Input comes from ActionContext, output from ModPsiUpdater. For a shared helper that still wants an editor, change its parameter to ModNavigator — call sites with a real editor pass editor.asModNavigator(). See FixDocCommentAction.generateComment(PsiElement, Project, ModNavigator) for a helper already converted this way.
  • editor.getDocument() → element.getContainingFile().getFileDocument() (or updater.getDocument()). That document is writable, and raw replaceString/insertString/deleteString on it are legal — the engine listens on it and folds your edits into the resulting ModUpdateFileText. Keep the PsiDocumentManager.commitDocument(doc) that follows: without it the PSI you touch next is stale. See references/psi-updater.md.
  • The failure path is updater.cancel(message): it discards the changes and shows an error.
  • perform/invoke must be side-effect-free with respect to physical state. It may run for preview, and it may not run at all.

Step 5 — Find more candidates

Search with ijproxy (search_text, search_symbol) and fall back to ./community/tools/rg.cmd when MCP is unavailable. Scope with paths, e.g. paths: ["community/python/"]:

  • candidates — implements LocalQuickFix, extends LocalQuickFixOnPsiElement, LocalQuickFixAndIntentionActionOnPsiElement, implements IntentionAction
  • already migrated — search_symbol for PsiUpdateModCommandQuickFix, ModCommandQuickFix, PsiUpdateModCommandAction
  • red flags that decide the triage — @SafeFieldForPreview, generatePreview, getFileModifierForPreview, WriteCommandAction, showAndGet, DialogWrapper, Editor editor

Testing

A conversion is behaviour-preserving, so the inspection's existing tests are the real check. Run them before the change too, to tell a pre-existing failure from one you introduced: ./tests.cmd --module <module> --test <FQN> (FQN required — simple class names do not match). Then lint_files the files you touched. See the testing skill for discovery.

What breaks specifically because of a ModCommand conversion:

  • The action's visible name. LocalQuickFix.from(ModCommandAction) — and therefore holder.problem(...).fix(action) — produces an adapter whose getName() returns getFamilyName(). A fix whose old getName() differed from its family name needs its gold-file action hint updated: // "<expected action text>" "<true|false|ProblemHighlightType>".
  • A chooser adds a step. Walk into the ModChooseAction in the hint with |-> between steps, e.g. // "Add 'throws RuntimeException' to method signature|->Change only this method" "true-preview". Each segment is matched against the previous step's child actions; if the action returns no chooser the test fails with "does not produce a chooser". Suffix the state with -preview to also assert the intention preview.
  • Preview gold data. Deleting a hand-written generatePreview changes the preview. Confirm the generated one is equivalent before accepting a diff — it legitimately shows more, since it covers every file the command touches plus navigation and messages.
  • Batch tests. Navigation, highlighting, ModShowConflicts and ModStartRename are dropped, and the first chooser option is auto-selected. Caret and selection assertions therefore belong in interactive tests; if a batch result changed, check your chooser option order.
  • Driving an options chooser. ModEditOptions.applyOptions(Map) is @TestOnly — keys are option bind ids, and it returns the next command, so a chooseMultipleMembers branch is testable without UI.
  • Worth asserting once: the fix now works with no editor open, since ModPsiUpdater is always available where the old code returned early.

Hint parsing lives in community/platform/testFramework/src/com/intellij/codeInsight/daemon/quickFix/ActionHint.java.

References

External background (predates the current API — check spellings against references/capabilities.md):

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

actions

FreeSummary

Implement or update IntelliJ `AnAction` classes and their `plugin.xml` registrations. Keep labels and descriptions in message bundles, configure optional icons, and launch suspending work through the event coroutine scope so synchronous action handling does not freeze the IDE.

  • Adding a new IntelliJ action
  • Updating an action's registration or icon
  • Moving action labels into a message bundle
JetBrains/intellij-community20.7KUpdated Oct 26, 2026

Move IntelliJ JPS test modules to Bazel and diagnose failures that occur only under Bazel. The guide helps trace missing dependencies, plugins, test data, and runfiles, then verify the generated target and migrated tests.

  • Migrating a JPS test module to Bazel
  • Diagnosing a test failure that occurs only in Bazel
  • Checking Bazel dependencies and test data wiring
JetBrains/intellij-community20.7KUpdated Oct 26, 2026

code-style

FreeSummary

Write or review Kotlin and Java code in line with IntelliJ project conventions. The guidance covers language choice, formatting, sealed types, threading annotations, and safe handling of control flow exceptions so changes fit the surrounding codebase.

  • Writing a new Kotlin file that follows IntelliJ conventions
  • Reviewing Java code and checking its style guidance
  • Checking formatting, sealed-type handling, or exception handling
JetBrains/intellij-community20.7KUpdated Oct 26, 2026

commits

FreeSummary

Create, amend, or rename IntelliJ commits with messages that follow the project’s ticket and label formats. Keep each commit focused, explain the reason and decision in the body when needed, and pass the message safely through the shell or PowerShell.

  • Writing a message for a change linked to a YouTrack ticket
  • Preparing a commit message for tests, cleanup, or documentation
  • Amending or renaming an existing IntelliJ commit
JetBrains/intellij-community20.7KUpdated Oct 26, 2026

Compare how Python type checkers interpret a code snippet or file. The script runs selected tools, including ty, pyrefly, basedpyright, mypy, and zuban, then produces a Markdown report with verdicts, timings, and each checker's diagnostic output.

  • Comparing type inference for a Python snippet
  • Checking whether a Python expression should be a type error
  • Reviewing differences among Python type checkers
JetBrains/intellij-community20.7KUpdated Oct 26, 2026

Shape Compose Desktop UI code by keeping composables focused on rendering and placing application decisions in presenters or coordinators. Get guidance on state ownership, effects, reusable component APIs, lazy-list keys, animation, and performance for individual UI changes.

  • Separating screen rendering from application decisions
  • Choosing which UI state belongs in composition
  • Structuring effects and coroutine work
JetBrains/intellij-community20.7KUpdated Oct 26, 2026

See all skills by JetBrains

Report a problem with this skill