diff --git a/src/main/java/net/fabricmc/loom/task/GenVsCodeProjectTask.java b/src/main/java/net/fabricmc/loom/task/GenVsCodeProjectTask.java index 6684e5ce4..398bba75c 100644 --- a/src/main/java/net/fabricmc/loom/task/GenVsCodeProjectTask.java +++ b/src/main/java/net/fabricmc/loom/task/GenVsCodeProjectTask.java @@ -118,7 +118,8 @@ public void genRuns() throws IOException { } for (VsCodeConfiguration configuration : getLaunchConfigurations().get()) { - final JsonElement configurationJson = LoomGradlePlugin.GSON.toJsonTree(configuration); + JsonObject configurationJson = LoomGradlePlugin.GSON.toJsonTree(configuration).getAsJsonObject(); + configurationJson.remove("runDir"); final List toRemove = new LinkedList<>(); @@ -161,11 +162,14 @@ public record VsCodeConfiguration( String projectName, String runDir) implements Serializable { public static VsCodeConfiguration fromRunConfig(Project project, RunConfig runConfig) { + Path rootPath = project.getRootDir().toPath(); + Path projectPath = project.getProjectDir().toPath(); + String relativeRunDir = rootPath.relativize(projectPath).resolve(runConfig.runDir).toString(); return new VsCodeConfiguration( "java", runConfig.configName, "launch", - "${workspaceFolder}/" + runConfig.runDir, + "${workspaceFolder}/" + relativeRunDir, "integratedTerminal", false, runConfig.mainClass, @@ -173,7 +177,7 @@ public static VsCodeConfiguration fromRunConfig(Project project, RunConfig runCo RunConfig.joinArguments(runConfig.programArgs), new HashMap<>(runConfig.environmentVariables), runConfig.projectName, - project.getProjectDir().toPath().resolve(runConfig.runDir).toAbsolutePath().toString() + rootPath.resolve(relativeRunDir).toAbsolutePath().toString() ); } }