M4.7: blame annotations in the editor gutter

- crates/vcs: blame.rs (git blame --porcelain, --contents - from a
  buffer, revisions, untracked files and empty repositories give no
  lines; property-tested parser, ISO dates without a date crate)
- engine: git.blame {path, rev?} -> {lines, version} through start_with;
  an open buffer is blamed as it would be saved (line ending, BOM)
- ui: blame.ts gutter toggled per file (vcs.toggleBlame, Git menu, no
  shortcut), date + author per run, bar coloured by age from tokens,
  hover card with the full commit message, click opens the commit in
  the Log (vcs.showCommit); refreshed on edits and gitChanged
- docs: architecture "Blame (M4.7)"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-30 17:52:44 +01:00
parent dc4a00ea0b
commit 2f758d76b9
18 changed files with 2003 additions and 3 deletions

View file

@ -33,6 +33,10 @@
* tab opens. The Log tab (M4.6) appears with `vcs.showLog` and with
* `vcs.showHistory {path?}` (the history of a file or folder; without a
* path, of the active editor tab's file); neither has a default shortcut.
* `vcs.showCommit {hash}` (M4.7) shows the Log with that commit selected
* (a click on a blame annotation); `vcs.toggleBlame {path?}` shows or
* hides the blame annotations of a file (default: the active tab's). No
* default shortcuts.
*
* A slim header bar along the top (M3.9) holds the app menu
* ({@link AppMenu}); its `header` slot can replace it.
@ -54,6 +58,7 @@ import { useChangesStore } from "../vcs/changes/changes";
import LogToolWindow from "../vcs/log/LogToolWindow.vue";
import { SHOW_HISTORY_COMMAND, SHOW_LOG_COMMAND, useLogStore } from "../vcs/log/log";
import StashDialog from "../vcs/stash/StashDialog.vue";
import { SHOW_COMMIT_COMMAND, TOGGLE_BLAME_COMMAND, setCommitOpener, toggleBlame } from "../editor/blame";
import { useEditorStore } from "../../stores/editor";
import { useProjectStore } from "../../stores/project";
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
@ -174,6 +179,7 @@ onMounted(() => {
problems.start();
changes.start();
vcsLog.start();
setCommitOpener((hash) => void commands.execute(SHOW_COMMIT_COMMAND, { hash }));
withdraw = [
commands.provide("view.toggleProjectTree", {
run: () => {
@ -229,6 +235,28 @@ onMounted(() => {
},
enabled: () => project.root !== null,
}),
commands.provide(SHOW_COMMIT_COMMAND, {
run: async (params) => {
const hash = (params as { hash?: unknown } | null)?.hash;
if (typeof hash !== "string" || !/^[0-9a-f]{4,64}$/i.test(hash)) {
return;
}
bottomTool.value = "log";
await vcsLog.open();
await vcsLog.select(hash);
},
enabled: () => project.root !== null,
}),
commands.provide(TOGGLE_BLAME_COMMAND, {
run: (params) => {
const given = (params as { path?: unknown } | null)?.path;
const path = typeof given === "string" && given !== "" ? given : editor.activeTab?.path;
if (path !== undefined) {
toggleBlame(path);
}
},
enabled: () => project.root !== null,
}),
commands.provide("view.toggleStructure", {
run: () => {
toggleLeft("structure");
@ -242,6 +270,7 @@ onBeforeUnmount(() => {
fn();
}
withdraw = [];
setCommitOpener(() => undefined);
find.stop();
terminal.stop();
problems.stop();