дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
151 рядки
5.4 KiB
TypeScript
151 рядки
5.4 KiB
TypeScript
/**
|
||
* editor/core: the text editor (CodeMirror 6), document sync with the Rust
|
||
* backend, tabs and splits, find/replace, navigation history and the editor
|
||
* status bar widgets. See editor/api.ts for the extension contract.
|
||
*/
|
||
import {
|
||
provideEditorArea,
|
||
provideEditorService,
|
||
registerEditorBanner,
|
||
registerOverlay,
|
||
registerStatusItem,
|
||
} from "@/workbench/contributions";
|
||
import { _provideCodePreview, _provideDocumentAttacher, editorsFor } from "@/editor/api";
|
||
import { isUntitledUri } from "@/platform/virtualDocs";
|
||
import { formatDocument } from "@/editor/lsp/format";
|
||
import { chooserTitle, locationItems, pinToFind } from "@/editor/lsp/navigation";
|
||
import { openPopup } from "@/editor/lsp/popupStore";
|
||
import { editorController } from "./controller";
|
||
import { attachDocument } from "./model/attachment";
|
||
import { previewExtensions } from "./cm/preview";
|
||
import { registerEditorActions } from "./actions";
|
||
import { registerLibrarySourcesActions } from "./librarySources";
|
||
import { installColorScheme } from "./colorSchemeRuntime";
|
||
import { documentBanner } from "./view/Banner";
|
||
import { EditorAreaView } from "./view/EditorArea";
|
||
import { GotoLineDialog } from "./view/GotoLineDialog";
|
||
import { PasteHistoryDialogHost, registerPasteHistoryActions } from "./view/PasteHistoryDialog";
|
||
import { NavBarPopup } from "./view/NavBarPopup";
|
||
import { installClipboardTracking } from "./clipboardHistory";
|
||
import {
|
||
CaretStatus,
|
||
EncodingStatus,
|
||
IndentStatus,
|
||
LineEndingStatus,
|
||
ReadOnlyStatus,
|
||
StatusBarBreadcrumbs,
|
||
} from "./view/StatusItems";
|
||
|
||
/** The workbench navigation bar (View › Appearance › Navigation Bar). */
|
||
export { Breadcrumbs } from "./view/StatusItems";
|
||
|
||
export function activate(): void | (() => void) {
|
||
const ctrl = editorController();
|
||
ctrl.start();
|
||
provideEditorService({
|
||
openFile: (path, options) => ctrl.openFile(path, options),
|
||
openInput: (input, options) => ctrl.openInput(input, options),
|
||
openUntitled: (options) => ctrl.openUntitled(options),
|
||
activePath: () => ctrl.activePath(),
|
||
activeCursor: () => ctrl.activeCursor(),
|
||
saveAll: (opts) => ctrl.saveAll(opts),
|
||
dirtyDocumentIds: () => [...ctrl.manager.byId.values()].filter((m) => m.getMeta().dirty).map((m) => m.doc),
|
||
untitledDirtyDocumentIds: () =>
|
||
[...ctrl.manager.byId.values()].filter((m) => isUntitledUri(m.path) && m.getMeta().dirty).map((m) => m.doc),
|
||
focus: () => ctrl.focus(),
|
||
openPaths: () => ctrl.openPaths(),
|
||
openTabs: () => ctrl.openTabs(),
|
||
tabInput: (paneId, tabId) => ctrl.tabInput(paneId, tabId),
|
||
activeInput: () => ctrl.activeInput(),
|
||
onActiveInputChange: (fn) => ctrl.onActiveInputChange(fn),
|
||
closePath: (path) => ctrl.closePath(path),
|
||
closeInput: (key) => ctrl.closeInput(key),
|
||
prepareClose: () => ctrl.prepareClose(),
|
||
cancelClose: () => ctrl.cancelClose(),
|
||
forgetSavedTabs: () => ctrl.forgetSavedTabs(),
|
||
keepSavedTabs: () => ctrl.keepSavedTabs(),
|
||
documentHistory: (command) => ctrl.documentHistory(command),
|
||
chooseDeclaration: async (targets, name, anchor) =>
|
||
openPopup({
|
||
kind: "list",
|
||
anchor,
|
||
title: chooserTitle("declaration", name, targets.length),
|
||
items: await locationItems(targets),
|
||
pin: pinToFind(name, targets),
|
||
}),
|
||
reformat: async (path) => {
|
||
const handle = editorsFor(path)[0];
|
||
return !!handle && (await formatDocument(handle.view, { explicit: false, selectionOnly: false })).applied;
|
||
},
|
||
});
|
||
_provideDocumentAttacher((path, options) => attachDocument(ctrl.manager, path, options));
|
||
_provideCodePreview((path, editable) =>
|
||
previewExtensions(path, ctrl.manager.settings()?.editor, ctrl.manager.backend, editable),
|
||
);
|
||
const disposers = [
|
||
installColorScheme(),
|
||
provideEditorArea(EditorAreaView),
|
||
registerEditorActions(),
|
||
registerLibrarySourcesActions(),
|
||
registerPasteHistoryActions(),
|
||
registerEditorBanner(documentBanner),
|
||
registerOverlay({ id: "editor.gotoLine", component: GotoLineDialog }),
|
||
registerOverlay({ id: "editor.pasteHistory", component: PasteHistoryDialogHost }),
|
||
registerOverlay({ id: "editor.navigationBar", component: NavBarPopup }),
|
||
installClipboardTracking(),
|
||
registerStatusItem({
|
||
id: "editor.breadcrumbs",
|
||
align: "left",
|
||
priority: 0,
|
||
component: StatusBarBreadcrumbs,
|
||
title: "Navigation Bar",
|
||
}),
|
||
registerStatusItem({
|
||
id: "editor.caret",
|
||
align: "right",
|
||
priority: 20,
|
||
component: CaretStatus,
|
||
title: "Line:Column Number",
|
||
lightEdit: true,
|
||
}),
|
||
registerStatusItem({
|
||
id: "editor.lineEnding",
|
||
align: "right",
|
||
priority: 30,
|
||
component: LineEndingStatus,
|
||
title: "Line Separator",
|
||
lightEdit: true,
|
||
}),
|
||
registerStatusItem({
|
||
id: "editor.encoding",
|
||
align: "right",
|
||
priority: 40,
|
||
component: EncodingStatus,
|
||
title: "File Encoding",
|
||
lightEdit: true,
|
||
}),
|
||
registerStatusItem({
|
||
id: "editor.indent",
|
||
align: "right",
|
||
priority: 50,
|
||
component: IndentStatus,
|
||
title: "Indentation",
|
||
lightEdit: true,
|
||
}),
|
||
registerStatusItem({
|
||
id: "editor.readOnly",
|
||
align: "right",
|
||
priority: 55,
|
||
component: ReadOnlyStatus,
|
||
title: "Read-only Attribute",
|
||
lightEdit: true,
|
||
}),
|
||
];
|
||
return () => {
|
||
disposers.reverse().forEach((d) => d());
|
||
_provideDocumentAttacher(null);
|
||
_provideCodePreview(null);
|
||
ctrl.stop();
|
||
};
|
||
}
|