Windows daemon paths like C:\Users\... don't start with "/", breaking the explorer sidebar, checkout status, terminals, and file attachments when connected to a Windows daemon. Consolidate three private isAbsolutePath implementations into a shared utility and use it everywhere, with correct file URI conversion for Windows and UNC paths.
35 lines
933 B
TypeScript
35 lines
933 B
TypeScript
import { isAbsolutePath } from "./path";
|
|
|
|
interface BuildAbsoluteExplorerPathInput {
|
|
workspaceRoot: string;
|
|
entryPath: string;
|
|
}
|
|
|
|
export function buildAbsoluteExplorerPath({
|
|
workspaceRoot,
|
|
entryPath,
|
|
}: BuildAbsoluteExplorerPathInput): string {
|
|
const normalizedWorkspaceRoot = workspaceRoot.trim().replace(/[\\/]+$/, "");
|
|
const normalizedEntryPath = entryPath.trim();
|
|
|
|
if (!normalizedWorkspaceRoot) {
|
|
return normalizedEntryPath;
|
|
}
|
|
|
|
if (!normalizedEntryPath || normalizedEntryPath === ".") {
|
|
return normalizedWorkspaceRoot;
|
|
}
|
|
|
|
if (isAbsolutePath(normalizedEntryPath)) {
|
|
return normalizedEntryPath;
|
|
}
|
|
|
|
const separator = normalizedWorkspaceRoot.includes("\\") ? "\\" : "/";
|
|
const segments = normalizedEntryPath.split(/[\\/]+/).filter(Boolean);
|
|
if (segments.length === 0) {
|
|
return normalizedWorkspaceRoot;
|
|
}
|
|
|
|
return `${normalizedWorkspaceRoot}${separator}${segments.join(separator)}`;
|
|
}
|