Search in sources :

Example 1 with Language

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Mode(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode) CodeLensOptions(com.github._1c_syntax.bsl.languageserver.configuration.codelens.CodeLensOptions) Files(java.nio.file.Files) DEFAULT_LANGUAGE(com.github._1c_syntax.bsl.languageserver.configuration.Language.DEFAULT_LANGUAGE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FileSystemException(java.nio.file.FileSystemException) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) File(java.io.File) Absolute(com.github._1c_syntax.utils.Absolute) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Paths(java.nio.file.Paths) Map(java.util.Map) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) SkipSupport(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport) CleanupContextBeforeClassAndAfterEachTestMethod(com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod) Path(java.nio.file.Path) Path(java.nio.file.Path) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) File(java.io.File) Map(java.util.Map) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Language

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);
    }
}
Also used : FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo)

Example 3 with Language

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));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) Map(java.util.Map) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) Path(java.nio.file.Path) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Location(com.contrastsecurity.sarif.Location) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CleanupContextBeforeClassAndAfterClass(com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterClass) Collections(java.util.Collections) PhysicalLocation(com.contrastsecurity.sarif.PhysicalLocation) Result(com.contrastsecurity.sarif.Result) SarifSchema210(com.contrastsecurity.sarif.SarifSchema210) FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) Diagnostic(org.eclipse.lsp4j.Diagnostic) AnalysisInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PhysicalLocation(com.contrastsecurity.sarif.PhysicalLocation) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Language

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();
}
Also used : DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Language

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()));
    }
}
Also used : MDOReference(com.github._1c_syntax.mdclasses.mdo.support.MDOReference) MDLanguage(com.github._1c_syntax.mdclasses.mdo.MDLanguage)

Aggregations

File (java.io.File)3 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 DiagnosticsOptions (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions)2 AnalysisInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo)2 FileInfo (com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Location (com.contrastsecurity.sarif.Location)1 PhysicalLocation (com.contrastsecurity.sarif.PhysicalLocation)1 Result (com.contrastsecurity.sarif.Result)1 SarifSchema210 (com.contrastsecurity.sarif.SarifSchema210)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DEFAULT_LANGUAGE (com.github._1c_syntax.bsl.languageserver.configuration.Language.DEFAULT_LANGUAGE)1 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)1