use of com.github._1c_syntax.bsl.languageserver.configuration.Language in project bsl-language-server by 1c-syntax.
the class LanguageServerConfigurationTest method createFromFile.
@Test
void createFromFile() {
// given
File configurationFile = new File(PATH_TO_CONFIGURATION_FILE);
// when
configuration.update(configurationFile);
// then
DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
Language language = configuration.getLanguage();
Map<String, Either<Boolean, Map<String, Object>>> parameters = diagnosticsOptions.getParameters();
assertThat(language).isEqualTo(Language.EN);
assertThat(parameters).hasSize(2);
Either<Boolean, Map<String, Object>> lineLength = parameters.get("LineLength");
assertThat(lineLength.isRight()).isTrue();
assertThat(lineLength.getRight()).isInstanceOfAny(Map.class);
assertThat(lineLength.getRight()).extracting(stringObjectMap -> stringObjectMap.get("maxLineLength")).isEqualTo(140);
Either<Boolean, Map<String, Object>> methodSize = parameters.get("MethodSize");
assertThat(methodSize.isLeft()).isTrue();
assertThat(methodSize.getLeft()).isFalse();
Path configurationRoot = configuration.getConfigurationRoot();
assertThat(configurationRoot).isNotNull();
assertThat(configuration.isUseDevSite()).isTrue();
assertThat(configuration.getDiagnosticsOptions().isOrdinaryAppSupport()).isFalse();
}
use of com.github._1c_syntax.bsl.languageserver.configuration.Language in project sonar-bsl-plugin-community by 1c-syntax.
the class LanguageServerDiagnosticsLoaderSensor method parseAndSaveResults.
private void parseAndSaveResults(File analysisResultsFile) {
LOGGER.info("Parsing 'BSL Language Server' analysis results:");
LOGGER.info(analysisResultsFile.getAbsolutePath());
AnalysisInfo analysisInfo = getAnalysisInfo(analysisResultsFile);
if (analysisInfo == null) {
return;
}
List<FileInfo> fileinfos = analysisInfo.getFileinfos();
for (FileInfo fileInfo : fileinfos) {
processFileInfo(fileInfo);
}
}
use of com.github._1c_syntax.bsl.languageserver.configuration.Language in project bsl-language-server by 1c-syntax.
the class SarifReporterTest method report.
@Test
void report() throws IOException {
// given
configuration.getDiagnosticsOptions().getParameters().put("Typo", Either.forLeft(false));
configuration.getDiagnosticsOptions().getParameters().put("test", Either.forLeft(true));
configuration.getDiagnosticsOptions().getParameters().put("some", Either.forRight(Map.of("test", 1)));
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);
// when
reporter.report(analysisInfo, Path.of(sourceDir));
// then
ObjectMapper mapper = new ObjectMapper();
var report = mapper.readValue(file, SarifSchema210.class);
assertThat(report).isNotNull();
var run = report.getRuns().get(0);
assertThat(run.getTool().getDriver().getName()).isEqualTo("BSL Language Server");
assertThat(run.getTool().getDriver().getRules()).hasSize(diagnosticInfos.size());
var invocation = run.getInvocations().get(0);
assertThat(invocation.getRuleConfigurationOverrides()).hasSizeGreaterThan(0).anyMatch(configurationOverride -> configurationOverride.getDescriptor().getId().equals("Typo") && !configurationOverride.getConfiguration().getEnabled()).anyMatch(configurationOverride -> configurationOverride.getDescriptor().getId().equals("test") && configurationOverride.getConfiguration().getEnabled()).anyMatch(configurationOverride -> configurationOverride.getDescriptor().getId().equals("some") && configurationOverride.getConfiguration().getParameters().getAdditionalProperties().get("test").equals(1));
assertThat(run.getResults()).hasSize(1).element(0).matches(result -> result.getRuleId().equals("test")).matches(result -> result.getLevel() == Result.Level.ERROR).matches(result -> result.getMessage().getText().equals("message")).matches(result -> result.getAnalysisTarget().getUri().equals(documentContext.getUri().toString())).extracting(Result::getLocations).extracting(locations -> locations.get(0)).extracting(Location::getPhysicalLocation).extracting(PhysicalLocation::getRegion).matches(region -> region.getStartLine().equals(diagnostic.getRange().getStart().getLine() + 1)).matches(region -> region.getStartColumn().equals(diagnostic.getRange().getStart().getCharacter() + 1)).matches(region -> region.getEndLine().equals(diagnostic.getRange().getEnd().getLine() + 1)).matches(region -> region.getEndColumn().equals(diagnostic.getRange().getEnd().getCharacter() + 1));
}
use of com.github._1c_syntax.bsl.languageserver.configuration.Language in project bsl-language-server by 1c-syntax.
the class LanguageServerConfigurationTest method createFromEmptyFile.
@Test
void createFromEmptyFile() {
// given
File configurationFile = new File(PATH_TO_EMPTY_CONFIGURATION_FILE);
// when
configuration.update(configurationFile);
// then
DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
Language language = configuration.getLanguage();
Map<String, Either<Boolean, Map<String, Object>>> parameters = diagnosticsOptions.getParameters();
assertThat(language).isEqualTo(DEFAULT_LANGUAGE);
assertThat(parameters).isEmpty();
}
use of com.github._1c_syntax.bsl.languageserver.configuration.Language in project mdclasses by 1c-syntax.
the class PairConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
if ("languages".equals(reader.getNodeName())) {
var uuid = reader.getAttribute("uuid");
var language = (MDLanguage) context.convertAnother(new MDLanguage(), MDLanguage.class);
language.setUuid(uuid);
language.setMdoReference(new MDOReference(language));
return Either.right(language);
} else if (reader.getValue().contains(".")) {
// уже лежит имя
return Either.left(reader.getValue());
} else {
var type = MDOType.fromValue(reader.getNodeName());
return type.map(mdoType -> Either.left(mdoType.getName() + "." + reader.getValue())).orElseGet(() -> Either.left(reader.getNodeName() + "." + reader.getValue()));
}
}
Aggregations