refactor(editor): provide the Copy Path chooser to the editor API instead of importing it

Keeps @/editor/api free of the popup store and keymap imports, so modules
that load it (and the language smoke's inputs) don't grow.
Цей коміт міститься в:
l0ng-ai committed 2026-11-27 03:36:26 +08:00
1 джерело c6c17c4a8f
коміт f79ae0273e
4 files changed
+41 -14

No files matched your search

+32 -2
Переглянути файл
@@ -34,7 +34,7 @@ import type { LanguageDescription } from "@codemirror/language";
import type { HunkKind } from "@/bindings";
import type { LineEnding } from "@/platform/ipc";
import { create } from "zustand";
import { maybeEditorService, type EditorInput } from "@/workbench/contributions";
import { maybeEditorService, type EditorInput, type MenuGroupContext } from "@/workbench/contributions";
import { isSameOrInside } from "@/platform/paths";
import { useProject } from "@/platform/project";
import { rootOfPath } from "@/platform/projectRoots";
@@ -49,7 +49,6 @@ export {
type NavigationMatch,
} from "@/editor/navigationProviders";
export { registerRelatedProvider, type RelatedContext, type RelatedItem } from "@/editor/relatedProviders";
export { openCopyPathChooser, type CopyPathRow } from "@/editor/core/copyPathChooser";
export { offsetsToRange, offsetToPos, posToOffset, rangeToOffsets, textEditsToChanges } from "@/editor/lsp/positions";
/** Documents above this size (UTF-16 units) skip per-line decorations. */
@@ -1018,6 +1017,37 @@ export function _provideCodePreview(provider: typeof codePreviewProvider) {
codePreviewProvider = provider;
}
/** A row of the Copy Path/Reference… chooser. */
export interface CopyPathRow {
/** The action whose shortcut the row shows. */
id: string;
/** English label, translated by the chooser. */
label: string;
/** The copied text; a row without one is left out. */
preview: string | null;
run: () => void;
}
type CopyPathChooser = (
anchor: { x: number; y: number } | "center",
rows: readonly CopyPathRow[],
ctx: MenuGroupContext,
) => void;
let copyPathChooser: CopyPathChooser | null = null;
/**
* The editor's Copy Path/Reference… chooser for files outside an editor (the Project view's
* selection): `rows`, then the rows contributed to the `copyPath` menu for `ctx`, with previews.
*/
export function openCopyPathChooser(...args: Parameters<CopyPathChooser>): void {
copyPathChooser?.(...args);
}
/** @internal editor/core only. */
export function _provideCopyPathChooser(open: CopyPathChooser) {
copyPathChooser = open;
}
let workspaceHistory: ((id: number, redo: boolean) => Promise<void>) | null = null;
/** Undo/redo a refactoring through the same history used by editor commands. */
+2 -11
Переглянути файл
@@ -3,16 +3,7 @@ import { tx } from "@/platform/i18n";
import { shortcutLabel } from "@/platform/keymap";
import { menuGroupItems, type MenuGroupContext } from "@/workbench/contributions";
import { openPopup, type ListPopupItem, type LspPopup, type PopupPoint } from "@/editor/lsp/popupStore";
export interface CopyPathRow {
/** The action whose shortcut the row shows. */
id: string;
/** English label, translated here. */
label: string;
/** The copied text; a row without one is left out. */
preview: string | null;
run: () => void;
}
import type { CopyPathRow } from "@/editor/api";
/** The chooser's popup: `rows`, then the rows contributed to the `copyPath` menu for `ctx`. */
export function copyPathPopup(
@@ -51,7 +42,7 @@ export function copyPathPopup(
};
}
/** Opens the chooser for files outside an editor (the Project view's selection). */
/** Opens the chooser for files outside an editor (`openCopyPathChooser` of `@/editor/api`). */
export function openCopyPathChooser(
anchor: PopupPoint | "center",
rows: readonly CopyPathRow[],
+3 -1
Переглянути файл
@@ -10,7 +10,8 @@ import {
registerOverlay,
registerStatusItem,
} from "@/workbench/contributions";
import { _provideCodePreview, _provideDocumentAttacher, editorsFor } from "@/editor/api";
import { _provideCodePreview, _provideCopyPathChooser, _provideDocumentAttacher, editorsFor } from "@/editor/api";
import { openCopyPathChooser } from "./copyPathChooser";
import { isUntitledUri } from "@/platform/virtualDocs";
import { formatDocument } from "@/editor/lsp/format";
import { chooserTitle, locationItems, pinToFind } from "@/editor/lsp/navigation";
@@ -82,6 +83,7 @@ export function activate(): void | (() => void) {
},
});
_provideDocumentAttacher((path, options) => attachDocument(ctrl.manager, path, options));
_provideCopyPathChooser(openCopyPathChooser);
_provideCodePreview((path, editable) =>
previewExtensions(path, ctrl.manager.settings()?.editor, ctrl.manager.backend, editable),
);
+4
Переглянути файл
@@ -9,6 +9,10 @@ import { contextMenuItems, keyLabel, revealLabel } from "./contextMenu";
import type { ProjectNode } from "./model";
import { useProjectTree } from "./store";
import { closePopup, useLspPopup } from "@/editor/lsp/popupStore";
import { _provideCopyPathChooser } from "@/editor/api";
import { openCopyPathChooser } from "@/editor/core/copyPathChooser";
_provideCopyPathChooser(openCopyPathChooser);
vi.mock("@/platform/ipc", async (importOriginal) => ({
...(await importOriginal<typeof import("@/platform/ipc")>()),