r.item.id}
+ items={rows}
+ getKey={(row) => (row.kind === "section" ? row.key : row.item.id)}
+ isSection={isListSection}
+ sectionHeightOf={dividerHeight}
+ renderSection={(row) =>
+ row.kind === "section" && row.label ? {row.label} :
+ }
activeIndex={activeIndex}
onActiveChange={setActive}
hoverSelects
autoFocus
aria-label={popup.title}
- onActivate={(r) => activate(r.item)}
+ onActivate={(row) => row.kind === "action" && activate(row.item)}
empty={
popup.busy ? (
@@ -261,7 +299,9 @@ function ListPopup({ popup }: { popup: Extract }) {
)
}
- renderItem={({ item, match }) => {
+ renderItem={(row) => {
+ if (row.kind !== "action") return null;
+ const { item, match } = row;
const n = popup.numbered && !query ? indexOf(item) + 1 : 0;
return (
}) {
data-line={item.location?.line}
>
{popup.numbered && {n > 0 && n <= 9 ? n : ""}}
-
+ {showIcons && }
{item.preview && (
diff --git a/src/editor/lsp/popupStore.ts b/src/editor/lsp/popupStore.ts
index 7048ac72f..3dc3896b1 100644
--- a/src/editor/lsp/popupStore.ts
+++ b/src/editor/lsp/popupStore.ts
@@ -14,6 +14,8 @@ export interface PopupPoint {
export interface ListPopupItem {
id: string;
label: string;
+ /** Adjacent actions with the same section id share a caption or divider. */
+ section?: { id: string; label?: string };
/** Muted trailing text (file:line, kind…). */
detail?: string;
/** Second line / muted text after the label (code preview). */
@@ -100,6 +102,8 @@ export type LspPopup =
items: ListPopupItem[];
/** Rows 1-9 get a number; typing it runs the row (IDEA's numbered popups). */
numbered?: boolean;
+ /** Compact action list, with room for icons only when a row has one. */
+ compact?: boolean;
/** More rows are still being looked for (`aria-busy`). */
busy?: boolean;
/** Header pin button (e.g. "Open in Find Tool Window"). */
diff --git a/src/editor/refactor/catalog.ts b/src/editor/refactor/catalog.ts
index ac7638e4a..f26633559 100644
--- a/src/editor/refactor/catalog.ts
+++ b/src/editor/refactor/catalog.ts
@@ -28,6 +28,7 @@ export interface Refactoring {
/** Action id (keymaps, menu). */
action: string;
label: string;
+ section?: { id: string; label?: string };
/** LSP kind prefix that can produce it; null for client-side refactorings. */
kind: string | null;
/** IDEA's reason when nothing applies at the caret / selection. */
@@ -35,6 +36,9 @@ export interface Refactoring {
}
const AT_NAME = "Caret should be positioned at the name of the element to be refactored";
+const EXTRACT = { id: "extract", label: "Extract/Introduce" };
+const MOVE = { id: "move" };
+const HIERARCHY = { id: "hierarchy" };
/** IDEA's Refactor This order. */
export const REFACTORINGS: readonly Refactoring[] = [
@@ -52,26 +56,11 @@ export const REFACTORINGS: readonly Refactoring[] = [
kind: "refactor.rewrite",
reason: () => "Caret should be positioned at the name of the function or method to be refactored",
},
- { id: "move", action: "refactor.move", label: "Move…", kind: "refactor.move", reason: () => AT_NAME },
- {
- id: "safeDelete",
- action: "refactor.safeDelete",
- label: "Safe Delete…",
- kind: null,
- reason: () => "Caret should be on a symbol",
- },
- {
- id: "extractMethod",
- action: "refactor.extractMethod",
- label: "Extract Method…",
- kind: "refactor.extract",
- reason: (sel) =>
- sel ? "Selected block should represent a set of statements or an expression" : "Select the code to extract",
- },
{
id: "extractVariable",
action: "refactor.extractVariable",
label: "Introduce Variable…",
+ section: EXTRACT,
kind: "refactor.extract",
reason: (sel) => (sel ? "Selected block should represent an expression" : "Caret should be inside an expression"),
},
@@ -79,6 +68,7 @@ export const REFACTORINGS: readonly Refactoring[] = [
id: "extractConstant",
action: "refactor.extractConstant",
label: "Introduce Constant…",
+ section: EXTRACT,
kind: "refactor.extract",
reason: (sel) => (sel ? "Selected block should represent an expression" : "Caret should be inside an expression"),
},
@@ -86,6 +76,7 @@ export const REFACTORINGS: readonly Refactoring[] = [
id: "extractField",
action: "refactor.extractField",
label: "Introduce Field…",
+ section: EXTRACT,
kind: "refactor.extract",
reason: (sel) =>
sel ? "Selected block should represent an expression" : "Caret should be inside an expression in a class",
@@ -94,22 +85,50 @@ export const REFACTORINGS: readonly Refactoring[] = [
id: "extractParameter",
action: "refactor.extractParameter",
label: "Introduce Parameter…",
+ section: EXTRACT,
kind: "refactor.extract",
reason: (sel) =>
sel ? "Selected block should represent an expression" : "Caret should be inside an expression in a function",
},
+ {
+ id: "extractMethod",
+ action: "refactor.extractMethod",
+ label: "Extract Method…",
+ section: EXTRACT,
+ kind: "refactor.extract",
+ reason: (sel) =>
+ sel ? "Selected block should represent a set of statements or an expression" : "Select the code to extract",
+ },
{
id: "extractInterface",
action: "refactor.extractInterface",
label: "Extract Interface…",
+ section: EXTRACT,
kind: null,
reason: () => "Caret should be inside a class",
},
- { id: "inline", action: "refactor.inline", label: "Inline…", kind: "refactor.inline", reason: () => AT_NAME },
+ {
+ id: "inline",
+ action: "refactor.inline",
+ label: "Inline…",
+ section: { id: "inline" },
+ kind: "refactor.inline",
+ reason: () => AT_NAME,
+ },
+ { id: "move", action: "refactor.move", label: "Move…", section: MOVE, kind: "refactor.move", reason: () => AT_NAME },
+ {
+ id: "safeDelete",
+ action: "refactor.safeDelete",
+ label: "Safe Delete…",
+ section: MOVE,
+ kind: null,
+ reason: () => "Caret should be on a symbol",
+ },
{
id: "pullMembersUp",
action: "refactor.pullMembersUp",
label: "Pull Members Up…",
+ section: HIERARCHY,
kind: null,
reason: () => "Caret should be inside a class that has members to pull up",
},
@@ -117,6 +136,7 @@ export const REFACTORINGS: readonly Refactoring[] = [
id: "pushMembersDown",
action: "refactor.pushMembersDown",
label: "Push Members Down…",
+ section: HIERARCHY,
kind: null,
reason: () => "Caret should be inside a class that has members to push down",
},
diff --git a/src/editor/refactor/refactorThis.test.ts b/src/editor/refactor/refactorThis.test.ts
index a6c53a742..cf6cff633 100644
--- a/src/editor/refactor/refactorThis.test.ts
+++ b/src/editor/refactor/refactorThis.test.ts
@@ -181,7 +181,7 @@ describe("catalog", () => {
});
describe("Refactor This", () => {
- it("lists only the refactorings applicable at the caret, in IDEA order", async () => {
+ it("lists applicable refactorings in menu order and groups extraction actions", async () => {
prepare = ok({ start: { line: 0, col: 0 }, end: { line: 0, col: 1 } });
query = answer([
action("Inline variable", "refactor.inline"),
@@ -190,7 +190,9 @@ describe("Refactor This", () => {
action("Extract into function", "refactor.extract", "Can't extract here"),
]);
await refactorThis(editor(), vi.fn());
- expect(labels()).toEqual(["Rename…", "Safe Delete…", "Introduce Variable…", "Inline…", "Convert to raw string"]);
+ expect(labels()).toEqual(["Rename…", "Introduce Variable…", "Inline…", "Safe Delete…", "Convert to raw string"]);
+ const popup = useLspPopup.getState().popup;
+ expect(popup?.kind === "list" && popup.items[1]?.section?.label).toBe("Extract/Introduce");
// IDEA's numbered list: 1-9 run a row directly.
expect((useLspPopup.getState().popup as { numbered?: boolean }).numbered).toBe(true);
expect(lspCodeActionQuery).toHaveBeenCalledOnce();
diff --git a/src/editor/refactor/refactorThis.ts b/src/editor/refactor/refactorThis.ts
index b7a0ae100..673fb8153 100644
--- a/src/editor/refactor/refactorThis.ts
+++ b/src/editor/refactor/refactorThis.ts
@@ -263,7 +263,13 @@ export function refactorThisItems(
go = () => introduceFallback(view, INTRODUCE[r.id]!, answer.status === "notReady" ? "notReady" : "error");
if (!go) continue;
const exec = go;
- items.push({ id: r.id, label: r.label, shortcut: shortcutLabel(r.action), run: () => void exec() });
+ items.push({
+ id: r.id,
+ label: r.label,
+ section: r.section,
+ shortcut: shortcutLabel(r.action),
+ run: () => void exec(),
+ });
}
other.forEach((a, i) =>
items.push({
@@ -326,6 +332,7 @@ export async function refactorThis(view: EditorView, rename: (view: EditorView)
anchor: caretAnchor(view, state.selection.main.head),
title: "Refactor This",
items,
+ compact: true,
numbered: true,
});
}
@@ -338,6 +345,7 @@ export function showNothingHere(
kind: "list",
anchor,
title: "Refactor This",
+ compact: true,
items: [{ id: "nothing", label: "Nothing here", disabled: "No refactoring applies here", run: () => {} }],
});
}
diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json
index 7bbbc10d0..77d73a81d 100644
--- a/src/platform/locales/text/en.json
+++ b/src/platform/locales/text/en.json
@@ -2646,6 +2646,7 @@
"Delete…": "Delete…",
"Previous Definition": "Previous Definition",
"Next Definition": "Next Definition",
+ "Extract/Introduce": "Extract/Introduce",
"Configure {name}…": "Configure {name}…",
"Check the system Trash for these items. {names}": "Check the system Trash for these items. {names}",
"Git User Name Is Not Defined": "Git User Name Is Not Defined",
diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json
index df388fad9..86f8cc39a 100644
--- a/src/platform/locales/text/zh.json
+++ b/src/platform/locales/text/zh.json
@@ -709,6 +709,7 @@
"Unwrap/Remove…": "解包/移除…",
"Basic": "基本补全",
"Quick Definition": "快速定义",
+ "Extract/Introduce": "提取/引入",
"Reformat File…": "重新格式化文件…",
"Go to Declaration or Usages": "转到声明或用法",
"Go to Implementation(s)": "转到实现",