Search in sources :

Example 1 with DiagnosticsOptions

use of com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions 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 DiagnosticsOptions

use of com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions in project bsl-language-server by 1c-syntax.

the class LanguageServerConfigurationTest method testPartialInitialization.

@Test
void testPartialInitialization() {
    // given
    File configurationFile = new File(PATH_TO_PARTIAL_CONFIGURATION_FILE);
    configuration.update(configurationFile);
    // when
    CodeLensOptions codeLensOptions = configuration.getCodeLensOptions();
    DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
    // then
    assertThat(codeLensOptions.isShowCognitiveComplexity()).isTrue();
    assertThat(codeLensOptions.isShowCyclomaticComplexity()).isFalse();
    assertThat(configuration.getLanguage()).isEqualTo(DEFAULT_LANGUAGE);
    assertThat(diagnosticsOptions.getMode()).isEqualTo(Mode.ON);
    assertThat(diagnosticsOptions.getSkipSupport()).isEqualTo(SkipSupport.NEVER);
    assertThat(diagnosticsOptions.getParameters()).isEmpty();
}
Also used : DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) CodeLensOptions(com.github._1c_syntax.bsl.languageserver.configuration.codelens.CodeLensOptions) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with DiagnosticsOptions

use of com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions in project bsl-language-server by 1c-syntax.

the class DiagnosticsConfiguration method diagnostics.

@Bean
@Scope("prototype")
public List<BSLDiagnostic> diagnostics(DocumentContext documentContext) {
    Collection<DiagnosticInfo> diagnosticInfos = diagnosticInfos();
    DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
    if (needToComputeDiagnostics(documentContext, diagnosticsOptions)) {
        FileType fileType = documentContext.getFileType();
        CompatibilityMode compatibilityMode = documentContext.getServerContext().getConfiguration().getCompatibilityMode();
        ModuleType moduleType = documentContext.getModuleType();
        return diagnosticInfos.stream().filter(diagnosticInfo -> isEnabled(diagnosticInfo, diagnosticsOptions)).filter(info -> inScope(info, fileType)).filter(info -> correctModuleType(info, moduleType, fileType)).filter(info -> passedCompatibilityMode(info, compatibilityMode)).map(DiagnosticInfo::getDiagnosticClass).map(diagnosticObjectProvider::get).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
Also used : SupportConfiguration(com.github._1c_syntax.mdclasses.supportconf.SupportConfiguration) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Scope(org.springframework.context.annotation.Scope) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) DiagnosticScope(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) DiagnosticCompatibilityMode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode) Map(java.util.Map) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Mode(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode) SupportVariant(com.github._1c_syntax.mdclasses.supportconf.SupportVariant) Collection(java.util.Collection) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) BSLDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.BSLDiagnostic) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) SkipSupport(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport) Lookup(org.springframework.beans.factory.annotation.Lookup) Bean(org.springframework.context.annotation.Bean) CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) Comparator(java.util.Comparator) Collections(java.util.Collections) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) DiagnosticCompatibilityMode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode) CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Scope(org.springframework.context.annotation.Scope) DiagnosticScope(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope) Bean(org.springframework.context.annotation.Bean)

Example 4 with DiagnosticsOptions

use of com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions 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)

Aggregations

DiagnosticsOptions (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions)4 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 CodeLensOptions (com.github._1c_syntax.bsl.languageserver.configuration.codelens.CodeLensOptions)2 Mode (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode)2 SkipSupport (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport)2 Map (java.util.Map)2 DEFAULT_LANGUAGE (com.github._1c_syntax.bsl.languageserver.configuration.Language.DEFAULT_LANGUAGE)1 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)1 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)1 FileType (com.github._1c_syntax.bsl.languageserver.context.FileType)1 BSLDiagnostic (com.github._1c_syntax.bsl.languageserver.diagnostics.BSLDiagnostic)1 DiagnosticCompatibilityMode (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode)1 DiagnosticInfo (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo)1 DiagnosticScope (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope)1 CleanupContextBeforeClassAndAfterEachTestMethod (com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod)1 CompatibilityMode (com.github._1c_syntax.mdclasses.common.CompatibilityMode)1 ModuleType (com.github._1c_syntax.mdclasses.mdo.support.ModuleType)1