Search in sources :

Example 1 with ServerContext

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

the class BSLCoreSensor method processFile.

private void processFile(InputFile inputFile, ServerContext bslServerContext) {
    URI uri = inputFile.uri();
    String content;
    try {
        content = IOUtils.toString(inputFile.inputStream(), StandardCharsets.UTF_8);
    } catch (IOException e) {
        LOGGER.warn("Can't read content of file " + uri, e);
        content = "";
    }
    DocumentContext documentContext = bslServerContext.addDocument(uri, content, 1);
    if (langServerEnabled) {
        documentContext.getDiagnostics().forEach(diagnostic -> issuesLoader.createIssue(inputFile, diagnostic));
    }
    saveCpd(inputFile, documentContext);
    highlighter.saveHighlighting(inputFile, documentContext);
    saveMeasures(inputFile, documentContext);
    documentContext.clearSecondaryData();
}
Also used : IOException(java.io.IOException) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) URI(java.net.URI)

Example 2 with ServerContext

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

the class DiagnosticsTest method testCompatibilityMode.

@Test
void testCompatibilityMode() {
    // given
    documentContext = spy(TestUtils.getDocumentContext(""));
    var serverContext = spy(context);
    var bslConfiguration = spy(serverContext.getConfiguration());
    doReturn(serverContext).when(documentContext).getServerContext();
    doReturn(bslConfiguration).when(serverContext).getConfiguration();
    configuration.getDiagnosticsOptions().setMode(Mode.ON);
    // when-then pairs
    doReturn(new CompatibilityMode(3, 10)).when(bslConfiguration).getCompatibilityMode();
    assertThat(diagnosticsConfiguration.diagnostics(documentContext)).anyMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
    doReturn(new CompatibilityMode(3, 6)).when(bslConfiguration).getCompatibilityMode();
    assertThat(diagnosticsConfiguration.diagnostics(documentContext)).anyMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
    doReturn(new CompatibilityMode(2, 16)).when(bslConfiguration).getCompatibilityMode();
    assertThat(diagnosticsConfiguration.diagnostics(documentContext)).noneMatch(diagnostic -> diagnostic instanceof DeprecatedFindDiagnostic);
}
Also used : CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)1 CompatibilityMode (com.github._1c_syntax.mdclasses.common.CompatibilityMode)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1