Skip to content

Commit e3bc1be

Browse files
committed
Remove redundant fileExists check from absolute path suggestions
1 parent e9b6f1d commit e3bc1be

4 files changed

Lines changed: 8 additions & 33 deletions

File tree

apps/code/src/main/services/fs/schemas.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const fileEntry = z.object({
2929

3030
export const listRepoFilesOutput = z.array(fileEntry);
3131
export const readRepoFileOutput = z.string().nullable();
32-
export const fileExistsOutput = z.boolean();
3332

3433
export type ListRepoFilesInput = z.infer<typeof listRepoFilesInput>;
3534
export type ReadRepoFileInput = z.infer<typeof readRepoFileInput>;

apps/code/src/main/services/fs/service.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ export class FsService {
9797
}
9898
}
9999

100-
async fileExists(filePath: string): Promise<boolean> {
101-
try {
102-
const stat = await fs.promises.stat(path.resolve(filePath));
103-
return stat.isFile();
104-
} catch {
105-
return false;
106-
}
107-
}
108-
109100
async readAbsoluteFile(filePath: string): Promise<string | null> {
110101
try {
111102
return await fs.promises.readFile(path.resolve(filePath), "utf-8");

apps/code/src/main/trpc/routers/fs.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { container } from "../../di/container";
22
import { MAIN_TOKENS } from "../../di/tokens";
33
import {
4-
fileExistsOutput,
54
listRepoFilesInput,
65
listRepoFilesOutput,
76
readAbsoluteFileInput,
@@ -34,11 +33,6 @@ export const fsRouter = router({
3433
.output(readRepoFileOutput)
3534
.query(({ input }) => getService().readAbsoluteFile(input.filePath)),
3635

37-
fileExists: publicProcedure
38-
.input(readAbsoluteFileInput)
39-
.output(fileExistsOutput)
40-
.query(({ input }) => getService().fileExists(input.filePath)),
41-
4236
readFileAsBase64: publicProcedure
4337
.input(readAbsoluteFileInput)
4438
.output(readRepoFileOutput)

apps/code/src/renderer/features/message-editor/suggestions/getSuggestions.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
pathToFileItem,
77
searchFiles,
88
} from "@hooks/useRepoFiles";
9-
import { trpcClient } from "@renderer/trpc/client";
109
import { isAbsolutePath } from "@utils/path";
1110
import Fuse, { type IFuseOptions } from "fuse.js";
1211
import { useDraftStore } from "../stores/draftStore";
@@ -50,19 +49,10 @@ function parentDirLabel(dir: string, name: string): string {
5049
return parent ? `${parent}/${name}` : name;
5150
}
5251

53-
async function getAbsolutePathSuggestion(
54-
query: string,
55-
): Promise<FileSuggestionItem | null> {
52+
function getAbsolutePathSuggestion(query: string): FileSuggestionItem | null {
5653
if (!isAbsolutePath(query)) return null;
5754
if (!/\.\w+$/.test(query)) return null;
5855

59-
try {
60-
const exists = await trpcClient.fs.fileExists.query({ filePath: query });
61-
if (!exists) return null;
62-
} catch {
63-
return null;
64-
}
65-
6656
const fileItem = pathToFileItem(query);
6757
return {
6858
id: query,
@@ -78,11 +68,10 @@ export async function getFileSuggestions(
7868
query: string,
7969
): Promise<FileSuggestionItem[]> {
8070
const repoPath = useDraftStore.getState().contexts[sessionId]?.repoPath;
81-
const absolutePathSuggestion = getAbsolutePathSuggestion(query);
71+
const absoluteMatch = getAbsolutePathSuggestion(query);
8272

8373
if (!repoPath) {
84-
const resolved = await absolutePathSuggestion;
85-
return resolved ? [resolved] : [];
74+
return absoluteMatch ? [absoluteMatch] : [];
8675
}
8776

8877
const { files, fzf } = await fetchRepoFiles(repoPath);
@@ -96,9 +85,11 @@ export async function getFileSuggestions(
9685
path: file.path,
9786
}));
9887

99-
const resolved = await absolutePathSuggestion;
100-
if (resolved && !results.some((r) => `${repoPath}/${r.id}` === resolved.id)) {
101-
results.unshift(resolved);
88+
if (
89+
absoluteMatch &&
90+
!results.some((r) => `${repoPath}/${r.id}` === absoluteMatch.id)
91+
) {
92+
results.unshift(absoluteMatch);
10293
}
10394

10495
return results;

0 commit comments

Comments
 (0)