use existing function

This commit is contained in:
Nate 2024-12-18 22:50:05 -08:00
parent f65704f6ad
commit 7fe6ac1159
2 changed files with 7 additions and 20 deletions

View file

@ -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 [
{

View file

@ -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];
}