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