use of com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo in project bsl-language-server by 1c-syntax.
the class JUnitReporterTest method report.
@Test
void report() throws IOException {
// given
List<Diagnostic> diagnostics = new ArrayList<>();
diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test"));
diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 4), "message4", DiagnosticSeverity.Error, "test-source2", "test3"));
diagnostics.add(new Diagnostic(Ranges.create(3, 1, 4, 4), "message4", DiagnosticSeverity.Error, "test-source2", "test3"));
DocumentContext documentContext = TestUtils.getDocumentContext(Paths.get("./src/test/java/diagnostics/CanonicalSpellingKeywordsDiagnostic.bsl").toUri(), "");
String sourceDir = ".";
FileInfo fileInfo = new FileInfo(sourceDir, documentContext, diagnostics);
AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
DiagnosticReporter reporter = new JUnitReporter();
// when
reporter.report(analysisInfo, Path.of(sourceDir));
// then
ObjectMapper mapper = new XmlMapper();
JUnitTestSuites report = mapper.readValue(file, JUnitTestSuites.class);
assertThat(report).isNotNull();
}
use of com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo in project bsl-language-server by 1c-syntax.
the class JsonReporterTest method report.
@Test
void report() throws IOException {
// given
Diagnostic diagnostic = new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test");
DocumentContext documentContext = TestUtils.getDocumentContext("");
String sourceDir = ".";
FileInfo fileInfo = new FileInfo(sourceDir, documentContext, Collections.singletonList(diagnostic));
AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
JsonReporter reporter = new JsonReporter();
// when
reporter.report(analysisInfo, Path.of(sourceDir));
// then
ObjectMapper mapper = new AnalysisInfoObjectMapper();
mapper.findAndRegisterModules();
AnalysisInfo report = mapper.readValue(file, AnalysisInfo.class);
Assertions.assertThat(report.getFileinfos()).hasSize(1);
}
use of com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo in project bsl-language-server by 1c-syntax.
the class TSLintReporterTest method report.
@Test
void report() throws IOException {
// given
Diagnostic diagnostic = new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", "test");
DocumentContext documentContext = TestUtils.getDocumentContext("");
String sourceDir = ".";
FileInfo fileInfo = new FileInfo(sourceDir, documentContext, Collections.singletonList(diagnostic));
AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
TSLintReporter reporter = new TSLintReporter();
// when
reporter.report(analysisInfo, Path.of(sourceDir));
// then
ObjectMapper mapper = new ObjectMapper();
List<TSLintReportEntry> report = mapper.readValue(file, new TypeReference<ArrayList<TSLintReportEntry>>() {
});
assertThat(report).hasSize(1);
}
use of com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo in project bsl-language-server by 1c-syntax.
the class SarifReporter method createResult.
private static Result createResult(FileInfo fileInfo, Diagnostic diagnostic) {
var uri = Absolute.uri(fileInfo.getPath().toUri()).toString();
var message = new Message().withText(diagnostic.getMessage());
var ruleId = DiagnosticCode.getStringValue(diagnostic.getCode());
var level = severityToResultLevel.get(diagnostic.getSeverity());
var analysisTarget = new ArtifactLocation().withUri(uri);
var locations = List.of(createLocation(diagnostic.getMessage(), uri, diagnostic.getRange()));
var relatedLocations = Optional.ofNullable(diagnostic.getRelatedInformation()).stream().flatMap(Collection::stream).skip(1).map(relatedInformation -> createLocation(relatedInformation.getMessage(), relatedInformation.getLocation().getUri(), relatedInformation.getLocation().getRange())).collect(Collectors.toSet());
return new Result().withMessage(message).withRuleId(ruleId).withLevel(level).withAnalysisTarget(analysisTarget).withLocations(locations).withRelatedLocations(relatedLocations);
}
use of com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo in project bsl-language-server by 1c-syntax.
the class AnalyzeCommand method getFileInfoFromFile.
private FileInfo getFileInfoFromFile(Path srcDir, File file) {
String textDocumentContent;
try {
textDocumentContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
DocumentContext documentContext = context.addDocument(file.toURI(), textDocumentContent, 1);
Path filePath = srcDir.relativize(Absolute.path(file));
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
String mdoRef = "";
Optional<AbstractMDObjectBase> mdObjectBase = documentContext.getMdObject();
if (mdObjectBase.isPresent()) {
mdoRef = mdObjectBase.get().getMdoReference().getMdoRef();
}
FileInfo fileInfo = new FileInfo(filePath, mdoRef, diagnostics, metrics);
// clean up AST after diagnostic computing to free up RAM.
documentContext.clearSecondaryData();
return fileInfo;
}
Aggregations