Files
arboretum/packages/vscode/src/views/repos-tree.ts
Johan LEROY cf7eb05aca feat(vscode): extension VS Code native (intégration native, pas un webview)
Nouveau workspace packages/vscode (git-arboretum, privé, non publié sur npm), client REST/WS
réutilisant @arboretum/shared. Auth Authorization: Bearer sur REST et l'upgrade WS (via `ws`) ;
un client Node sans en-tête Origin passe le check Origin strict du serveur.

- Arbres temps réel : Repositories (repos → worktrees → sessions) et Groups, via le WebSocket.
- Terminaux natifs (vscode.Pseudoterminal) pour attacher/observer une session — rendu et
  scrollback de VS Code ; décodage UTF-8 streaming + comptabilité ACK dans des modules purs.
- Status bar (compteur waiting) + notifications natives sur passage en waiting, réponses Yes/No
  via la commande WS answer.
- Mutations git (create worktree, commit, push, promote), start/kill/hide/resume/fork, session
  de groupe ; conscience du workspace (reveal + start/create here).
- Bundle esbuild (format cjs, external vscode) inlinant @arboretum/shared → VSIX autonome.
  Logique réutilisable sans import vscode → testée par vitest (19 tests).
- CI : .gitea/workflows/vscode-release.yml package le VSIX sur tag vscode-vX.Y.Z (artefact +
  asset de release best-effort). build:vscode hors du build principal (comme le site).
- spikes/s5-vscode/STUDY.md : décision de conception (GO phasé A→D), marquée implémentée.
2026-06-23 17:43:03 +02:00

86 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Arbre Repositories → Worktrees → Sessions, rafraîchi en temps réel (store.onDidChange).
// Les nœuds sont reconstruits et mis en cache à chaque changement pour donner une identité stable à
// getParent()/reveal() (conscience du workspace, Phase D).
import * as vscode from 'vscode';
import type { Store } from '../state/store.js';
import type { ReposNode } from './nodes.js';
import { repoTreeItem, sessionTreeItem, worktreeTreeItem } from './tree-items.js';
function normPath(p: string): string {
return p.replace(/\/+$/, '') || '/';
}
export class ReposTreeProvider implements vscode.TreeDataProvider<ReposNode> {
private readonly changeEmitter = new vscode.EventEmitter<ReposNode | undefined>();
readonly onDidChangeTreeData = this.changeEmitter.event;
private readonly repoNodes = new Map<string, ReposNode>();
private readonly worktreeNodes = new Map<string, ReposNode>();
constructor(private readonly store: Store) {
store.onDidChange(() => {
this.rebuild();
this.changeEmitter.fire(undefined);
});
this.rebuild();
}
private wtKey(repoId: string, path: string): string {
return `${repoId}${normPath(path)}`;
}
private rebuild(): void {
this.repoNodes.clear();
this.worktreeNodes.clear();
for (const repo of this.store.listRepos()) {
this.repoNodes.set(repo.id, { kind: 'repo', repo });
for (const worktree of this.store.listWorktrees(repo.id)) {
this.worktreeNodes.set(this.wtKey(repo.id, worktree.path), { kind: 'worktree', repoId: repo.id, worktree });
}
}
}
/** nœud worktree mis en cache (pour reveal depuis le mapping workspace). */
worktreeNode(repoId: string, path: string): ReposNode | undefined {
return this.worktreeNodes.get(this.wtKey(repoId, path));
}
getTreeItem(node: ReposNode): vscode.TreeItem {
switch (node.kind) {
case 'repo':
return repoTreeItem(node.repo);
case 'worktree':
return worktreeTreeItem(node.worktree);
case 'session': {
const item = sessionTreeItem(node.session);
if (node.session.live) {
item.command = { command: 'arboretum.attachSession', title: 'Attach', arguments: [node] };
}
return item;
}
}
}
getChildren(node?: ReposNode): ReposNode[] {
if (!node) return [...this.repoNodes.values()];
if (node.kind === 'repo') {
return this.store
.listWorktrees(node.repo.id)
.map((worktree) => this.worktreeNodes.get(this.wtKey(node.repo.id, worktree.path)))
.filter((n): n is ReposNode => n !== undefined);
}
if (node.kind === 'worktree') {
return this.store
.sessionsForWorktree(node.worktree.path)
.map((session) => ({ kind: 'session', session, repoId: node.repoId, worktreePath: node.worktree.path }));
}
return [];
}
getParent(node: ReposNode): ReposNode | undefined {
if (node.kind === 'repo') return undefined;
if (node.kind === 'worktree') return this.repoNodes.get(node.repoId);
return this.worktreeNodes.get(this.wtKey(node.repoId, node.worktreePath));
}
}