Search in sources :

Example 1 with SourceDefinedSymbol

use of com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol 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 2 with SourceDefinedSymbol

use of com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol 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)

Example 3 with SourceDefinedSymbol

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

the class ReferenceIndex method isReferenceAccessible.

private static boolean isReferenceAccessible(Reference reference) {
    if (!reference.isSourceDefinedSymbolReference()) {
        return true;
    }
    SourceDefinedSymbol to = reference.getSourceDefinedSymbol().orElseThrow();
    SourceDefinedSymbol from = reference.getFrom();
    if (to.getOwner().equals(from.getOwner())) {
        return true;
    }
    if (to instanceof Exportable) {
        return ((Exportable) to).isExport();
    }
    return true;
}
Also used : Exportable(com.github._1c_syntax.bsl.languageserver.context.symbol.Exportable) SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol)

Example 4 with SourceDefinedSymbol

use of com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol 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 5 with SourceDefinedSymbol

use of com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol 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

SourceDefinedSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol)3 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)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 Exportable (com.github._1c_syntax.bsl.languageserver.context.symbol.Exportable)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 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 Position (org.eclipse.lsp4j.Position)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1