Skip to content

Commit

Permalink
chore: update providefileatinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Sma1lboy authored Dec 21, 2024
1 parent 09f7f30 commit 5244117
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions clients/vscode/src/chat/WebviewHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import {
uriToFileAtFileInfo,
} from "./utils";

import path from "path";

export class WebviewHelper {
webview?: Webview;
client?: ServerApi;
Expand Down Expand Up @@ -787,15 +789,33 @@ export class WebviewHelper {

return results.length > 0 ? results : null;
},

provideFileAtInfo: async (opts?: AtInputOpts): Promise<FileAtInfo[] | null> => {
const maxResults = opts?.limit || 50;
const query = opts?.query?.toLowerCase();
const query = opts?.query;

const globPattern = query ? `**/${query}*` : "**/*";
const globPattern = "**/*";
const excludePattern = "**/node_modules/**";
try {
const files = await workspace.findFiles(globPattern, null, maxResults);
return files.map((uri) => uriToFileAtFileInfo(uri, this.gitProvider));
const files = await workspace.findFiles(globPattern, excludePattern);

// start with
const filteredFiles = query
? files.filter((uri) =>
path.basename(uri.fsPath).toLowerCase().startsWith(query.toLowerCase());
)
: files;

// sort
const sortedFiles = filteredFiles.sort((a, b) => {
const nameA = a.fsPath.toLowerCase();
const nameB = b.fsPath.toLowerCase();
return nameA < nameB ? -1 : nameA > nameB ? 1 : 0;
});

// limit
const limitedFiles = sortedFiles.slice(0, maxResults);

return limitedFiles.map((uri) => uriToFileAtInfo(uri, this.gitProvider));
} catch (error) {
this.logger.error("Failed to find files:", error);
return null;
Expand Down

0 comments on commit 5244117

Please sign in to comment.