Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically generated .vscode/settings.json file #1759

Merged
merged 1 commit into from
May 21, 2023
Merged
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
26 changes: 25 additions & 1 deletion org.lflang/src/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -538,7 +539,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
try {
String compileDefs = targetConfig.compileDefinitions.keySet().stream()
.map(key -> key + "=" + targetConfig.compileDefinitions.get(key))
.collect(Collectors.joining("\n"));
.collect(Collectors.joining("\n")) + "\n";
FileUtil.writeToFile(
compileDefs,
Path.of(fileConfig.getSrcGenPath() + File.separator + "CompileDefinitions.txt")
Expand All @@ -547,6 +548,29 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
Exceptions.sneakyThrow(e);
}

// Create a .vscode/settings.json file in the target directory so that VSCode can
// immediately compile the generated code.
try {
String compileDefs = targetConfig.compileDefinitions.keySet().stream()
.map(key -> "\"-D" + key + "=" + targetConfig.compileDefinitions.get(key) + "\"")
.collect(Collectors.joining(",\n"));
String settings = "{\n"
+ "\"cmake.configureArgs\": [\n"
+ compileDefs
+ "\n]\n}\n";
Path vscodePath = Path.of(fileConfig.getSrcGenPath() + File.separator + ".vscode");
if (!Files.exists(vscodePath))
Files.createDirectory(vscodePath);
FileUtil.writeToFile(
settings,
Path.of(fileConfig.getSrcGenPath()
+ File.separator + ".vscode"
+ File.separator + "settings.json")
);
} catch (IOException e) {
Exceptions.sneakyThrow(e);
}

// If this code generator is directly compiling the code, compile it now so that we
// clean it up after, removing the #line directives after errors have been reported.
if (
Expand Down