IntelliJプラグインのAnActionと登録設定を実装・変更し、表示文言やアイコンの定義、非同期処理の起動方法を整えます。
- IDEに新しいアクションを追加したいとき
- アクションの登録やアイコンを変更したいとき
- 表示名と説明文の定義を整理したいとき
IntelliJのクイックフィックスやインテンションをModCommand APIへ移行し、対応する編集操作や選択UI、プレビューを新しい実行方式に合わせて組み直すスキルです。
Convert LocalQuickFix or IntentionAction to the ModCommand API.
実行スコア 未検証
インストール方法を見るLocalQuickFix や IntentionAction を、宣言的な ModCommand を返すAPIへ移行する作業を案内します。まず既存処理を調べ、PSI編集や対応する選択UIのように移行できるもの、UIの置き換えが必要なもの、カスタム入力ダイアログやプロジェクト設定変更など移行しないものに分類します。そのうえで処理内容に合う基底クラスを選び、メソッドやプレゼンテーション、PSI更新方法を変更します。プレビュー、バッチ実行、既存テストへの影響も確認できます。
IntelliJ Platform向けの既存クイックフィックスやインテンションを新APIに対応させたいときや、移行可能性を判断したいときに役立ちます。複数ファイルの編集、選択肢の提示、競合確認を含む処理について、APIの制約を踏まえて設計を見直せます。
LocalQuickFix をModCommand APIへ移行する手順を整理してください」任意のUIや Editor を使う処理は新APIで扱えない場合があり、その場合は移行対象にしません。資料ではテスト実行に tests.cmd、検索に ijproxy または代替スクリプトを挙げています。
この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。
インストールする前に、エージェントに与えられる指示の中身を確認できます。
Two APIs coexist in this repo, and they are not two styles of the same thing — they have opposite execution models:
LocalQuickFix / IntentionAction | ModCommandQuickFix / ModCommandAction | |
|---|---|---|
| when it runs | write action on EDT | background read action |
| what it does | mutates physical PSI directly | returns a ModCommand describing the effect; something else executes it |
| PSI it sees | physical | non-physical copies |
| capability | anything (dialogs, project model, refactoring engines, Editor) | only what the sealed ModCommand hierarchy models |
| intention preview | hand-written | derived 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.
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.
Everything it does is PSI editing plus editor state that ModPsiUpdater models:
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 contextThe 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 UI | Replacement |
|---|---|
| popup/list choosing an element or a variant | ModCommand.chooseAction + ModCommand.psiUpdateStep |
MemberChooser | ModCommand.chooseMultipleMembers (backed by ModEditOptions) |
| yes/no or "this will break X, continue?" confirmation | ModCommand.showConflicts with a single conflict |
| a form editing options | ModEditOptions |
Return chooseAction also when the list has zero or one option. The platform handles these cases, see
recipe 7 in references/recipes.md.
Leave these as LocalQuickFix. Trying to force them through the ModCommand API wastes a session:
ModStartRename models it explicitlySafeDeleteProcessor, full
change-signature, extract-method. Standard rename is modeled by ModStartRename; the narrow
'suggested refactoring' case is available via ModPsiUpdater.trackDeclarationOptionally 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.
| You have | Condition | Convert to |
|---|---|---|
LocalQuickFix | body only needs descriptor.getStartElement() — editing several files is still fine here, via updater.getWritable | PsiUpdateModCommandQuickFix → applyFix(project, element, updater) |
LocalQuickFix | needs the whole descriptor, composes commands with andThen, or must showConflicts before editing | ModCommandQuickFix → perform(project, descriptor): ModCommand |
LocalQuickFix | stores PsiElement / SmartPsiElementPointer fields | PsiUpdateModCommandAction<E> (see below) |
BatchQuickFix | ModCommandBatchQuickFix → perform(project, List<ProblemDescriptor>) | |
IntentionAction, LocalQuickFixAndIntentionActionOnPsiElement | simple | PsiUpdateModCommandAction<E> → invoke(context, element, updater) |
IntentionAction, LocalQuickFixAndIntentionActionOnPsiElement | needs the physical element, or builds the command itself | PsiBasedModCommandAction<E> → perform(context, element) |
| anything else | raw 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.)
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.startInWriteAction, getElementToMakeWritable, getFileModifierForPreview,
generatePreview, and every @SafeFieldForPreview. They are final or redundant on the new bases.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.ModCommandQuickFix / PsiUpdateModCommandQuickFix, getName() and getFamilyName() work as
before, and marker interfaces (HighPriorityAction, LowPriorityAction) still apply;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.psiUpdateFull detail in references/psi-updater.md. The rules that break code most often:
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.WriteCommandAction, CommandProcessor, preparePsiElementForWrite.
The engine handles it. Note this does not extend to PsiDocumentManager.commitDocument — see the
document bullet below.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.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.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.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/"]:
implements LocalQuickFix, extends LocalQuickFixOnPsiElement,
LocalQuickFixAndIntentionActionOnPsiElement, implements IntentionActionsearch_symbol for PsiUpdateModCommandQuickFix, ModCommandQuickFix,
PsiUpdateModCommandAction@SafeFieldForPreview, generatePreview,
getFileModifierForPreview, WriteCommandAction, showAndGet, DialogWrapper, Editor editorA 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:
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>".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.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.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.ModEditOptions.applyOptions(Map) is @TestOnly — keys are option
bind ids, and it returns the next command, so a chooseMultipleMembers branch is testable without UI.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.
ModCommand, every factory method,
and what the API can and cannot dopsiUpdate, ModPsiUpdater, ActionContextExternal background (predates the current API — check spellings against references/capabilities.md):
まだレビューはありません。使ってみた感想をお寄せください。
ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。
まだコメントはありません。最初のコメントを書いてみませんか。
IntelliJプラグインのAnActionと登録設定を実装・変更し、表示文言やアイコンの定義、非同期処理の起動方法を整えます。
IntelliJのJPSテストモジュールをBazelへ移行し、Bazelだけで起きる失敗を依存関係や実行環境から切り分ける手順を案内します。
IntelliJのKotlin・Javaコードを新規作成やレビューする際に、言語の選び方、書式、型の扱い、例外処理などのプロジェクト規約に沿って整えるスキルです。
IntelliJ向けの変更を適切な単位に分け、チケットの有無に応じた形式で、理由や判断も伝わるコミットメッセージを作成・修正するスキルです。
Pythonコードの型推論や型エラーを複数の型チェッカーで比較し、各ツールの判定と診断内容をまとめたレポートを作成します。
Compose Desktopの画面で状態や副作用をどこに持たせるか整理し、表示と判断の境界、再利用部品やリストの設計を整えます。