Skip to content

Commit 51b392c

Browse files
committed
fix: Too many open files
Fixes #1062 Signed-off-by: azerr <azerr@redhat.com>
1 parent eb26b97 commit 51b392c

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/project/tags/QuteCompletionsForSourceUserTagSection.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.logging.Level;
2121
import java.util.logging.Logger;
2222
import java.util.stream.Collectors;
23+
import java.util.stream.Stream;
2324

2425
import com.redhat.qute.ls.commons.snippets.SnippetRegistry;
2526
import com.redhat.qute.project.QuteProject;
@@ -50,10 +51,11 @@ public void refresh(Path tagsDir, QuteProject project) {
5051
try {
5152
if (snippets.isEmpty()) {
5253
// create all user tags
53-
Files.list(tagsDir) //
54-
.forEach(path -> {
55-
snippetRegistry.registerSnippet(createUserTag(path, tagsDir, project));
56-
});
54+
try (Stream<Path> stream = Files.list(tagsDir)) {
55+
stream.forEach(path -> {
56+
snippetRegistry.registerSnippet(createUserTag(path, tagsDir, project));
57+
});
58+
}
5759
} else {
5860
// Remove all user tags which doesn't exist anymore
5961
List<UserTag> existingSnippets = new ArrayList<UserTag>(snippets);
@@ -67,12 +69,14 @@ public void refresh(Path tagsDir, QuteProject project) {
6769
.stream() //
6870
.map(userTag -> ((SourceUserTag) userTag).getPath()) //
6971
.collect(Collectors.toSet());
70-
Files.list(tagsDir) //
71-
.forEach(path -> {
72-
if (!existingSnippetPaths.contains(path)) {
73-
snippetRegistry.registerSnippet(createUserTag(path, tagsDir, project));
74-
}
75-
});
72+
73+
try (Stream<Path> stream = Files.list(tagsDir)) {
74+
stream.forEach(path -> {
75+
if (!existingSnippetPaths.contains(path)) {
76+
snippetRegistry.registerSnippet(createUserTag(path, tagsDir, project));
77+
}
78+
});
79+
}
7680
}
7781
} catch (IOException e) {
7882
LOGGER.log(Level.SEVERE, "Error while collecting source user tags", e);

0 commit comments

Comments
 (0)