Skip to content

Commit 1212d99

Browse files
committed
better vscode logging, fix caching
1 parent 951d455 commit 1212d99

15 files changed

Lines changed: 178 additions & 115 deletions

File tree

de.peeeq.wurstscript/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ dependencies {
9797
implementation 'org.apache.velocity:velocity:1.7'
9898
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
9999
implementation 'com.github.inwc3:jmpq3:29b55f2c32'
100-
implementation 'com.github.inwc3:wc3libs:bd76116d0e'
100+
implementation 'com.github.inwc3:wc3libs:8a8fc98f3a'
101101
implementation 'com.github.wurstscript:wurstsetup:393cf5ea39'
102102
implementation 'org.slf4j:slf4j-api:1.7.25'
103103
implementation 'ch.qos.logback:logback-classic:1.5.13'

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompiletimeFunctionRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ private void executeCompiletimeFunction(ImFunction f) {
495495
if (!f.getBody().isEmpty()) {
496496
interpreter.getGlobalState().setLastStatement(f.getBody().get(0));
497497
}
498-
WLogger.info("running " + functionFlag + " function " + f.getName());
498+
WLogger.debug("running " + functionFlag + " function " + f.getName());
499499
interpreter.runVoidFunc(f, null);
500500
successTests.add(f);
501501
} catch (TestSuccessException e) {

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/gui/WurstGuiImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void sendError(CompileError err) {
128128
@Override
129129
public void sendProgress(String whatsRunningNow) {
130130
if (whatsRunningNow != null) {
131-
WLogger.info("progress: " + whatsRunningNow);
131+
WLogger.debug("progress: " + whatsRunningNow);
132132
}
133133
if (whatsRunningNow == null || done.contains(whatsRunningNow)) {
134134
return;

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/intermediateLang/interpreter/ProgramStateIO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,13 @@ public void writeBack(boolean inject) {
451451
if (oldManifest.hasEntry(fileType.getExt()) &&
452452
oldManifest.hashMatches(fileType.getExt(), currentHash)) {
453453

454-
WLogger.info("Object file " + fileType.getExt() + " unchanged (hash match), skipping writeback");
454+
System.out.println("Object file " + fileType.getExt() + " unchanged (hash match), skipping writeback");
455455
filesSkipped++;
456456

457457
// Still add to new manifest
458458
newManifest.putEntry(fileType.getExt(), currentHash, dataStore.getObjsList().size());
459459
} else {
460-
WLogger.info("Object file " + fileType.getExt() + " changed or new, writing back");
460+
System.out.println("Object file " + fileType.getExt() + " changed or new, writing back");
461461
filesUpdated++;
462462
writebackObjectFile(dataStore, fileType, inject);
463463
newManifest.putEntry(fileType.getExt(), currentHash, dataStore.getObjsList().size());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ private void replaceCompilationUnit(WFile filename) {
469469
String contents = Files.toString(f, Charsets.UTF_8);
470470
bufferManager.updateFile(WFile.create(f), contents);
471471
replaceCompilationUnit(filename, contents, true);
472-
WLogger.info("replaceCompilationUnit 3 " + f);
473472
} catch (IOException e) {
474473
WLogger.severe(e);
475474
throw new ModelManagerException(e);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public CompletableFuture<CompletionItem> resolveCompletionItem(CompletionItem un
3737

3838
@Override
3939
public CompletableFuture<Hover> hover(HoverParams hoverParams) {
40-
WLogger.info("hover");
4140
return worker.handle(new HoverInfo(hoverParams, worker.getBufferManager()));
4241
}
4342

@@ -90,7 +89,6 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume
9089

9190
@Override
9291
public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActionParams params) {
93-
WLogger.info("codeAction");
9492
return worker.handle(new CodeActionRequest(params, worker.getBufferManager()));
9593
}
9694

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Hover execute(ModelManager modelManager) {
4444
return new Hover(Collections.singletonList(Either.forLeft("File " + filename + " is not part of the project. Move it to the wurst folder.")));
4545
}
4646
Element e = Utils.getAstElementAtPos(cu, line, column, false).get();
47-
WLogger.info("hovering over " + Utils.printElement(e));
47+
WLogger.debug("hovering over " + Utils.printElement(e));
4848
List<Either<String, MarkedString>> desription = e.match(new Description());
4949
desription = addArgumentHint(e, desription);
5050

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

Lines changed: 117 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,6 @@ private static void replaceBaseScriptWithConfig(ModelManager modelManager, File
342342
}
343343
}
344344

345-
/**
346-
* Gets the cached map file location
347-
*/
348-
protected File getCachedMapFile() {
349-
File buildDir = getBuildDir();
350-
File cacheDir = new File(buildDir, "cache");
351-
if (!cacheDir.exists()) {
352-
UtilsIO.mkdirs(cacheDir);
353-
}
354-
return new File(cacheDir, "cached_map.w3x");
355-
}
356-
357345
/**
358346
* Checks if we can use the cached map
359347
*/
@@ -374,31 +362,53 @@ protected boolean canUseCachedMap(File cachedMap) {
374362
}
375363

376364

365+
/**
366+
* Gets or creates the cached map file location
367+
*/
368+
protected File getCachedMapFile() {
369+
File buildDir = getBuildDir();
370+
File cacheDir = new File(buildDir, "cache");
371+
if (!cacheDir.exists()) {
372+
UtilsIO.mkdirs(cacheDir);
373+
}
374+
return new File(cacheDir, "cached_map.w3x");
375+
}
376+
377+
/**
378+
* Ensures cached map exists and is up to date
379+
*/
380+
protected File ensureCachedMap(WurstGui gui) throws IOException {
381+
File cachedMap = getCachedMapFile();
382+
383+
if (!map.isPresent()) {
384+
throw new RequestFailedException(MessageType.Error, "No source map provided");
385+
}
386+
387+
File sourceMap = map.get();
388+
389+
// If cached map doesn't exist or source is newer, update cache
390+
if (!cachedMap.exists() || sourceMap.lastModified() > cachedMap.lastModified()) {
391+
WLogger.info("Updating cached map from source");
392+
gui.sendProgress("Updating cached map");
393+
Files.copy(sourceMap, cachedMap);
394+
}
395+
396+
return cachedMap;
397+
}
398+
377399
protected CompilationResult compileScript(ModelManager modelManager, WurstGui gui, Optional<File> testMap,
378400
WurstProjectConfigData projectConfigData, File buildDir,
379401
boolean isProd) throws Exception {
380402

381-
File cachedMap = getCachedMapFile();
403+
// Ensure we're working with the cached map
404+
File cachedMap = ensureCachedMap(gui);
382405

383-
if (!cachedMap.exists()) {
384-
if (testMap.get().exists()) {
385-
boolean deleteOk = testMap.get().delete();
386-
if (!deleteOk) {
387-
throw new RequestFailedException(MessageType.Error, "Could not delete old mapfile: " + testMap);
388-
}
389-
}
390-
if (map.isPresent()) {
391-
gui.sendProgress("Creating new cached map");
392-
Files.copy(map.get(), testMap.get());
393-
// Also update the cache
394-
Files.copy(map.get(), cachedMap);
395-
}
396-
}
406+
// Update testMap to point to cached map
407+
testMap = Optional.of(cachedMap);
397408

398409
CompilationResult result;
399410

400411
if (runArgs.isHotReload()) {
401-
// For hot reload use cached war3map if it exists
402412
result = new CompilationResult();
403413
result.script = new File(buildDir, "war3mapj_with_config.j.txt");
404414
if (!result.script.exists()) {
@@ -414,7 +424,7 @@ protected CompilationResult compileScript(ModelManager modelManager, WurstGui gu
414424
result = applyProjectConfig(gui, testMap, buildDir, projectConfigData, scriptFile);
415425
}
416426

417-
// first compile the script:
427+
// Compile the script
418428
result.script = compileScript(gui, modelManager, compileArgs, testMap, projectConfigData, isProd, result.script);
419429

420430
Optional<WurstModel> model = Optional.ofNullable(modelManager.getModel());
@@ -430,6 +440,84 @@ protected CompilationResult compileScript(ModelManager modelManager, WurstGui gu
430440
return result;
431441
}
432442

443+
protected void injectMapData(WurstGui gui, Optional<File> testMap, CompilationResult result) throws Exception {
444+
gui.sendProgress("Injecting map data");
445+
timeTaker.beginPhase("Injecting map data");
446+
447+
// Work directly with the cached map
448+
File cachedMap = getCachedMapFile();
449+
450+
if (!cachedMap.exists()) {
451+
throw new RequestFailedException(MessageType.Error, "Cached map does not exist");
452+
}
453+
454+
try (MpqEditor mpqEditor = MpqEditorFactory.getEditor(Optional.of(cachedMap))) {
455+
String mapScriptName;
456+
if (runArgs.isLua()) {
457+
mapScriptName = "war3map.lua";
458+
injectExternalLuaFiles(result.script);
459+
} else {
460+
mapScriptName = "war3map.j";
461+
}
462+
463+
// Delete old scripts
464+
if (mpqEditor.hasFile("war3map.j")) {
465+
mpqEditor.deleteFile("war3map.j");
466+
}
467+
if (mpqEditor.hasFile("war3map.lua")) {
468+
mpqEditor.deleteFile("war3map.lua");
469+
}
470+
471+
// Insert new script
472+
mpqEditor.insertFile(mapScriptName, result.script);
473+
474+
// Insert w3i if it changed
475+
if (result.w3i != null) {
476+
String w3iHash = ImportFile.calculateFileHash(result.w3i);
477+
478+
Optional<ImportFile.CacheManifest> manifestOpt = ImportFile.getCachedManifest(mpqEditor);
479+
boolean w3iChanged = true;
480+
481+
if (manifestOpt.isPresent() && manifestOpt.get().w3iConfigMatches(w3iHash)) {
482+
WLogger.info("W3I file unchanged, skipping injection");
483+
w3iChanged = false;
484+
}
485+
486+
if (w3iChanged) {
487+
WLogger.info("W3I file changed, injecting");
488+
if (mpqEditor.hasFile(W3I.GAME_PATH.getName())) {
489+
mpqEditor.deleteFile(W3I.GAME_PATH.getName());
490+
}
491+
mpqEditor.insertFile(W3I.GAME_PATH.getName(), result.w3i);
492+
493+
// Update manifest
494+
ImportFile.CacheManifest manifest = manifestOpt.orElse(new ImportFile.CacheManifest());
495+
manifest.setW3iConfig(w3iHash);
496+
ImportFile.saveManifest(mpqEditor, manifest);
497+
}
498+
}
499+
500+
// CRITICAL: Import files into THIS mpq editor instance
501+
gui.sendProgress("Importing resource files");
502+
timeTaker.beginPhase("Importing files");
503+
try {
504+
ImportFile.ImportResult importResult = ImportFile.importFilesFromImports(
505+
workspaceRoot.getFile(),
506+
mpqEditor
507+
);
508+
WLogger.info("Import result: " + importResult.toString());
509+
} catch (Exception e) {
510+
WLogger.severe("Failed to import files: " + e.getMessage());
511+
throw e;
512+
}
513+
timeTaker.endPhase();
514+
}
515+
516+
timeTaker.endPhase();
517+
518+
WLogger.info("Cached map size after injection: " + (cachedMap.length() / 1024 / 1024) + " MB");
519+
}
520+
433521
private static boolean startsWith(byte[] data, byte[] prefix) {
434522
if (data.length < prefix.length) return false;
435523
for (int i = 0; i < prefix.length; i++) {
@@ -532,58 +620,6 @@ private W3InstallationData getBestW3InstallationData() throws RequestFailedExcep
532620
}
533621
}
534622

535-
// In MapRequest.java - Updated injectMapData method
536-
537-
protected void injectMapData(WurstGui gui, Optional<File> testMap, CompilationResult result) throws Exception {
538-
gui.sendProgress("Injecting map data");
539-
timeTaker.beginPhase("Injecting map data");
540-
541-
File cachedMap = getCachedMapFile();
542-
543-
try (MpqEditor mpqEditor = MpqEditorFactory.getEditor(Optional.ofNullable(cachedMap))) {
544-
String mapScriptName;
545-
if (runArgs.isLua()) {
546-
mapScriptName = "war3map.lua";
547-
injectExternalLuaFiles(result.script);
548-
} else {
549-
mapScriptName = "war3map.j";
550-
}
551-
552-
// Delete old scripts
553-
mpqEditor.deleteFile("war3map.j");
554-
mpqEditor.deleteFile("war3map.lua");
555-
556-
// Insert new script
557-
mpqEditor.insertFile(mapScriptName, result.script);
558-
559-
// Insert w3i if it changed
560-
if (result.w3i != null) {
561-
// Calculate hash to track w3i changes
562-
String w3iHash = ImportFile.calculateFileHash(result.w3i);
563-
564-
Optional<ImportFile.CacheManifest> manifestOpt = ImportFile.getCachedManifest(mpqEditor);
565-
boolean w3iChanged = true;
566-
567-
if (manifestOpt.isPresent() && manifestOpt.get().w3iConfigMatches(w3iHash)) {
568-
WLogger.info("W3I file unchanged, skipping injection");
569-
w3iChanged = false;
570-
}
571-
572-
if (w3iChanged) {
573-
WLogger.info("W3I file changed, injecting");
574-
mpqEditor.deleteFile(W3I.GAME_PATH.getName());
575-
mpqEditor.insertFile(W3I.GAME_PATH.getName(), result.w3i);
576-
577-
// Update manifest
578-
ImportFile.CacheManifest manifest = manifestOpt.orElse(new ImportFile.CacheManifest());
579-
manifest.setW3iConfig(w3iHash);
580-
ImportFile.saveManifest(mpqEditor, manifest);
581-
}
582-
}
583-
}
584-
585-
timeTaker.endPhase();
586-
}
587623

588624
private void injectExternalLuaFiles(File script) {
589625
File luaDir;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,31 @@ private String compileMap(ModelManager modelManager, WurstGui gui, WurstProjectC
117117

118118

119119
if (testMap.isPresent()) {
120-
startGame(gui, testMap, result);
120+
startGame(gui, result);
121121
}
122122
return null;
123123
}
124124

125-
private void startGame(WurstGui gui, Optional<File> testMap, CompilationResult result) throws Exception {
126-
injectMapData(gui, testMap, result);
125+
private void startGame(WurstGui gui, CompilationResult result) throws Exception {
126+
Optional<File> cachedMapFile = Optional.ofNullable(getCachedMapFile());
127+
injectMapData(gui, cachedMapFile, result);
127128

128129
timeTaker.beginPhase("Starting Warcraft 3");
129130
gui.sendProgress("Starting Warcraft 3...");
130131

131-
File mapCopy = testMap.get();
132+
File mapCopy = cachedMapFile.get();
132133
if (w3data.getWc3PatchVersion().isPresent()) {
133134
GameVersion gameVersion = w3data.getWc3PatchVersion().get();
134-
if (gameVersion != VERSION_1_32) {
135-
mapCopy = copyToWarcraftMapDir(testMap.get());
135+
if (gameVersion.compareTo(GameVersion.VERSION_1_32) < 0) {
136+
mapCopy = copyToWarcraftMapDir(cachedMapFile.get());
136137
}
137138
}
138139

139140

140141
WLogger.info("Starting wc3 ... ");
141142
String path = "";
142143
if (customTarget != null) {
143-
path = new File(customTarget, testMap.get().getName()).getAbsolutePath();
144+
path = new File(customTarget, cachedMapFile.get().getName()).getAbsolutePath();
144145
} else if (mapCopy != null) {
145146
path = mapCopy.getAbsolutePath();
146147
}

0 commit comments

Comments
 (0)