Search in sources :

Example 1 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_2_comments_strings.

@Test
void testMethodVarContentFromDirectFile_2_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");
    // TODO баг - нет \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 2 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_OneCommentsStringFromRight.

@Test
void testFileVarContentFromDirectFile_OneCommentsStringFromRight() {
    // 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(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("описание\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 3 with SymbolTree

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

the class SymbolTreeComputerTest method testModule.

@Test
void testModule() {
    // given
    var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/context/symbol/SymbolTreeComputer.bsl");
    var symbolTreeComputer = new SymbolTreeComputer(documentContext);
    // when
    var symbolTree = symbolTreeComputer.compute();
    // then
    var module = symbolTree.getModule();
    assertThat(module.getOwner()).isEqualTo(documentContext);
    assertThat(module.getParent()).isEmpty();
    assertThat(module.getChildren()).hasSize(2);
    for (SourceDefinedSymbol child : module.getChildren()) {
        assertThat(child.getParent()).hasValue(module);
    }
}
Also used : SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SymbolTree

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

the class DocumentContextLazyDataMeasurer method handleEvent.

/**
 * Обработчик события {@link DocumentContextContentChangedEvent}. Вызывает основную логику выполнения замеров.
 *
 * @param event Событие
 */
@EventListener
@Order
@SneakyThrows
public void handleEvent(DocumentContextContentChangedEvent event) {
    var documentContext = event.getSource();
    LOGGER.debug("Take measurements for {}", documentContext.getUri());
    measureCollector.measureIt(documentContext::getAst, "context: ast");
    measureCollector.measureIt(documentContext::getQueries, "context: queries");
    for (SDBLTokenizer sdblTokenizer : documentContext.getQueries()) {
        measureCollector.measureIt(sdblTokenizer::getAst, "context: queryAst");
    }
    measureCollector.measureIt(documentContext::getSymbolTree, "context: symbolTree");
    measureCollector.measureIt(documentContext::getDiagnosticIgnorance, "context: diagnosticIgnorance");
    measureCollector.measureIt(documentContext::getCognitiveComplexityData, "context: cognitiveComplexity");
    measureCollector.measureIt(documentContext::getCyclomaticComplexityData, "context: cyclomaticComplexity");
    measureCollector.measureIt(documentContext::getMetrics, "context: metrics");
}
Also used : SDBLTokenizer(com.github._1c_syntax.bsl.parser.SDBLTokenizer) Order(org.springframework.core.annotation.Order) SneakyThrows(lombok.SneakyThrows) EventListener(org.springframework.context.event.EventListener)

Example 5 with SymbolTree

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

the class SymbolTreeComputer method compute.

@Override
public SymbolTree compute() {
    ModuleSymbol moduleSymbol = new ModuleSymbolComputer(documentContext).compute();
    List<MethodSymbol> methods = new MethodSymbolComputer(documentContext).compute();
    List<RegionSymbol> regions = new RegionSymbolComputer(documentContext).compute();
    List<VariableSymbol> variables = new VariableSymbolComputer(documentContext).compute();
    List<SourceDefinedSymbol> allOfThem = new ArrayList<>(methods);
    allOfThem.addAll(regions);
    allOfThem.addAll(variables);
    allOfThem.sort(Comparator.comparingInt(symbol -> symbol.getRange().getStart().getLine()));
    List<SourceDefinedSymbol> topLevelSymbols = new ArrayList<>();
    SourceDefinedSymbol currentParent = moduleSymbol;
    for (SourceDefinedSymbol symbol : allOfThem) {
        currentParent = placeSymbol(topLevelSymbols, currentParent, symbol);
    }
    return new SymbolTree(moduleSymbol);
}
Also used : RegionSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol) List(java.util.List) Ranges(com.github._1c_syntax.bsl.languageserver.utils.Ranges) VariableSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol) SymbolTree(com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree) Optional(java.util.Optional) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) ModuleSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol) SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) Comparator(java.util.Comparator) MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) ArrayList(java.util.ArrayList) RegionSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol) ModuleSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol) ArrayList(java.util.ArrayList) MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) SymbolTree(com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree) SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) VariableSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.VariableSymbol)

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