Files
openidea/src/features/vcs/annotateRevisionProvider.ts
T
Muuandmuutot 83b9744a36 feat(vcs): annotate the file as of an earlier revision (#3265)
The annotation gutter's menu gains IDEA's annotate family:

- Annotate Previous Revision opens the file at the first parent of the annotated line's commit next to the commit's version, with the previous side annotated; on a file's first commit it says there is no previous revision.
- Annotate at Revision… opens the file's revision chooser and shows the picked revision annotated next to the working copy, following renames through historyPath.

One diff viewer provider annotates the left pane once per diff, so annotations the user closes stay closed when the panes rebuild. The diff opens at its first change, since the annotated line's number belongs to the working copy.

Co-authored-by: muutot <92625353+muutot@users.noreply.github.com>
2026-11-14 10:38:39 +08:00

28 lines
1.1 KiB
TypeScript

/** Annotates the left (historical) pane of a diff opened by an annotate action. */
import { toggleAnnotations } from "./blame";
import type { DiffViewerContribution, DiffViewerHost } from "./diffViewerProviders";
import { registerDiffViewerProvider } from "./diffViewerProviders";
import type { DiffData } from "./diffInput";
/** A diff is annotated once: rebuilding its panes must not reopen closed annotations. */
const annotated = new WeakSet<DiffData>();
class LeftPaneAnnotations implements DiffViewerContribution {
constructor(private readonly data: DiffData) {}
attach(host: DiffViewerHost): void {
const left = this.data.left;
const pane = host.panes().find((p) => p.side === "left");
if (!pane || left.type !== "rev" || annotated.has(this.data)) return;
annotated.add(this.data);
void toggleAnnotations(pane.view, this.data.path, host.doc("left").toString(), left.rev);
}
}
export function activateRevisionAnnotations(): () => void {
return registerDiffViewerProvider({
id: "vcs.annotateRevision",
create: (data) => (data.annotateLeft ? new LeftPaneAnnotations(data) : null),
});
}