fix(web): normalize Windows drive letter case for session path matching (#675)

On Windows, VS Code's uri.fsPath returns a lowercase drive letter
(e.g. d:\MyProject) while the OpenCode server stores paths using
process.cwd() which returns uppercase (D:\MyProject). This caused
session queries to return empty results due to case-sensitive string
comparison.

Normalize drive letters to uppercase in both the VS Code extension
(opencode.ts) and the shared UI client (client.ts) so that directory
paths match regardless of the source casing.

Fixes #670
This commit is contained in:
zerone0x
2026-03-17 11:29:50 +02:00
committed by GitHub
parent c4dc8b45cf
commit a07c068b66
2 changed files with 12 additions and 3 deletions
+7 -2
View File
@@ -467,8 +467,13 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
let status: ConnectionStatus = 'disconnected';
let lastError: string | undefined;
const listeners = new Set<(status: ConnectionStatus, error?: string) => void>();
/** On Windows, VS Code's uri.fsPath returns a lowercase drive letter (e.g. d:\...)
* while process.cwd() (used by OpenCode server) returns uppercase (D:\...).
* Normalize to uppercase so session directory queries match. */
const normalizeWindowsDriveLetter = (p: string): string =>
p.replace(/^([a-z]):/, (_, letter: string) => letter.toUpperCase() + ':');
const workspaceDirectory = (): string =>
vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || os.homedir();
normalizeWindowsDriveLetter(vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || os.homedir());
let workingDirectory: string = workspaceDirectory();
let startCount = 0;
let restartCount = 0;
@@ -577,7 +582,7 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
lastStartAttempts = startCount;
if (typeof workdir === 'string' && workdir.trim().length > 0) {
workingDirectory = workdir.trim();
workingDirectory = normalizeWindowsDriveLetter(workdir.trim());
} else {
workingDirectory = workspaceDirectory();
}