Search in sources :

Example 21 with Diagnostics

use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics 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 22 with Diagnostics

use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.

the class CodeActionProviderTest method testGetCodeActions.

@Test
void testGetCodeActions() {
    // given
    DiagnosticInfo diagnosticInfo = new DiagnosticInfo(CanonicalSpellingKeywordsDiagnostic.class, configuration);
    DiagnosticCode diagnosticCode = diagnosticInfo.getCode();
    List<Diagnostic> diagnostics = documentContext.getDiagnostics().stream().filter(diagnostic -> diagnostic.getCode().equals(diagnosticCode)).peek(diagnostic -> diagnostic.setTags(null)).collect(Collectors.toList());
    CodeActionParams params = new CodeActionParams();
    TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(documentContext.getUri().toString());
    CodeActionContext codeActionContext = new CodeActionContext();
    codeActionContext.setDiagnostics(diagnostics);
    params.setRange(new Range());
    params.setTextDocument(textDocumentIdentifier);
    params.setContext(codeActionContext);
    // when
    List<Either<Command, CodeAction>> codeActions = codeActionProvider.getCodeActions(params, documentContext);
    // then
    assertThat(codeActions).extracting(Either::getRight).hasSizeGreaterThanOrEqualTo(3).anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(0))).anyMatch(codeAction -> codeAction.getDiagnostics().contains(diagnostics.get(1))).anyMatch(codeAction -> codeAction.getKind().equals(CodeActionKind.QuickFix)).allMatch(codeAction -> (codeAction.getDiagnostics().size() == 1) == toBoolean(codeAction.getIsPreferred()));
}
Also used : DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) CodeAction(org.eclipse.lsp4j.CodeAction) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Collectors(java.util.stream.Collectors) CanonicalSpellingKeywordsDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.CanonicalSpellingKeywordsDiagnostic) Test(org.junit.jupiter.api.Test) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) Command(org.eclipse.lsp4j.Command) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CodeActionKind(org.eclipse.lsp4j.CodeActionKind) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) DiagnosticCode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Diagnostic(org.eclipse.lsp4j.Diagnostic) CanonicalSpellingKeywordsDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.CanonicalSpellingKeywordsDiagnostic) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DiagnosticCode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCode) Range(org.eclipse.lsp4j.Range) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with Diagnostics

use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.

the class DiagnosticProviderTest method testComputeDiagnostics.

@Test
void testComputeDiagnostics() {
    // given
    // TODO: это тест на новый getDiagnostics, а не на DiagnosticProvider
    final DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/providers/diagnosticProvider.bsl");
    // when
    final List<Diagnostic> diagnostics = documentContext.getDiagnostics();
    // then
    assertThat(diagnostics.size()).isPositive();
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with Diagnostics

use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.

the class GenericReporterTest method report.

@Test
void report() throws IOException {
    // given
    List<Diagnostic> diagnostics = new ArrayList<>();
    var iterator = diagnosticInfos.entrySet().iterator();
    var firstInfo = iterator.next().getValue();
    var secondInfo = iterator.next().getValue();
    diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 3), "message", DiagnosticSeverity.Error, "test-source", firstInfo.getCode().getStringValue()));
    diagnostics.add(new Diagnostic(Ranges.create(0, 1, 2, 4), "message4", DiagnosticSeverity.Error, "test-source2", firstInfo.getCode().getStringValue()));
    diagnostics.add(new Diagnostic(Ranges.create(3, 1, 4, 4), "message4", DiagnosticSeverity.Error, "test-source2", secondInfo.getCode().getStringValue()));
    DocumentContext documentContext = TestUtils.getDocumentContext("");
    Location location = new Location("file:///fake-uri2.bsl", Ranges.create(0, 2, 2, 3));
    diagnostics.get(0).setRelatedInformation(Collections.singletonList(new DiagnosticRelatedInformation(location, "message")));
    String sourceDir = ".";
    FileInfo fileInfo = new FileInfo(sourceDir, documentContext, diagnostics);
    AnalysisInfo analysisInfo = new AnalysisInfo(LocalDateTime.now(), Collections.singletonList(fileInfo), sourceDir);
    // when
    reporter.report(analysisInfo, Path.of(sourceDir));
    // then
    ObjectMapper mapper = new ObjectMapper();
    GenericIssueReport report = mapper.readValue(file, GenericIssueReport.class);
    assertThat(report).isNotNull();
    assertThat(report.getIssues()).isNotNull();
    assertThat(report.getIssues().size()).isEqualTo(3);
    assertThat(report.getIssues().get(0).getPrimaryLocation()).isNotNull();
    assertThat(report.getIssues().get(0).getSecondaryLocations()).isNotNull();
    assertThat(report.getIssues().get(0).getSecondaryLocations().size()).isEqualTo(1);
    assertThat(report.getIssues().get(2).getRuleId()).isEqualTo(secondInfo.getCode().getStringValue());
    assertThat(report.getIssues().get(1).getSeverity()).isEqualTo(firstInfo.getSeverity().name());
}
Also used : FileInfo(com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticRelatedInformation(org.eclipse.lsp4j.DiagnosticRelatedInformation) 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) Location(org.eclipse.lsp4j.Location) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Diagnostics

use of com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics in project bsl-language-server by 1c-syntax.

the class SmokyTest method testIAllDiagnostics.

@SneakyThrows
@Test
void testIAllDiagnostics() {
    // прочитаем все файлы ресурсов
    var srcDir = "./src/test/resources/";
    var fixtures = FileUtils.listFiles(new File(srcDir), new String[] { "bsl", "os" }, true);
    // получим все возможные коды диагностик и положим в мапу "включенным"
    Map<String, Either<Boolean, Map<String, Object>>> diagnostics = diagnosticInfos.stream().map(DiagnosticInfo::getCode).collect(Collectors.toMap(diagnosticCode -> diagnosticCode.getStringValue(), diagnosticCode -> Either.forLeft(true), (a, b) -> b));
    // создадим новый конфиг, в котором включим все диагностики
    configuration.getDiagnosticsOptions().setParameters(diagnostics);
    // для каждой фикстуры расчитаем диагностики
    // если упадет, запомним файл и текст ошибки
    Map<File, Exception> diagnosticErrors = new HashMap<>();
    fixtures.forEach(filePath -> {
        try {
            var documentContext = TestUtils.getDocumentContextFromFile(filePath.toString());
            documentContext.getDiagnostics();
        } catch (Exception e) {
            diagnosticErrors.put(filePath, e);
        }
    });
    assertThat(diagnosticErrors).isEmpty();
}
Also used : DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) BSLLSPLauncher(com.github._1c_syntax.bsl.languageserver.BSLLSPLauncher) SneakyThrows(lombok.SneakyThrows) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) FileUtils(org.apache.commons.io.FileUtils) Diagnostic(org.eclipse.lsp4j.Diagnostic) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) ExpectSystemExitWithStatus(com.ginsberg.junit.exit.ExpectSystemExitWithStatus) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Paths(java.nio.file.Paths) Map(java.util.Map) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) CleanupContextBeforeClassAndAfterEachTestMethod(com.github._1c_syntax.bsl.languageserver.util.CleanupContextBeforeClassAndAfterEachTestMethod) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) HashMap(java.util.HashMap) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)25 Diagnostic (org.eclipse.lsp4j.Diagnostic)24 Test (org.junit.jupiter.api.Test)19 CodeAction (org.eclipse.lsp4j.CodeAction)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Path (java.nio.file.Path)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)5 DiagnosticInfo (com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo)5 Collectors (java.util.stream.Collectors)5 SneakyThrows (lombok.SneakyThrows)5 Collections (java.util.Collections)4 Range (org.eclipse.lsp4j.Range)4 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)4 TestUtils (com.github._1c_syntax.bsl.languageserver.util.TestUtils)3 Collection (java.util.Collection)3 Map (java.util.Map)3 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2