Skip to content

Commit

Permalink
Fix vscode cwd property for subprojects, delete unused runDir pro…
Browse files Browse the repository at this point in the history
…perty
  • Loading branch information
fewizz committed Jan 8, 2025
1 parent c80333b commit 036b73f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/net/fabricmc/loom/task/GenVsCodeProjectTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -140,7 +139,7 @@ public void genRuns() throws IOException {
toRemove.forEach(configurations::remove);
configurations.add(configurationJson);

Files.createDirectories(Paths.get(configuration.runDir));
Files.createDirectories(configuration.absoluteRunDirPath(getProject()));
}

final String json = LoomGradlePlugin.GSON.toJson(root);
Expand All @@ -158,23 +157,28 @@ public record VsCodeConfiguration(
String vmArgs,
String args,
Map<String, Object> env,
String projectName,
String runDir) implements Serializable {
String projectName) implements Serializable {
public static VsCodeConfiguration fromRunConfig(Project project, RunConfig runConfig) {
Path rootPath = project.getRootDir().toPath();
Path projectPath = project.getProjectDir().toPath();
Path relativeProjectPath = rootPath.relativize(projectPath);
return new VsCodeConfiguration(
"java",
runConfig.configName,
"launch",
"${workspaceFolder}/" + runConfig.runDir,
"${workspaceFolder}/" + relativeProjectPath.resolve(runConfig.runDir).toString(),
"integratedTerminal",
false,
runConfig.mainClass,
RunConfig.joinArguments(runConfig.vmArgs),
RunConfig.joinArguments(runConfig.programArgs),
new HashMap<>(runConfig.environmentVariables),
runConfig.projectName,
project.getProjectDir().toPath().resolve(runConfig.runDir).toAbsolutePath().toString()
runConfig.projectName
);
}

Path absoluteRunDirPath(Project project) {
return project.getRootDir().toPath().resolve(this.cwd.replace("${workspaceFolder}/", ""));
}
}
}

0 comments on commit 036b73f

Please sign in to comment.