Search in sources :

Example 21 with DocumentContext

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

the class FormatProviderTest method testRangeFormat.

@Test
void testRangeFormat() throws IOException {
    // given
    int startLine = 4;
    int endLine = 25;
    DocumentRangeFormattingParams params = new DocumentRangeFormattingParams();
    params.setTextDocument(getTextDocumentIdentifier());
    params.setRange(Ranges.create(startLine, 0, endLine, 0));
    params.setOptions(new FormattingOptions(4, true));
    String fileContent = FileUtils.readFileToString(getTestFile(), StandardCharsets.UTF_8);
    String formattedFileContent = FileUtils.readFileToString(getFormattedTestFile(), StandardCharsets.UTF_8);
    String[] strings = formattedFileContent.split("\n");
    StringJoiner joiner = new StringJoiner("\n");
    for (int i = 0; i < strings.length; i++) {
        if (i < startLine || i > endLine) {
            continue;
        }
        joiner.add(strings[i]);
    }
    formattedFileContent = joiner.toString();
    DocumentContext documentContext = TestUtils.getDocumentContext(URI.create(params.getTextDocument().getUri()), fileContent);
    // when
    List<TextEdit> textEdits = formatProvider.getRangeFormatting(params, documentContext);
    // then
    assertThat(textEdits).hasSize(1);
    TextEdit textEdit = textEdits.get(0);
    assertThat(textEdit.getNewText()).isEqualTo(formattedFileContent);
}
Also used : FormattingOptions(org.eclipse.lsp4j.FormattingOptions) DocumentRangeFormattingParams(org.eclipse.lsp4j.DocumentRangeFormattingParams) TextEdit(org.eclipse.lsp4j.TextEdit) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) StringJoiner(java.util.StringJoiner) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with DocumentContext

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

the class HoverProviderTest method testSourceDefinedVariable.

@Test
void testSourceDefinedVariable() {
    // given
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    HoverParams params = new HoverParams();
    params.setPosition(new Position(6, 15));
    // when
    Optional<Hover> optionalHover = hoverProvider.getHover(documentContext, params);
    // then
    assertThat(optionalHover).isPresent();
    var hover = optionalHover.get();
    assertThat(hover.getContents().getRight().getValue()).isNotEmpty();
    assertThat(hover.getRange()).isEqualTo(Ranges.create(6, 10, 20));
}
Also used : HoverParams(org.eclipse.lsp4j.HoverParams) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with DocumentContext

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

the class HoverProviderTest method testSourceDefinedMethod.

@Test
void testSourceDefinedMethod() {
    // given
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    HoverParams params = new HoverParams();
    params.setPosition(new Position(3, 10));
    // when
    Optional<Hover> optionalHover = hoverProvider.getHover(documentContext, params);
    // then
    assertThat(optionalHover).isPresent();
    var hover = optionalHover.get();
    assertThat(hover.getContents().getRight().getValue()).isNotEmpty();
    assertThat(hover.getRange()).isEqualTo(Ranges.create(3, 8, 18));
}
Also used : HoverParams(org.eclipse.lsp4j.HoverParams) Position(org.eclipse.lsp4j.Position) Hover(org.eclipse.lsp4j.Hover) 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 DocumentContext

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

the class ReferencesProviderTest method testMethodsFromManagerModule.

@Test
void testMethodsFromManagerModule() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    var managerModule = serverContext.getDocument("Catalog.Справочник1", ModuleType.ManagerModule).orElseThrow();
    var params = new ReferenceParams();
    params.setPosition(new Position(24, 15));
    // when
    var references = referencesProvider.getReferences(managerModule, params);
    // then
    var location = new Location(documentContext.getUri().toString(), Ranges.create(6, 24, 38));
    assertThat(references).isNotEmpty().contains(location);
}
Also used : ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Location(org.eclipse.lsp4j.Location) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with DocumentContext

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

the class ReferencesProviderTest method testLocalMethods.

@Test
void testLocalMethods() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    var params = new ReferenceParams();
    params.setPosition(new Position(0, 10));
    // when
    var references = referencesProvider.getReferences(documentContext, params);
    // then
    assertThat(references).hasSize(1);
    var reference = references.get(0);
    assertThat(reference.getUri()).isEqualTo(documentContext.getUri().toString());
    assertThat(reference.getRange()).isEqualTo(Ranges.create(4, 0, 10));
}
Also used : ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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