Search in sources :

Example 16 with Diagnostics

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

the class BSLTextDocumentService method diagnostics.

@Override
public CompletableFuture<Diagnostics> diagnostics(DiagnosticParams params) {
    DocumentContext documentContext = context.getDocument(params.getTextDocument().getUri());
    if (documentContext == null) {
        return CompletableFuture.completedFuture(Diagnostics.EMPTY);
    }
    return CompletableFuture.supplyAsync(() -> {
        var diagnostics = documentContext.getDiagnostics();
        var range = params.getRange();
        if (range != null) {
            diagnostics = diagnostics.stream().filter(diagnostic -> Ranges.containsRange(range, diagnostic.getRange())).collect(Collectors.toList());
        }
        return new Diagnostics(diagnostics, documentContext.getVersion());
    });
}
Also used : Diagnostics(com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Example 17 with Diagnostics

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

the class CompilationDirectiveLostDiagnosticTest method testFormModule.

@Test
void testFormModule() {
    DocumentContext documentContext = getDocumentContext();
    List<Diagnostic> diagnostics = getDiagnostics(documentContext);
    assertThat(diagnostics).hasSize(1);
    assertThat(diagnostics, true).hasRange(9, 8, 9, 16);
}
Also used : Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 18 with Diagnostics

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

the class CommonModuleAssignDiagnosticTest method test.

@SneakyThrows
@Test
void test() {
    Path path = Absolute.path(PATH_TO_METADATA);
    initServerContext(path);
    Path testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
    DocumentContext documentContext = TestUtils.getDocumentContext(testFile.toUri(), FileUtils.readFileToString(testFile.toFile(), StandardCharsets.UTF_8), context);
    List<Diagnostic> diagnostics = diagnosticInstance.getDiagnostics(documentContext);
    assertThat(diagnostics).hasSize(1);
    assertThat(diagnostics, true).hasRange(3, 0, 3, 17);
}
Also used : Path(java.nio.file.Path) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SneakyThrows(lombok.SneakyThrows)

Example 19 with Diagnostics

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

the class CanonicalSpellingKeywordsDiagnosticTest method testQuickFix.

@Test
void testQuickFix() {
    final DocumentContext documentContext = getDocumentContext();
    List<Diagnostic> diagnostics = getDiagnostics();
    final Diagnostic firstDiagnostic = diagnostics.get(0);
    List<CodeAction> quickFixes = getQuickFixes(firstDiagnostic);
    assertThat(quickFixes).hasSize(1);
    final CodeAction quickFix = quickFixes.get(0);
    assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(firstDiagnostic);
    assertThat(quickFix).in(documentContext).hasChanges(1);
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 20 with Diagnostics

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

the class EmptyRegionDiagnosticTest method testQuickFix.

@Test
void testQuickFix() {
    final DocumentContext documentContext = getDocumentContext();
    List<Diagnostic> diagnostics = getDiagnostics();
    final Diagnostic externalRegionDiagnostic = diagnostics.get(2);
    final Diagnostic internalRegionDiagnostic = diagnostics.get(1);
    List<CodeAction> quickFixes = getQuickFixes(externalRegionDiagnostic);
    assertThat(quickFixes).hasSize(1);
    final CodeAction quickFix = quickFixes.get(0);
    assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(externalRegionDiagnostic);
    assertThat(quickFix).of(diagnosticInstance).in(documentContext).fixes(internalRegionDiagnostic);
    assertThat(quickFix).in(documentContext).hasChanges(1).hasNewText("");
}
Also used : CodeAction(org.eclipse.lsp4j.CodeAction) Diagnostic(org.eclipse.lsp4j.Diagnostic) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test)

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