Search in sources :

Example 6 with SymbolTree

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

the class VariableSymbolMarkupContentBuilderTest method testFileVarContentFromDirectFile_NoComments.

@Test
void testFileVarContentFromDirectFile_NoComments() {
    // given
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    final var symbolTree = documentContext.getSymbolTree();
    var varSymbol = symbolTree.getVariableSymbol("ИмяБезОписания", symbolTree.getModule()).orElseThrow();
    // when
    var content = markupContentBuilder.getContent(varSymbol).getValue();
    assertThat(content).isNotEmpty();
    var blocks = Arrays.asList(content.split("---\n?"));
    assertThat(blocks).hasSize(2);
    assertThat(blocks.get(0)).isEqualTo("```bsl\n" + "Перем ИмяБезОписания\n" + "```\n" + "\n");
    assertThat(blocks.get(1)).matches("Переменная из file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl\n" + "\n");
}
Also used : DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with SymbolTree

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

the class VariableSymbolMarkupContentBuilderTest method testMethodVarContentFromDirectFile_3_comments_strings.

@Test
void testMethodVarContentFromDirectFile_3_comments_strings() {
    // given
    DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
    final var symbolTree = documentContext.getSymbolTree();
    var methodSymbol = symbolTree.getMethodSymbol("ИмяФункции").orElseThrow();
    var varSymbol = symbolTree.getVariableSymbol("Имя_ОписаниеСверхуТриСтрокиПоследняяПустая_Функция", methodSymbol).orElseThrow();
    // when
    var content = markupContentBuilder.getContent(varSymbol).getValue();
    assertThat(content).isNotEmpty();
    var blocks = Arrays.asList(content.split("---\n?"));
    assertThat(blocks).hasSize(3);
    assertThat(blocks.get(0)).isEqualTo("```bsl\n" + "Перем Имя_ОписаниеСверхуТриСтрокиПоследняяПустая_Функция\n" + "```\n" + "\n");
    assertThat(blocks.get(1)).matches("Переменная из file://.*/src/test/resources/hover/variableSymbolMarkupContentBuilder.bsl.ИмяФункции\n" + "\n");
    assertThat(blocks.get(2)).matches("описание 1 строка\n2 строка\n" + "\n");
}
Also used : DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with SymbolTree

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

the class ReferenceIndex method getSourceDefinedSymbol.

private Optional<SourceDefinedSymbol> getSourceDefinedSymbol(MultiKey<String> multikey) {
    String mdoRef = multikey.getKey(0);
    ModuleType moduleType = ModuleType.valueOf(multikey.getKey(1));
    String symbolName = multikey.getKey(2);
    return serverContext.getDocument(mdoRef, moduleType).map(DocumentContext::getSymbolTree).flatMap(symbolTree -> symbolTree.getMethodSymbol(symbolName));
}
Also used : ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType)

Example 9 with SymbolTree

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

the class SourceDefinedSymbolDeclarationReferenceFinder method findReference.

@Override
public Optional<Reference> findReference(URI uri, Position position) {
    DocumentContext document = serverContext.getDocument(uri);
    if (document == null) {
        return Optional.empty();
    }
    SymbolTree symbolTree = document.getSymbolTree();
    return symbolTree.getChildrenFlat().stream().filter(sourceDefinedSymbol -> Ranges.containsPosition(sourceDefinedSymbol.getSelectionRange(), position)).map(sourceDefinedSymbol -> new Reference(symbolTree.getModule(), sourceDefinedSymbol, uri, sourceDefinedSymbol.getSelectionRange())).findFirst();
}
Also used : ServerContext(com.github._1c_syntax.bsl.languageserver.context.ServerContext) Component(org.springframework.stereotype.Component) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) SymbolTree(com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Position(org.eclipse.lsp4j.Position) Optional(java.util.Optional) URI(java.net.URI) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) SymbolTree(com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)6 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 SourceDefinedSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol)2 SymbolTree (com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree)2 Ranges (com.github._1c_syntax.bsl.languageserver.utils.Ranges)2 Optional (java.util.Optional)2 ServerContext (com.github._1c_syntax.bsl.languageserver.context.ServerContext)1 MethodSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol)1 ModuleSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol)1 RegionSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol)1 VariableSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol)1 SDBLTokenizer (com.github._1c_syntax.bsl.parser.SDBLTokenizer)1 ModuleType (com.github._1c_syntax.mdclasses.mdo.support.ModuleType)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 SneakyThrows (lombok.SneakyThrows)1