use existing function
This commit is contained in:
parent
f65704f6ad
commit
7fe6ac1159
2 changed files with 7 additions and 20 deletions
|
|
@ -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 [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue