Skip to content

Commit cf83dab

Browse files
committed
Fix directory exclusion logic by properly appending trailing slashes to directory paths in ignore pattern checks
1 parent 10cf735 commit cf83dab

1 file changed

Lines changed: 77 additions & 19 deletions

File tree

packages/vscode/src/context/providers/workspace-provider.ts

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,21 @@ export class WorkspaceProvider
355355
const parent_dir = path.dirname(created_file_path)
356356
const relative_path = path.relative(workspace_root, created_file_path)
357357

358+
let is_directory = false
359+
try {
360+
is_directory = fs.statSync(created_file_path).isDirectory()
361+
} catch {
362+
// Ignore if file was deleted quickly
363+
}
364+
358365
if (
359-
!this.is_excluded(relative_path) &&
366+
!this.is_excluded(is_directory ? relative_path + '/' : relative_path) &&
360367
!this.is_ignored_by_patterns(created_file_path)
361368
) {
362369
this.checked_items.set(
363370
created_file_path,
364371
vscode.TreeItemCheckboxState.Checked
365372
)
366-
const is_directory = fs.statSync(created_file_path).isDirectory()
367373

368374
if (is_directory) {
369375
await this._update_directory_check_state(
@@ -575,7 +581,12 @@ export class WorkspaceProvider
575581
const workspace_root = this.get_workspace_root_for_file(dir_path)
576582
if (workspace_root) {
577583
const relative_path = path.relative(workspace_root, dir_path)
578-
if (this.is_excluded(relative_path)) {
584+
// Ensure we check directory exclusions with a trailing slash
585+
if (
586+
this.is_excluded(
587+
relative_path ? relative_path + '/' : relative_path
588+
)
589+
) {
579590
return []
580591
}
581592
}
@@ -609,7 +620,11 @@ export class WorkspaceProvider
609620
const workspace_root = this.get_workspace_root_for_file(dir_path)
610621
if (workspace_root) {
611622
const relative_path = path.relative(workspace_root, dir_path)
612-
if (this.is_excluded(relative_path)) {
623+
if (
624+
this.is_excluded(
625+
relative_path ? relative_path + '/' : relative_path
626+
)
627+
) {
613628
return []
614629
}
615630
}
@@ -832,7 +847,11 @@ export class WorkspaceProvider
832847
}
833848

834849
const relative_dir_path = path.relative(workspace_root, dir_path)
835-
if (this.is_excluded(relative_dir_path)) {
850+
if (
851+
this.is_excluded(
852+
relative_dir_path ? relative_dir_path + '/' : relative_dir_path
853+
)
854+
) {
836855
this.directory_token_counts.set(dir_path, 0)
837856
return 0
838857
}
@@ -846,7 +865,11 @@ export class WorkspaceProvider
846865
const full_path = path.join(dir_path, entry.name)
847866
const relative_path = path.relative(workspace_root, full_path)
848867

849-
if (this.is_excluded(relative_path)) {
868+
if (
869+
this.is_excluded(
870+
entry.isDirectory() ? relative_path + '/' : relative_path
871+
)
872+
) {
850873
continue
851874
}
852875

@@ -916,7 +939,11 @@ export class WorkspaceProvider
916939
}
917940

918941
const relative_dir_path = path.relative(workspace_root, dir_path)
919-
if (this.is_excluded(relative_dir_path)) {
942+
if (
943+
this.is_excluded(
944+
relative_dir_path ? relative_dir_path + '/' : relative_dir_path
945+
)
946+
) {
920947
this.directory_selected_token_counts.set(dir_path, 0)
921948
return 0
922949
}
@@ -929,7 +956,9 @@ export class WorkspaceProvider
929956
const relative_path = path.relative(workspace_root, full_path)
930957

931958
if (
932-
this.is_excluded(relative_path) ||
959+
this.is_excluded(
960+
entry.isDirectory() ? relative_path + '/' : relative_path
961+
) ||
933962
this.is_ignored_by_patterns(full_path)
934963
) {
935964
continue
@@ -989,7 +1018,9 @@ export class WorkspaceProvider
9891018
const relative_dir_path = path.relative(workspace_root, dir_path)
9901019
if (
9911020
dir_path !== workspace_root && // Don't exclude workspace roots
992-
this.is_excluded(relative_dir_path)
1021+
this.is_excluded(
1022+
relative_dir_path ? relative_dir_path + '/' : relative_dir_path
1023+
)
9931024
) {
9941025
return []
9951026
}
@@ -1034,7 +1065,9 @@ export class WorkspaceProvider
10341065
}
10351066
}
10361067

1037-
const is_excluded = this.is_excluded(relative_path)
1068+
const is_excluded = this.is_excluded(
1069+
entry.isDirectory() ? relative_path + '/' : relative_path
1070+
)
10381071
if (is_excluded) {
10391072
continue
10401073
}
@@ -1163,7 +1196,11 @@ export class WorkspaceProvider
11631196
if (!workspace_root) return
11641197

11651198
const relative_dir_path = path.relative(workspace_root, dir_path)
1166-
if (this.is_excluded(relative_dir_path)) {
1199+
if (
1200+
this.is_excluded(
1201+
relative_dir_path ? relative_dir_path + '/' : relative_dir_path
1202+
)
1203+
) {
11671204
// If directory is excluded, ensure it's unchecked
11681205
this.checked_items.set(dir_path, vscode.TreeItemCheckboxState.Unchecked)
11691206
this.partially_checked_dirs.delete(dir_path)
@@ -1183,7 +1220,9 @@ export class WorkspaceProvider
11831220
const relative_path = path.relative(workspace_root, sibling_path)
11841221

11851222
if (
1186-
this.is_excluded(relative_path) ||
1223+
this.is_excluded(
1224+
entry.isDirectory() ? relative_path + '/' : relative_path
1225+
) ||
11871226
this.is_ignored_by_patterns(sibling_path)
11881227
) {
11891228
continue
@@ -1254,7 +1293,12 @@ export class WorkspaceProvider
12541293
this.directory_selected_token_counts.delete(dir_path)
12551294

12561295
const relative_dir_path = path.relative(workspace_root, dir_path)
1257-
if (this.is_excluded(relative_dir_path) || parent_is_excluded) {
1296+
if (
1297+
this.is_excluded(
1298+
relative_dir_path ? relative_dir_path + '/' : relative_dir_path
1299+
) ||
1300+
parent_is_excluded
1301+
) {
12581302
return
12591303
}
12601304

@@ -1272,7 +1316,9 @@ export class WorkspaceProvider
12721316
const relative_path = path.relative(workspace_root, full_path)
12731317

12741318
if (
1275-
this.is_excluded(relative_path) ||
1319+
this.is_excluded(
1320+
entry.isDirectory() ? relative_path + '/' : relative_path
1321+
) ||
12761322
this.is_ignored_by_patterns(full_path)
12771323
) {
12781324
continue
@@ -1346,11 +1392,17 @@ export class WorkspaceProvider
13461392
const workspace_root = this.get_workspace_root_for_file(file_path)
13471393
if (!workspace_root) continue
13481394

1395+
const stats = fs.lstatSync(file_path)
1396+
const is_directory = stats.isDirectory()
1397+
13491398
const relative_path = path.relative(workspace_root, file_path)
1350-
if (this.is_excluded(relative_path)) continue
1399+
if (
1400+
this.is_excluded(is_directory ? relative_path + '/' : relative_path)
1401+
) {
1402+
continue
1403+
}
13511404

1352-
const stats = fs.lstatSync(file_path)
1353-
if (stats.isDirectory()) {
1405+
if (is_directory) {
13541406
this.checked_items.set(file_path, vscode.TreeItemCheckboxState.Checked)
13551407
await this._update_directory_check_state(
13561408
file_path,
@@ -1560,7 +1612,9 @@ export class WorkspaceProvider
15601612
const relative_dir_path = path.relative(workspace_root, dir_path)
15611613
if (
15621614
dir_path !== workspace_root && // Don't exclude the root itself
1563-
this.is_excluded(relative_dir_path)
1615+
this.is_excluded(
1616+
relative_dir_path ? relative_dir_path + '/' : relative_dir_path
1617+
)
15641618
) {
15651619
return
15661620
}
@@ -1574,7 +1628,11 @@ export class WorkspaceProvider
15741628
const full_path = path.join(dir_path, entry.name)
15751629
const relative_path = path.relative(workspace_root, full_path)
15761630

1577-
if (this.is_excluded(relative_path)) {
1631+
if (
1632+
this.is_excluded(
1633+
entry.isDirectory() ? relative_path + '/' : relative_path
1634+
)
1635+
) {
15781636
continue
15791637
}
15801638

0 commit comments

Comments
 (0)