diff --git a/kernel/src/main/java/org/kframework/lsp/TextDocumentSyncHandler.java b/kernel/src/main/java/org/kframework/lsp/TextDocumentSyncHandler.java index 76782fc4d36..327caadf6dc 100644 --- a/kernel/src/main/java/org/kframework/lsp/TextDocumentSyncHandler.java +++ b/kernel/src/main/java/org/kframework/lsp/TextDocumentSyncHandler.java @@ -61,7 +61,8 @@ public void findCacheFile() { cacheFile = Files.walk(Path.of(URI.create(workspaceFolder.getUri()))) .filter(p -> p.endsWith(CACHE_FILE_NAME)) - .findFirst(); + .min(Comparator.comparing(Path::getNameCount, Comparator.naturalOrder())); + clientLogger.logMessage("Found cache file: " + cacheFile); loadCaches(); } catch (IOException e) { clientLogger.logMessage("findCachesException: " + e); @@ -81,7 +82,7 @@ public void loadCaches() { // this way we can find all the updated locations when finding references if (!files.containsKey(uri)) add(uri); }); - clientLogger.logMessage("loaded cached modules: " + caches.size()); + clientLogger.logMessage("Loaded cached modules: " + caches.size()); } public void add(String uri) { diff --git a/kernel/src/test/java/org/kframework/lsp/LSPTests.java b/kernel/src/test/java/org/kframework/lsp/LSPTests.java index 9e334c1620b..2b497556f82 100644 --- a/kernel/src/test/java/org/kframework/lsp/LSPTests.java +++ b/kernel/src/test/java/org/kframework/lsp/LSPTests.java @@ -5,6 +5,7 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -127,7 +128,7 @@ public void testKLSPathK() throws IOException { Optional cacheFile = Files.walk(Path.of(URI.create(workspaceFolder.getUri()))) .filter(p -> p.endsWith(Kompile.CACHE_FILE_NAME)) - .findFirst(); + .min(Comparator.comparing(Path::getNameCount, Comparator.naturalOrder())); if (cacheFile.isPresent()) caches = loader.loadCache(java.util.Map.class, cacheFile.get().toFile());