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();
}
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"));
}
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);
}
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();
}
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");
}
Aggregations