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:
@@ -199,7 +199,11 @@ class OpencodeService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalized = trimmed.replace(/\\/g, '/');
|
// Normalize backslashes and uppercase the Windows drive letter so that
|
||||||
|
// d:\MyProject and D:\MyProject resolve to the same canonical form.
|
||||||
|
const normalized = trimmed
|
||||||
|
.replace(/\\/g, '/')
|
||||||
|
.replace(/^([a-z]):/, (_, letter: string) => letter.toUpperCase() + ':');
|
||||||
const withoutTrailingSlash = normalized.length > 1 ? normalized.replace(/\/+$/, '') : normalized;
|
const withoutTrailingSlash = normalized.length > 1 ? normalized.replace(/\/+$/, '') : normalized;
|
||||||
|
|
||||||
return withoutTrailingSlash || null;
|
return withoutTrailingSlash || null;
|
||||||
|
|||||||
@@ -467,8 +467,13 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
|
|||||||
let status: ConnectionStatus = 'disconnected';
|
let status: ConnectionStatus = 'disconnected';
|
||||||
let lastError: string | undefined;
|
let lastError: string | undefined;
|
||||||
const listeners = new Set<(status: ConnectionStatus, error?: string) => void>();
|
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 =>
|
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 workingDirectory: string = workspaceDirectory();
|
||||||
let startCount = 0;
|
let startCount = 0;
|
||||||
let restartCount = 0;
|
let restartCount = 0;
|
||||||
@@ -577,7 +582,7 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
|
|||||||
lastStartAttempts = startCount;
|
lastStartAttempts = startCount;
|
||||||
|
|
||||||
if (typeof workdir === 'string' && workdir.trim().length > 0) {
|
if (typeof workdir === 'string' && workdir.trim().length > 0) {
|
||||||
workingDirectory = workdir.trim();
|
workingDirectory = normalizeWindowsDriveLetter(workdir.trim());
|
||||||
} else {
|
} else {
|
||||||
workingDirectory = workspaceDirectory();
|
workingDirectory = workspaceDirectory();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user