use of com.github._1c_syntax.bsl.languageserver.utils.RelatedInformation in project bsl-language-server by 1c-syntax.
the class DuplicateRegionDiagnostic method visitFile.
@Override
public ParseTree visitFile(BSLParser.FileContext ctx) {
List<RegionSymbol> regions = documentContext.getSymbolTree().getModuleLevelRegions();
// анализировать модуль без областей не будем
if (regions.isEmpty()) {
return ctx;
}
// считаем дубли с учетом альтернативных имен для стандартных областей
regions.stream().collect(Collectors.groupingBy(regionSymbol -> regionNames.getOrDefault(regionSymbol.getName(), regionSymbol.getName()))).forEach((String name, List<RegionSymbol> regionsList) -> {
if (regionsList.size() > 1) {
List<DiagnosticRelatedInformation> relatedInformation = new ArrayList<>();
RegionSymbol currentRegion = regionsList.get(0);
Range currentRange = currentRegion.getStartRange();
regionsList.stream().map(region -> RelatedInformation.create(documentContext.getUri(), region.getStartRange(), "+1")).collect(Collectors.toCollection(() -> relatedInformation));
diagnosticStorage.addDiagnostic(currentRange, info.getMessage(currentRegion.getName()), relatedInformation);
}
});
return ctx;
}
use of com.github._1c_syntax.bsl.languageserver.utils.RelatedInformation 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.utils.RelatedInformation in project sonar-bsl-plugin-community by 1c-syntax.
the class IssuesLoaderTest method test_createIssue.
@Test
void test_createIssue() {
var issueSeverity = DiagnosticSeverity.Information;
var diagnosticName = "OneStatementPerLine";
var ruleKey = RuleKey.of(BSLLanguageServerRuleDefinition.REPOSITORY_KEY, diagnosticName);
var context = SensorContextTester.create(BASE_DIR);
var activeRules = new ActiveRulesBuilder().addRule(new NewActiveRule.Builder().setRuleKey(ruleKey).setName(diagnosticName).build()).build();
context.setActiveRules(activeRules);
var inputFile = Tools.inputFileBSL(FILE_NAME, BASE_DIR);
context.fileSystem().add(inputFile);
var issuesLoader = new IssuesLoader(context);
var diagnostic = new Diagnostic();
diagnostic.setCode(diagnosticName);
diagnostic.setSeverity(issueSeverity);
diagnostic.setMessage("Check message OneStatementPerLine");
diagnostic.setRange(new Range(new Position(0, 0), new Position(0, 1)));
var uri = inputFile.uri().toString();
var relatedInformation = List.of(new DiagnosticRelatedInformation(new Location(uri, new Range(new Position(11, 0), new Position(11, 8))), "+1"), new DiagnosticRelatedInformation(new Location(uri, new Range(new Position(12, 0), new Position(12, 5))), "+1"));
diagnostic.setRelatedInformation(relatedInformation);
issuesLoader.createIssue(inputFile, diagnostic);
assertThat(context.allIssues()).hasSize(1);
DefaultIssue issue = (DefaultIssue) context.allIssues().toArray()[0];
assertThat(issue.ruleKey()).isEqualTo(ruleKey);
assertThat(issue.flows()).hasSize(2).anySatisfy(flow -> assertThat(flow.locations()).hasSize(1).element(0).extracting(IssueLocation::textRange).isEqualTo(new DefaultTextRange(new DefaultTextPointer(12, 0), new DefaultTextPointer(12, 8)))).anySatisfy(flow -> assertThat(flow.locations()).hasSize(1).element(0).extracting(IssueLocation::textRange).isEqualTo(new DefaultTextRange(new DefaultTextPointer(13, 0), new DefaultTextPointer(13, 5))));
}
Aggregations