Skip to content

Commit 0689536

Browse files
committed
feat: throw an error when too many files selected (temp)
1 parent 6824fbe commit 0689536

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/main/java/ee/carlrobert/codegpt/ui/checkbox/PsiElementCheckboxTree.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ public PsiElementCheckboxTree(@NotNull PsiElement rootElement) {
2424
}
2525

2626
public List<CheckedFile> getCheckedFiles() {
27-
return Arrays.stream(getCheckedNodes(
28-
PsiElement.class,
29-
node -> Optional.ofNullable(node.getContainingFile())
30-
.map(PsiFile::getVirtualFile)
31-
.isPresent()))
27+
var checkedNodes = getCheckedNodes(
28+
PsiElement.class,
29+
node -> Optional.ofNullable(node.getContainingFile())
30+
.map(PsiFile::getVirtualFile)
31+
.isPresent());
32+
if (checkedNodes.length > 1000) {
33+
throw new RuntimeException("Too many files selected");
34+
}
35+
36+
return Arrays.stream(checkedNodes)
3237
.map(item -> new CheckedFile(new File(item.getContainingFile().getVirtualFile().getPath())))
3338
.collect(toList());
3439
}

src/main/java/ee/carlrobert/codegpt/ui/checkbox/VirtualFileCheckboxTree.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ public VirtualFileCheckboxTree(@NotNull VirtualFile[] rootFiles) {
2020
}
2121

2222
public List<CheckedFile> getCheckedFiles() {
23-
return Arrays.stream(getCheckedNodes(VirtualFile.class, Objects::nonNull))
23+
var checkedNodes = getCheckedNodes(VirtualFile.class, Objects::nonNull);
24+
if (checkedNodes.length > 1000) {
25+
throw new RuntimeException("Too many files selected");
26+
}
27+
28+
return Arrays.stream(checkedNodes)
2429
.map(item -> new CheckedFile(new File(item.getPath())))
2530
.collect(toList());
2631
}

0 commit comments

Comments
 (0)