Skip to content

Commit 5a9e95e

Browse files
Olasunkanmi OyinlolaOlasunkanmi Oyinlola
authored andcommitted
feat(workspace): Enhance file and directory exclusion during workspace indexing
- Add logic to exclude specific directories (node_modules, build, .git, dist) and files (package-lock.json, .vscode, .env) during workspace traversal. - Move the WorkspceSelector component to be rendered after the currenFile component.
1 parent e7f3917 commit 5a9e95e

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/services/workspace-service.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { randomUUID } from "crypto";
88
export class WorkspaceService implements IWorkspaceService {
99
private static instance: WorkspaceService;
1010
private readonly logger: Logger;
11+
private readonly excludedDirectories = ["node_modules", "build", ".git", "dist"];
12+
private readonly excludedFiles = ["package-lock.json", ".vscode", ".env"];
1113

1214
private constructor() {
1315
this.logger = new Logger(WorkspaceService.name);
@@ -40,9 +42,9 @@ export class WorkspaceService implements IWorkspaceService {
4042
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
4143
for (const entry of entries) {
4244
const fullPath = path.join(dir, entry.name);
43-
if (entry.isDirectory() && !entry.name.includes(".git")) {
45+
if (entry.isDirectory() && !this.excludedDirectories.some((dir) => entry.name.includes(dir))) {
4446
await this.traverseDirectory(fullPath, workspaceFiles);
45-
} else if (entry.isFile()) {
47+
} else if (entry.isFile() && !this.excludedFiles.some((file) => entry.name.includes(file))) {
4648
await this.readFileAndStore(fullPath, workspaceFiles);
4749
}
4850
}
@@ -116,10 +118,10 @@ export class WorkspaceService implements IWorkspaceService {
116118

117119
for (const entry of entries) {
118120
const fullPath = path.join(dir, entry.name);
119-
120-
if (entry.isDirectory() && !entry.name.includes(".git")) {
121+
console.log("Entry Name:", entry.name);
122+
if (entry.isDirectory() && this.excludedDirectories.some((dir) => entry.name.includes(dir))) {
121123
await this.traverseDirectoryForFolderMap(fullPath, folderToFilesMap);
122-
} else if (entry.isFile()) {
124+
} else if (entry.isFile() && !this.excludedFiles.some((file) => entry.name.includes(file))) {
123125
const rootPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
124126
if (rootPath) {
125127
const relativePath = path.relative(rootPath, fullPath);
@@ -150,10 +152,10 @@ export class WorkspaceService implements IWorkspaceService {
150152
for (const entry of entries) {
151153
const fullPath = path.join(dir, entry.name);
152154

153-
if (entry.isDirectory() && !entry.name.includes(".git")) {
155+
if (entry.isDirectory() && !this.excludedDirectories.some((dir) => entry.name.includes(dir))) {
154156
const childFolder = await this.traverseDirectoryForStructure(fullPath, rootPath);
155157
folderEntry.children.push(childFolder);
156-
} else if (entry.isFile()) {
158+
} else if (entry.isFile() && !this.excludedFiles.some((file) => entry.name.includes(file))) {
157159
const fileEntry: FileEntry = {
158160
id: randomUUID(),
159161
type: "file",

webviewUi/src/components/webview.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ export const WebviewUI = () => {
188188
}}
189189
>
190190
<div className="textarea-container">
191-
<WorkspceSelector onInputChange={handleAttachmentChange} folders={folders} />
192191
<div className="horizontal-stack">
193192
<span className="currenFile">
194193
<small>
@@ -197,6 +196,8 @@ export const WebviewUI = () => {
197196
</small>
198197
</span>
199198
</div>
199+
<WorkspceSelector onInputChange={handleAttachmentChange} folders={folders} />
200+
200201
<VSCodeTextArea
201202
value={userInput}
202203
onInput={handleTextChange}

0 commit comments

Comments
 (0)