Skip to content

Commit 88d5845

Browse files
committed
review fix
1 parent d79658f commit 88d5845

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/ModelManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public Changes removeCompilationUnit(WFile resource) {
9696
toRemove.add(compilationUnit);
9797
}
9898
}
99+
GlobalCaches.clearLookupCacheFor(toRemove);
99100
model2.removeAll(toRemove);
100101
}
101102

@@ -419,6 +420,7 @@ private void updateModel(CompilationUnit cu, WurstGui gui) {
419420
Set<String> oldPackages = providedPackages(c);
420421
Set<CompilationUnit> mustUpdate = calculateCUsToUpdate(Collections.singletonList(cu), oldPackages, model2);
421422

423+
GlobalCaches.clearLookupCacheFor(Collections.singletonList(c));
422424
clearCompilationUnits(mustUpdate);
423425
// replace old compilationunit with new one:
424426
it.set(cu);

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/ModelManagerTests.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,67 @@ public void readdingMovedFileWithSameContentUpdatesModel() throws IOException {
365365
assertNotNull(manager.getCompilationUnit(fileTest), "file should be present after re-adding same contents");
366366
}
367367

368+
@Test
369+
public void replacingCompilationUnitClearsOldLookupCacheKeys() throws IOException {
370+
GlobalCaches.clearAll();
371+
File projectFolder = new File("./temp/testProject_replace_clears_lookup_cache/");
372+
File wurstFolder = new File(projectFolder, "wurst");
373+
newCleanFolder(wurstFolder);
374+
375+
WFile fileMain = WFile.create(new File(wurstFolder, "Main.wurst"));
376+
WFile fileWurst = WFile.create(new File(wurstFolder, "Wurst.wurst"));
377+
writeFile(fileMain, string(
378+
"package Main",
379+
"public function foo()"
380+
));
381+
writeFile(fileWurst, "package Wurst\n");
382+
383+
ModelManagerImpl manager = new ModelManagerImpl(projectFolder, new BufferManager());
384+
manager.buildProject();
385+
CompilationUnit oldCu = manager.getCompilationUnit(fileMain);
386+
assertNotNull(oldCu);
387+
388+
GlobalCaches.CacheKey oldKey = new GlobalCaches.CacheKey(oldCu, "foo", GlobalCaches.LookupType.FUNC);
389+
GlobalCaches.lookupCache.put(oldKey, oldCu);
390+
391+
manager.syncCompilationUnitContent(fileMain, string(
392+
"package Main",
393+
"public function bar()"
394+
));
395+
396+
assertEquals(GlobalCaches.lookupCache.containsKey(oldKey), false,
397+
"replacing a CU must drop lookup keys that keep the old AST alive");
398+
}
399+
400+
@Test
401+
public void removingCompilationUnitClearsOldLookupCacheKeys() throws IOException {
402+
GlobalCaches.clearAll();
403+
File projectFolder = new File("./temp/testProject_remove_clears_lookup_cache/");
404+
File wurstFolder = new File(projectFolder, "wurst");
405+
newCleanFolder(wurstFolder);
406+
407+
WFile fileMain = WFile.create(new File(wurstFolder, "Main.wurst"));
408+
WFile fileWurst = WFile.create(new File(wurstFolder, "Wurst.wurst"));
409+
writeFile(fileMain, string(
410+
"package Main",
411+
"public function foo()"
412+
));
413+
writeFile(fileWurst, "package Wurst\n");
414+
415+
ModelManagerImpl manager = new ModelManagerImpl(projectFolder, new BufferManager());
416+
manager.buildProject();
417+
CompilationUnit oldCu = manager.getCompilationUnit(fileMain);
418+
assertNotNull(oldCu);
419+
420+
GlobalCaches.CacheKey oldKey = new GlobalCaches.CacheKey(oldCu, "foo", GlobalCaches.LookupType.FUNC);
421+
GlobalCaches.lookupCache.put(oldKey, oldCu);
422+
423+
manager.removeCompilationUnit(fileMain);
424+
425+
assertEquals(GlobalCaches.lookupCache.containsKey(oldKey), false,
426+
"removing a CU must drop lookup keys that keep the old AST alive");
427+
}
428+
368429
@Test
369430
public void duplicatePackageReportsSingleClearMessage() throws IOException {
370431
File projectFolder = new File("./temp/testProject_duplicate_package_message/");

0 commit comments

Comments
 (0)