Search in sources :

Example 56 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext in project sonar-bsl-plugin-community by 1c-syntax.

the class BSLCoreSensor method saveMeasures.

private void saveMeasures(InputFile inputFile, DocumentContext documentContext) {
    MetricStorage metrics = documentContext.getMetrics();
    context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.NCLOC).withValue(metrics.getNcloc()).save();
    context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.STATEMENTS).withValue(metrics.getStatements()).save();
    context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.FUNCTIONS).withValue(metrics.getProcedures() + metrics.getFunctions()).save();
    context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COGNITIVE_COMPLEXITY).withValue(metrics.getCognitiveComplexity()).save();
    context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMPLEXITY).withValue(metrics.getCyclomaticComplexity()).save();
    context.<Integer>newMeasure().on(inputFile).forMetric(CoreMetrics.COMMENT_LINES).withValue(metrics.getComments()).save();
    FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(inputFile);
    for (int line : metrics.getNclocData()) {
        fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, 1);
    }
    fileLinesContext.save();
}
Also used : MetricStorage(com.github._1c_syntax.bsl.languageserver.context.MetricStorage) FileLinesContext(org.sonar.api.measures.FileLinesContext)

Example 57 with DocumentContext

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

the class BSLTextDocumentService method rangeFormatting.

@Override
public CompletableFuture<List<? extends TextEdit>> rangeFormatting(DocumentRangeFormattingParams params) {
    DocumentContext documentContext = context.getDocument(params.getTextDocument().getUri());
    if (documentContext == null) {
        return CompletableFuture.completedFuture(null);
    }
    List<TextEdit> edits = formatProvider.getRangeFormatting(params, documentContext);
    return CompletableFuture.completedFuture(edits);
}
Also used : TextEdit(org.eclipse.lsp4j.TextEdit) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Example 58 with DocumentContext

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

the class BSLTextDocumentService method didClose.

@Override
public void didClose(DidCloseTextDocumentParams params) {
    DocumentContext documentContext = context.getDocument(params.getTextDocument().getUri());
    if (documentContext == null) {
        return;
    }
    documentContext.clearSecondaryData();
    diagnosticProvider.publishEmptyDiagnosticList(documentContext);
}
Also used : DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Example 59 with DocumentContext

use of com.github._1c_syntax.bsl.languageserver.context.DocumentContext 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 60 with DocumentContext

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

the class BSLTextDocumentService method formatting.

@Override
public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormattingParams params) {
    DocumentContext documentContext = context.getDocument(params.getTextDocument().getUri());
    if (documentContext == null) {
        return CompletableFuture.completedFuture(null);
    }
    List<TextEdit> edits = formatProvider.getFormatting(params, documentContext);
    return CompletableFuture.completedFuture(edits);
}
Also used : TextEdit(org.eclipse.lsp4j.TextEdit) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)86 Test (org.junit.jupiter.api.Test)69 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)57 Diagnostic (org.eclipse.lsp4j.Diagnostic)36 List (java.util.List)22 Position (org.eclipse.lsp4j.Position)21 SneakyThrows (lombok.SneakyThrows)17 Path (java.nio.file.Path)16 CodeAction (org.eclipse.lsp4j.CodeAction)16 TestUtils (com.github._1c_syntax.bsl.languageserver.util.TestUtils)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 Collectors (java.util.stream.Collectors)14 Range (org.eclipse.lsp4j.Range)13 ArrayList (java.util.ArrayList)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)12 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)12 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)11 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)10 MDCommonModule (com.github._1c_syntax.mdclasses.mdo.MDCommonModule)10