use of com.github._1c_syntax.bsl.languageserver.references.Reference in project bsl-language-server by 1c-syntax.
the class CallHierarchyProvider method incomingCalls.
public List<CallHierarchyIncomingCall> incomingCalls(DocumentContext documentContext, CallHierarchyIncomingCallsParams params) {
URI uri = documentContext.getUri();
CallHierarchyItem item = params.getItem();
Position position = item.getSelectionRange().getStart();
return referenceResolver.findReference(uri, position).flatMap(Reference::getSourceDefinedSymbol).stream().map(referenceIndex::getReferencesTo).flatMap(Collection::stream).collect(groupingBy(Reference::getFrom, mapping(Reference::getSelectionRange, toCollection(ArrayList::new)))).entrySet().stream().map(entry -> new CallHierarchyIncomingCall(getCallHierarchyItem(entry.getKey()), entry.getValue())).collect(Collectors.toList());
}
use of com.github._1c_syntax.bsl.languageserver.references.Reference in project bsl-language-server by 1c-syntax.
the class ReferencesProviderTest method testLocalMethods.
@Test
void testLocalMethods() {
DocumentContext documentContext = TestUtils.getDocumentContextFromFile(PATH_TO_FILE);
var params = new ReferenceParams();
params.setPosition(new Position(0, 10));
// when
var references = referencesProvider.getReferences(documentContext, params);
// then
assertThat(references).hasSize(1);
var reference = references.get(0);
assertThat(reference.getUri()).isEqualTo(documentContext.getUri().toString());
assertThat(reference.getRange()).isEqualTo(Ranges.create(4, 0, 10));
}
use of com.github._1c_syntax.bsl.languageserver.references.Reference in project bsl-language-server by 1c-syntax.
the class ReferenceIndexFillerTest method testRebuildClearReferences.
@Test
void testRebuildClearReferences() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/references/ReferenceIndexFillerTest.bsl");
MethodSymbol methodSymbol = documentContext.getSymbolTree().getMethodSymbol("Локальная").orElseThrow();
// when
referenceIndexFiller.fill(documentContext);
List<Reference> referencesTo = referenceIndex.getReferencesTo(methodSymbol);
// then
assertThat(referencesTo).hasSize(1);
// when
// recalculate
referenceIndexFiller.fill(documentContext);
referencesTo = referenceIndex.getReferencesTo(methodSymbol);
// then
assertThat(referencesTo).hasSize(1);
}
use of com.github._1c_syntax.bsl.languageserver.references.Reference in project bsl-language-server by 1c-syntax.
the class ReferenceIndexFillerTest method testFindCalledMethod.
@Test
void testFindCalledMethod() {
// given
DocumentContext documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/references/ReferenceIndexFillerTest.bsl");
referenceIndexFiller.fill(documentContext);
// when
Optional<Reference> referencedSymbol = referenceIndex.getReference(documentContext.getUri(), new Position(4, 0));
// then
assertThat(referencedSymbol).isPresent();
assertThat(referencedSymbol).get().extracting(Reference::getSymbol).extracting(Symbol::getName).isEqualTo("Локальная");
assertThat(referencedSymbol).get().extracting(Reference::getSelectionRange).isEqualTo(Ranges.create(4, 0, 4, 9));
}
use of com.github._1c_syntax.bsl.languageserver.references.Reference in project bsl-language-server by 1c-syntax.
the class SourceDefinedSymbolDeclarationReferenceFinderTest method testFindReferenceOnMethodDeclaration.
@Test
void testFindReferenceOnMethodDeclaration() {
// given
var documentContext = TestUtils.getDocumentContextFromFile("./src/test/resources/references/SourceDefinedSymbolDeclarationReferenceFinder.bsl");
var module = documentContext.getSymbolTree().getModule();
var method = documentContext.getSymbolTree().getMethods().get(0);
// when
var optionalReference = referenceFinder.findReference(documentContext.getUri(), new Position(0, 15));
// then
assertThat(optionalReference).isPresent().hasValueSatisfying(reference -> assertThat(reference.getFrom()).isEqualTo(module)).hasValueSatisfying(reference -> assertThat(reference.getSymbol()).isEqualTo(method)).hasValueSatisfying(reference -> assertThat(reference.getSelectionRange()).isEqualTo(method.getSelectionRange()));
}
Aggregations