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