Skip to content

Commit b08bff4

Browse files
committed
one more cleanup
1 parent 18a9e5b commit b08bff4

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ protected File loadMapScript(Optional<File> mapCopy, ModelManager modelManager,
808808
"RunArg noExtractMapScript is set but no war3map.j is provided inside the wurst folder");
809809
}
810810
}
811-
if (MapRequest.mapLastModified > lastMapModified || !MapRequest.mapPath.equals(lastMapPath)) {
811+
if (shouldExtractMapScript(scriptFile)) {
812812
lastMapModified = MapRequest.mapLastModified;
813813
lastMapPath = MapRequest.mapPath;
814814
System.out.println("Map not cached yet, extracting script");
@@ -851,6 +851,19 @@ protected File loadMapScript(Optional<File> mapCopy, ModelManager modelManager,
851851
return scriptFile;
852852
}
853853

854+
private static boolean shouldExtractMapScript(File scriptFile) {
855+
if (!scriptFile.exists()) {
856+
return true;
857+
}
858+
if (!MapRequest.mapPath.equals(lastMapPath)) {
859+
return true;
860+
}
861+
if (MapRequest.mapLastModified > lastMapModified) {
862+
return true;
863+
}
864+
return MapRequest.mapLastModified > scriptFile.lastModified();
865+
}
866+
854867
private static void ensureScriptIsSynced(ModelManager modelManager, File scriptFile) {
855868
CompilationUnit compilationUnit = modelManager.getCompilationUnit(WFile.create(scriptFile));
856869
if (compilationUnit == null) {

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,44 @@ public void hotReloadExtractionUsesSourceMap() throws Exception {
6262
assertEquals(Files.readString(scriptFile.toPath()), "source script");
6363
}
6464

65+
@Test
66+
public void mapScriptIsExtractedWhenWorkspaceScriptIsMissingDespiteStaticCacheHit() throws Exception {
67+
File projectFolder = new File("./temp/testProject_extract_missing_script/");
68+
File wurstFolder = new File(projectFolder, "wurst");
69+
newCleanFolder(wurstFolder);
70+
71+
File sourceMap = new File(projectFolder, "source_map.w3x");
72+
Files.write(sourceMap.toPath(), new byte[] {0x01});
73+
74+
WurstLanguageServer langServer = new WurstLanguageServer();
75+
TestMapRequest request = new TestMapRequest(
76+
langServer,
77+
Optional.of(sourceMap),
78+
List.of(),
79+
WFile.create(projectFolder),
80+
Map.of(sourceMap, "fresh map script".getBytes(StandardCharsets.UTF_8))
81+
);
82+
83+
MapRequest.mapLastModified = sourceMap.lastModified();
84+
MapRequest.mapPath = sourceMap.getAbsolutePath();
85+
86+
File firstExtract = request.loadMapScriptForTest(
87+
Optional.of(sourceMap),
88+
new ModelManagerImpl(projectFolder, new BufferManager()),
89+
new WurstGuiLogger()
90+
);
91+
assertEquals(Files.readString(firstExtract.toPath()), "fresh map script");
92+
93+
Files.delete(firstExtract.toPath());
94+
File secondExtract = request.loadMapScriptForTest(
95+
Optional.of(sourceMap),
96+
new ModelManagerImpl(projectFolder, new BufferManager()),
97+
new WurstGuiLogger()
98+
);
99+
100+
assertEquals(Files.readString(secondExtract.toPath()), "fresh map script");
101+
}
102+
65103
@Test
66104
public void cachedMapFileNameIsModeSpecific() throws Exception {
67105
File projectFolder = new File("./temp/testProject_cache_mode_specific/");

0 commit comments

Comments
 (0)