Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,13 @@ protected CompilationResult compileScript(ModelManager modelManager, WurstGui gu
WurstProjectConfigData projectConfigData, File buildDir,
boolean isProd) throws Exception {

// Ensure we're working with the cached map
File cachedMap = ensureCachedMap(gui);
if (!runArgs.isHotReload()) {
// Ensure we're working with the cached map
File cachedMap = ensureCachedMap(gui);

// Update testMap to point to cached map
testMap = Optional.of(cachedMap);
// Update testMap to point to cached map
testMap = Optional.of(cachedMap);
}

CompilationResult result;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tests.wurstscript.tests;

import config.WurstProjectConfigData;
import de.peeeq.wurstio.languageserver.BufferManager;
import de.peeeq.wurstio.languageserver.ModelManagerImpl;
import de.peeeq.wurstio.languageserver.WFile;
Expand Down Expand Up @@ -85,11 +86,69 @@ public void jhcrPipelineRenamesOutputScript() throws Exception {
assertEquals(renamed.getName(), MapRequest.BUILD_JHCR_SCRIPT_NAME);
}

@Test
public void hotReloadDoesNotRequireSourceMap() throws Exception {
File projectFolder = new File("./temp/testProject_hotreload_nomap/");
File wurstFolder = new File(projectFolder, "wurst");
newCleanFolder(wurstFolder);

File war3mapJ = new File(wurstFolder, "war3map.j");
Files.writeString(war3mapJ.toPath(), "function main takes nothing returns nothing\nendfunction");

WurstLanguageServer langServer = new WurstLanguageServer();
HotReloadNoMapRequest request = new HotReloadNoMapRequest(
langServer,
Optional.empty(),
List.of("-hotreload"),
WFile.create(projectFolder)
);

MapRequest.CompilationResult result = request.compileScriptForTest(
new ModelManagerImpl(projectFolder, new BufferManager()),
new WurstGuiLogger(),
Optional.empty(),
new WurstProjectConfigData()
);

assertEquals(result.script.getCanonicalFile(), war3mapJ.getCanonicalFile());
}

private void newCleanFolder(File f) throws Exception {
FileUtils.deleteRecursively(f);
Files.createDirectories(f.toPath());
}

private static final class HotReloadNoMapRequest extends MapRequest {
private HotReloadNoMapRequest(WurstLanguageServer langServer, Optional<File> map, List<String> compileArgs,
WFile workspaceRoot) {
super(langServer, map, compileArgs, workspaceRoot, Optional.empty(), Optional.empty());
}

@Override
public Object execute(de.peeeq.wurstio.languageserver.ModelManager modelManager) {
return null;
}

@Override
protected File ensureCachedMap(WurstGui gui) {
throw new AssertionError("ensureCachedMap should not be called for hotreload without a map.");
}

@Override
protected File compileScript(WurstGui gui, de.peeeq.wurstio.languageserver.ModelManager modelManager,
List<String> compileArgs, Optional<File> mapCopy,
WurstProjectConfigData projectConfigData, boolean isProd, File scriptFile) {
return scriptFile;
}

private CompilationResult compileScriptForTest(de.peeeq.wurstio.languageserver.ModelManager modelManager,
WurstGui gui,
Optional<File> testMap,
WurstProjectConfigData projectConfigData) throws Exception {
return compileScript(modelManager, gui, testMap, projectConfigData, getBuildDir(), false);
}
}

private static final class TestMapRequest extends MapRequest {
private final Map<File, byte[]> scriptByMap;
private File lastExtractedMap;
Expand Down
Loading