Add proper VS Code multi-root workspace support. New sessions now start in the workspace folder the user chooses instead of always using the first folder. The VS Code sidebar now shows one shared flat session list for the currently opened workspace folders, keeps that list synced when folders are added or removed, and excludes sessions from worktrees unless that worktree is opened as a workspace folder. Also keep the OpenCode server process independent from a specific workspace folder so changing the selected folder does not restart or interrupt existing sessions.
27 lines
734 B
TypeScript
27 lines
734 B
TypeScript
import { normalizeWindowsDriveLetter } from './pathUtils';
|
|
|
|
export interface WorkspaceFolderInput {
|
|
name: string;
|
|
uri: { fsPath: string };
|
|
}
|
|
|
|
export interface WorkspaceFolderCandidate {
|
|
name: string;
|
|
path: string;
|
|
}
|
|
|
|
export function resolveWorkspaceFolders(
|
|
folders: ReadonlyArray<WorkspaceFolderInput>
|
|
): WorkspaceFolderCandidate[] {
|
|
const seen = new Map<string, WorkspaceFolderCandidate>();
|
|
for (const folder of folders) {
|
|
const path = normalizeWindowsDriveLetter(folder.uri.fsPath).replace(/[\\/]+$/, '');
|
|
if (!seen.has(path)) {
|
|
seen.set(path, { name: folder.name, path });
|
|
}
|
|
}
|
|
return [...seen.values()].sort((a, b) =>
|
|
a.name.localeCompare(b.name, undefined, { sensitivity: 'base' })
|
|
);
|
|
}
|