Search in sources :

Example 16 with DocumentContext

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

the class DefinitionProviderTest method testEmptyDefinition.

@Test
void testEmptyDefinition() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    var params = new DefinitionParams();
    params.setPosition(new Position(1, 0));
    // when
    var definitions = definitionProvider.getDefinition(documentContext, params);
    // then
    assertThat(definitions).isEmpty();
}
Also used : Position(org.eclipse.lsp4j.Position) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) DefinitionParams(org.eclipse.lsp4j.DefinitionParams) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with DocumentContext

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

the class DocumentSymbolProviderTest method testDocumentSymbol.

@Test
void testDocumentSymbol() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/providers/documentSymbol.bsl");
    List<Either<SymbolInformation, DocumentSymbol>> documentSymbols = documentSymbolProvider.getDocumentSymbols(documentContext);
    assertThat(documentSymbols).hasSize(9);
    // global variables
    assertThat(documentSymbols).filteredOn(documentSymbol -> documentSymbol.getRight().getKind().equals(SymbolKind.Variable)).hasSize(3).extracting(Either::getRight).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(0, 6, 0, 7))).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(2, 6, 2, 7))).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(2, 9, 2, 10)));
    // methods
    assertThat(documentSymbols).filteredOn(documentSymbol -> documentSymbol.getRight().getKind().equals(SymbolKind.Method)).hasSize(4).extracting(Either::getRight).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(4, 0, 5, 14))).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(7, 0, 8, 12))).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(10, 0, 13, 14))).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(47, 0, 48, 12))).filteredOn(documentSymbol1 -> documentSymbol1.getTags().contains(SymbolTag.Deprecated)).anyMatch(documentSymbol -> documentSymbol.getRange().equals(Ranges.create(47, 0, 48, 12)));
    // sub vars
    assertThat(documentSymbols).filteredOn(documentSymbol -> documentSymbol.getRight().getKind().equals(SymbolKind.Method)).extracting(Either::getRight).flatExtracting(DocumentSymbol::getChildren).filteredOn(documentSymbol -> documentSymbol.getKind() == SymbolKind.Variable).hasSize(3).anyMatch(subVar -> subVar.getRange().equals(Ranges.create(11, 10, 11, 11))).anyMatch(subVar -> subVar.getRange().equals(Ranges.create(12, 10, 12, 11))).anyMatch(subVar -> subVar.getRange().equals(Ranges.create(12, 12, 12, 13)));
    // regions
    assertThat(documentSymbols).filteredOn(documentSymbol -> documentSymbol.getRight().getKind() == SymbolKind.Namespace).extracting(Either::getRight).hasSize(2).flatExtracting(DocumentSymbol::getChildren).hasSize(3).anyMatch(documentSymbol -> documentSymbol.getKind() == SymbolKind.Namespace).anyMatch(documentSymbol -> documentSymbol.getKind() == SymbolKind.Method).filteredOn(documentSymbol -> documentSymbol.getKind() == SymbolKind.Method).hasSize(2).anyMatch(subVar -> subVar.getRange().equals(Ranges.create(17, 0, 19, 14))).anyMatch(subVar -> subVar.getRange().equals(Ranges.create(36, 0, 42, 14)));
    DocumentSymbol externalRegion = documentSymbols.stream().map(Either::getRight).filter(documentSymbol -> documentSymbol.getKind() == SymbolKind.Namespace).filter(documentSymbol -> documentSymbol.getName().equals("ВнешняяОбласть")).findFirst().get();
    assertThat(externalRegion.getChildren()).hasSize(1).allMatch(documentSymbol -> documentSymbol.getKind() == SymbolKind.Method);
    DocumentSymbol method = externalRegion.getChildren().get(0);
    assertThat(method.getChildren()).hasSize(1).allMatch(documentSymbol -> documentSymbol.getKind() == SymbolKind.Namespace).allMatch(documentSymbol -> documentSymbol.getName().equals("ВнутренняяОбласть1"));
    DocumentSymbol internalRegion1 = method.getChildren().get(0);
    assertThat(internalRegion1.getChildren()).hasSize(1).allMatch(documentSymbol -> documentSymbol.getKind() == SymbolKind.Namespace).allMatch(documentSymbol -> documentSymbol.getName().equals("ВнутренняяОбласть2"));
}
Also used : SymbolKind(org.eclipse.lsp4j.SymbolKind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) SymbolInformation(org.eclipse.lsp4j.SymbolInformation) Test(org.junit.jupiter.api.Test) SymbolTag(org.eclipse.lsp4j.SymbolTag) List(java.util.List) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DocumentSymbol(org.eclipse.lsp4j.DocumentSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with DocumentContext

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

the class FoldingRangeProviderTest method testFoldingRange.

@Test
void testFoldingRange() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/providers/foldingRange.bsl");
    List<FoldingRange> foldingRanges = foldingRangeProvider.getFoldingRange(documentContext);
    assertThat(foldingRanges).hasSize(11);
    // regions
    assertThat(foldingRanges).filteredOn(foldingRange -> foldingRange.getKind().equals(FoldingRangeKind.Region)).anyMatch(foldingRange -> foldingRange.getStartLine() == 3 && foldingRange.getEndLine() == 26).anyMatch(foldingRange -> foldingRange.getStartLine() == 5 && foldingRange.getEndLine() == 19).anyMatch(foldingRange -> foldingRange.getStartLine() == 7 && foldingRange.getEndLine() == 17).anyMatch(foldingRange -> foldingRange.getStartLine() == 11 && foldingRange.getEndLine() == 15).anyMatch(foldingRange -> foldingRange.getStartLine() == 12 && foldingRange.getEndLine() == 14).anyMatch(foldingRange -> foldingRange.getStartLine() == 23 && foldingRange.getEndLine() == 24).anyMatch(foldingRange -> foldingRange.getStartLine() == 28 && foldingRange.getEndLine() == 29);
    // comments
    assertThat(foldingRanges).filteredOn(foldingRange -> foldingRange.getKind().equals(FoldingRangeKind.Comment)).hasSize(2).anyMatch(foldingRange -> foldingRange.getStartLine() == 9 && foldingRange.getEndLine() == 10).anyMatch(foldingRange -> foldingRange.getStartLine() == 21 && foldingRange.getEndLine() == 22);
    // import
    assertThat(foldingRanges).filteredOn(foldingRange -> foldingRange.getKind().equals(FoldingRangeKind.Imports)).hasSize(1).anyMatch(foldingRange -> foldingRange.getStartLine() == 0 && foldingRange.getEndLine() == 1);
}
Also used : Test(org.junit.jupiter.api.Test) List(java.util.List) FoldingRangeKind(org.eclipse.lsp4j.FoldingRangeKind) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) FoldingRange(org.eclipse.lsp4j.FoldingRange) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) FoldingRange(org.eclipse.lsp4j.FoldingRange) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with DocumentContext

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

the class FoldingRangeProviderTest method testFoldingRangeParseError.

@Test
void testFoldingRangeParseError() {
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/providers/foldingRangeParseError.bsl");
    List<FoldingRange> foldingRanges = foldingRangeProvider.getFoldingRange(documentContext);
    assertThat(foldingRanges).isEmpty();
}
Also used : DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) FoldingRange(org.eclipse.lsp4j.FoldingRange) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with DocumentContext

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

the class FormatProviderTest method testFormatUnaryMinus.

@Test
void testFormatUnaryMinus() {
    // given
    DocumentFormattingParams params = new DocumentFormattingParams();
    params.setTextDocument(getTextDocumentIdentifier());
    params.setOptions(new FormattingOptions(4, true));
    String fileContent = "Возврат-1>-2";
    DocumentContext documentContext = TestUtils.getDocumentContext(URI.create(params.getTextDocument().getUri()), fileContent);
    // when
    List<TextEdit> textEdits = formatProvider.getFormatting(params, documentContext);
    // then
    assertThat(textEdits).hasSize(1);
    TextEdit textEdit = textEdits.get(0);
    assertThat(textEdits.get(0).getNewText()).isEqualTo("Возврат -1 > -2");
}
Also used : FormattingOptions(org.eclipse.lsp4j.FormattingOptions) DocumentFormattingParams(org.eclipse.lsp4j.DocumentFormattingParams) TextEdit(org.eclipse.lsp4j.TextEdit) 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