From aa72fcd64df97e3bc085843f4eb42bc8956c5813 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 13 Dec 2024 15:55:22 -0800 Subject: [PATCH] path -> uri build error fixes --- core/core.ts | 2 +- core/test/testDir.ts | 2 +- core/util/filesystem.ts | 2 -- core/util/pathToUri.ts | 21 +++++++++++++++++++ core/util/uri.ts | 17 --------------- .../lang-server/codeLens/providers/index.ts | 1 - 6 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 core/util/pathToUri.ts diff --git a/core/core.ts b/core/core.ts index 09cded385..a9a45634b 100644 --- a/core/core.ts +++ b/core/core.ts @@ -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 diff --git a/core/test/testDir.ts b/core/test/testDir.ts index b79624e1d..098075c34 100644 --- a/core/test/testDir.ts +++ b/core/test/testDir.ts @@ -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"); diff --git a/core/util/filesystem.ts b/core/util/filesystem.ts index 886e58e10..1dc5e556c 100644 --- a/core/util/filesystem.ts +++ b/core/util/filesystem.ts @@ -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 { diff --git a/core/util/pathToUri.ts b/core/util/pathToUri.ts new file mode 100644 index 000000000..a8d1b3a7f --- /dev/null +++ b/core/util/pathToUri.ts @@ -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; + } +} diff --git a/core/util/uri.ts b/core/util/uri.ts index f110a870a..25d42efba 100644 --- a/core/util/uri.ts +++ b/core/util/uri.ts @@ -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 diff --git a/extensions/vscode/src/lang-server/codeLens/providers/index.ts b/extensions/vscode/src/lang-server/codeLens/providers/index.ts index 8285b1fe5..00a309e62 100644 --- a/extensions/vscode/src/lang-server/codeLens/providers/index.ts +++ b/extensions/vscode/src/lang-server/codeLens/providers/index.ts @@ -1,4 +1,3 @@ -export { DiffViewerCodeLensProvider } from "./DiffViewerCodeLensProvider"; export { QuickActionsCodeLensProvider } from "./QuickActionsCodeLensProvider"; export { SuggestionsCodeLensProvider } from "./SuggestionsCodeLensProvider"; export { VerticalDiffCodeLensProvider as VerticalPerLineCodeLensProvider } from "./VerticalPerLineCodeLensProvider";