Skip to content

Commit

Permalink
Merge pull request #860 from lf-lang/vscode-validate-generated-code-c…
Browse files Browse the repository at this point in the history
…leanups

vscode-validate-generated-code cleanups
  • Loading branch information
petervdonovan committed Jan 24, 2022
2 parents 4b3a013 + d16cb04 commit ef6d1bc
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -36,7 +36,7 @@ jobs:

# Run language server tests.
lsp-tests:
uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/lsp-tests.yml@vscode-validate-generated-code-cleanups

# Run the C integration tests.
c-tests:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/lsp-tests.yml
Expand Up @@ -29,12 +29,6 @@ jobs:
uses: actions/setup-java@v1.4.3
with:
java-version: 11
- name: Check out lingua-franca repository
uses: actions/checkout@v2
with:
repository: lf-lang/lingua-franca
submodules: true
ref: ${{ inputs.compiler-ref }}
- name: Setup Node.js environment
uses: actions/setup-node@v2.1.2
- name: Install pnpm
Expand All @@ -61,6 +55,12 @@ jobs:
vcpkgDirectory: ${{ github.workspace }}/vcpkg/
vcpkgTriplet: x64-windows-static
if: ${{ runner.os == 'Windows' }}
- name: Check out lingua-franca repository
uses: actions/checkout@v2
with:
repository: lf-lang/lingua-franca
submodules: true
ref: ${{ inputs.compiler-ref }}
- name: Run language server Python tests without PyLint
run: ./gradlew test --tests org.lflang.tests.lsp.LspTests.pythonSyntaxOnlyValidationTest
- name: Report to CodeCov
Expand Down
2 changes: 2 additions & 0 deletions RELEASES.md
@@ -1,4 +1,6 @@
# Version 0.1.0-beta-SNAPSHOT
- LF programs with the TypeScript target can now be compiled on Windows (#850).
- In the VS Code extension, generated code is validated when an LF file is saved for all targets except C (#828). Generated C code is only validated when it is fully compiled.

## Language

Expand Down
7 changes: 5 additions & 2 deletions org.lflang/src/org/lflang/generator/Validator.java
Expand Up @@ -13,6 +13,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -85,9 +86,11 @@ private static <T> List<Future<T>> getFutures(List<Callable<T>> tasks) throws In
}
break;
default:
futures = Executors.newFixedThreadPool(
ExecutorService service = Executors.newFixedThreadPool(
Math.min(Runtime.getRuntime().availableProcessors(), tasks.size())
).invokeAll(tasks);
);
futures = service.invokeAll(tasks);
service.shutdown();
}
return futures;
}
Expand Down
3 changes: 2 additions & 1 deletion org.lflang/src/org/lflang/generator/cpp/CppGenerator.kt
Expand Up @@ -205,7 +205,8 @@ class CppGenerator(
if (cmakeReturnCode == 0) {
// If cmake succeeded, run make
val makeCommand = createMakeCommand(cppFileConfig.buildPath, version)
val makeReturnCode = CppValidator(cppFileConfig, errorReporter, codeMaps).run(makeCommand, context.cancelIndicator)
val makeReturnCode = if (context.mode == Mode.STANDALONE) makeCommand.run() else
CppValidator(cppFileConfig, errorReporter, codeMaps).run(makeCommand, context.cancelIndicator)

if (makeReturnCode == 0) {
println("SUCCESS (compiling generated C++ code)")
Expand Down
17 changes: 12 additions & 5 deletions org.lflang/src/org/lflang/generator/python/PythonValidator.java
Expand Up @@ -21,6 +21,8 @@
import org.lflang.generator.Validator;
import org.lflang.util.LFCommand;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand Down Expand Up @@ -62,8 +64,8 @@ private static final class PylintMessage {
private String obj;
private int line;
private int column;
private int endLine;
private int endColumn;
private Integer endLine;
private Integer endColumn;
private Path path;
private String symbol;
private String message;
Expand All @@ -81,7 +83,10 @@ private static final class PylintMessage {
@JsonProperty("message-id")
public void setMessageId(String messageId) { this.messageId = messageId; }
public Position getStart() { return Position.fromZeroBased(line - 1, column); }
public Position getEnd() { return Position.fromZeroBased(endLine - 1, endColumn); }
public Position getEnd() {
return endLine == null || endColumn == null ? getStart().plus(" ") :
Position.fromZeroBased(endLine - 1, endColumn);
}
public Path getPath(Path relativeTo) { return relativeTo.resolve(path); }
public DiagnosticSeverity getSeverity() {
// The following is consistent with VS Code's default behavior for pure Python:
Expand Down Expand Up @@ -272,8 +277,10 @@ public Strategy getOutputReportingStrategy() {
}
}
} catch (JsonProcessingException e) {
// This should be impossible unless Pylint's API changes. Maybe it's fine to fail quietly
// like this in case that happens -- this will go to stderr, so you can see it if you look.
errorReporter.reportWarning(
"Failed to parse linter output. The Lingua Franca code generator is tested with Pylint "
+ "version 2.12.2. Consider updating PyLint if you have an older version."
);
e.printStackTrace();
}
};
Expand Down
3 changes: 2 additions & 1 deletion org.lflang/src/org/lflang/generator/rust/RustGenerator.kt
Expand Up @@ -128,7 +128,8 @@ class RustGenerator(
fileConfig.srcGenPath.toAbsolutePath()
) ?: return

val cargoReturnCode = RustValidator(fileConfig, errorReporter, codeMaps).run(cargoCommand, context.cancelIndicator)
val cargoReturnCode = if (context.mode == TargetConfig.Mode.STANDALONE) cargoCommand.run() else
RustValidator(fileConfig, errorReporter, codeMaps).run(cargoCommand, context.cancelIndicator)

if (cargoReturnCode == 0) {
println("SUCCESS (compiling generated Rust code)")
Expand Down

0 comments on commit ef6d1bc

Please sign in to comment.