path -> uri build error fixes

This commit is contained in:
Dallin Romney 2024-12-13 15:55:22 -08:00
parent a3b5dd9e0c
commit aa72fcd64d
6 changed files with 23 additions and 22 deletions

View file

@ -45,7 +45,7 @@ import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
import { SYSTEM_PROMPT_DOT_FILE } from "./config/getSystemPromptDotFile";
import type { IMessenger, Message } from "./protocol/messenger";
import URI from "uri-js";
import { localPathToUri } from "./util/uri";
import { localPathToUri } from "./util/pathToUri";
export class Core {
// implements IMessenger<ToCoreProtocol, FromCoreProtocol>

View file

@ -1,7 +1,7 @@
import fs from "fs";
import os from "os";
import path from "path";
import { localPathOrUriToPath, localPathToUri } from "../util/uri";
import { localPathToUri, localPathOrUriToPath } from "../util/pathToUri";
// Want this outside of the git repository so we can change branches in tests
const TEST_DIR_PATH = path.join(os.tmpdir(), "testWorkspaceDir");

View file

@ -15,8 +15,6 @@ import {
ToastType,
} from "../index.d.js";
import { GetGhTokenArgs } from "../protocol/ide.js";
import { getContinueGlobalPath } from "./paths.js";
import { fileURLToPath } from "node:url";
class FileSystemIde implements IDE {

21
core/util/pathToUri.ts Normal file
View file

@ -0,0 +1,21 @@
import { fileURLToPath, pathToFileURL } from "url";
import URI from "uri-js";
// CAN ONLY BE USED IN CORE
// Converts a local path to a file:// URI
export function localPathToUri(path: string) {
const url = pathToFileURL(path);
return URI.normalize(url.toString());
}
export function localPathOrUriToPath(localPathOrUri: string): string {
try {
return fileURLToPath(localPathOrUri);
} catch (e) {
console.log("Received local filepath", localPathOrUri);
return localPathOrUri;
}
}

View file

@ -1,21 +1,4 @@
import URI from "uri-js";
import { fileURLToPath, pathToFileURL } from "url";
// Converts a local path to a file:// URI
export function localPathToUri(path: string) {
const url = pathToFileURL(path);
return URI.normalize(url.toString());
}
export function localPathOrUriToPath(localPathOrUri: string): string {
try {
return fileURLToPath(localPathOrUri);
} catch (e) {
console.log("Received local filepath", localPathOrUri);
return localPathOrUri;
}
}
/** Converts any OS path to cleaned up URI path segment format with no leading/trailing slashes
e.g. \path\to\folder\ -> path/to/folder

View file

@ -1,4 +1,3 @@
export { DiffViewerCodeLensProvider } from "./DiffViewerCodeLensProvider";
export { QuickActionsCodeLensProvider } from "./QuickActionsCodeLensProvider";
export { SuggestionsCodeLensProvider } from "./SuggestionsCodeLensProvider";
export { VerticalDiffCodeLensProvider as VerticalPerLineCodeLensProvider } from "./VerticalPerLineCodeLensProvider";