Skip to content

Commit

Permalink
Correctly compute log relative path on windows (#762)
Browse files Browse the repository at this point in the history
* Correctly compute log relative path on windows

* Simplify fix to manipulate only strings

---------

Co-authored-by: jjallaire <[email protected]>
  • Loading branch information
dragonstyle and jjallaire authored Oct 25, 2024
1 parent 3d53ebf commit 6c2a8c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions tools/vscode/src/core/uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,22 @@ export function getRelativeUri(parentUri: Uri, childUri: Uri): string | null {
}
return childStr.slice(parentStr.length);
}
}

export function normalizeWindowsUri(uri: string) {
if (os.platform() === "win32") {
// Check if the URI is already correctly formatted
const windowsFilePattern = /^file:\/\/\/[a-zA-Z]:\\/;
if (windowsFilePattern.test(uri)) {
return uri;
}

// If not, correct the URI to have the right number of slashes
const malformedPattern = /^file:\/\/([a-zA-Z]):\//;
const correctedUri = uri.replace(malformedPattern, 'file:///$1:/');

return correctedUri;
} else {
return uri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExtensionContext, Uri } from "vscode";
import { InspectViewServer } from "../../inspect/inspect-view-server";
import { log } from "../../../core/log";
import { LogListingMRU } from "./log-listing-mru";
import { normalizeWindowsUri } from "../../../core/uri";

export type LogNode =
| { type: "dir", parent?: LogNode } & LogDirectory
Expand Down Expand Up @@ -106,9 +107,9 @@ export class LogListing {
const logsJSON = await this.viewServer_.evalLogs(this.logDir_);
if (logsJSON) {
const logs = JSON.parse(logsJSON) as { log_dir: string; files: LogFile[] };
const log_dir = logs.log_dir.endsWith("/") ? logs.log_dir : `${logs.log_dir}/`;
const log_dir = normalizeWindowsUri(logs.log_dir.endsWith("/") ? logs.log_dir : `${logs.log_dir}/`);
for (const file of logs.files) {
file.name = file.name.replace(`${log_dir}`, "");
file.name = normalizeWindowsUri(file.name).replace(`${log_dir}`, "");
}
const tree = buildLogTree(logs.files);
return tree;
Expand Down

0 comments on commit 6c2a8c4

Please sign in to comment.