From 7fe6ac1159b6c4034c2f406a72d341fad290eccc Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 18 Dec 2024 22:50:05 -0800 Subject: [PATCH] use existing function --- core/tools/implementations/readFile.ts | 10 +++++++--- core/util/uri.ts | 17 ----------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/core/tools/implementations/readFile.ts b/core/tools/implementations/readFile.ts index 2653b3730..787955b5b 100644 --- a/core/tools/implementations/readFile.ts +++ b/core/tools/implementations/readFile.ts @@ -1,12 +1,16 @@ -import { firstAbsUriMatch, getUriPathBasename } from "../../util/uri"; +import { getUriPathBasename } from "../../util/uri"; import { ToolImpl } from "."; +import { resolveRelativePathInDir } from "../../util/ideUtils"; export const readFileImpl: ToolImpl = async (args, extras) => { - const firstUriMatch = await firstAbsUriMatch( + const firstUriMatch = await resolveRelativePathInDir( args.filepath, - await extras.ide.getWorkspaceDirs(), + extras.ide, ); + if (!firstUriMatch) { + throw new Error(`Could not find file ${args.filepath}`); + } const content = await extras.ide.readFile(firstUriMatch); return [ { diff --git a/core/util/uri.ts b/core/util/uri.ts index 7842ced10..49a9e8389 100644 --- a/core/util/uri.ts +++ b/core/util/uri.ts @@ -188,20 +188,3 @@ export function getLastNPathParts(filepath: string, n: number): string { } return filepath.split(/[\\/]/).slice(-n).join("/"); } - -export function firstAbsUriMatch( - relativePath: string, - workspaceDirUris: string[], -): string { - const cleanRelativePath = pathToUriPathSegment(relativePath); - - return workspaceDirUris - .map((dirUri) => { - try { - return joinPathsToUri(dirUri, cleanRelativePath); - } catch { - return null; - } - }) - .filter((uri): uri is string => uri !== null)[0]; -}