Search in sources :

Example 1 with Reference

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());
}
Also used : ReferenceResolver(com.github._1c_syntax.bsl.languageserver.references.ReferenceResolver) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) MdoRefBuilder(com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) SourceDefinedSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol) Collectors(java.util.stream.Collectors) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) ArrayList(java.util.ArrayList) Reference(com.github._1c_syntax.bsl.languageserver.references.Reference) CallHierarchyIncomingCall(org.eclipse.lsp4j.CallHierarchyIncomingCall) ReferenceIndex(com.github._1c_syntax.bsl.languageserver.references.ReferenceIndex) Collectors.toCollection(java.util.stream.Collectors.toCollection) Component(org.springframework.stereotype.Component) List(java.util.List) CallHierarchyOutgoingCallsParams(org.eclipse.lsp4j.CallHierarchyOutgoingCallsParams) CallHierarchyOutgoingCall(org.eclipse.lsp4j.CallHierarchyOutgoingCall) Collectors.mapping(java.util.stream.Collectors.mapping) Position(org.eclipse.lsp4j.Position) URI(java.net.URI) CallHierarchyIncomingCallsParams(org.eclipse.lsp4j.CallHierarchyIncomingCallsParams) CallHierarchyPrepareParams(org.eclipse.lsp4j.CallHierarchyPrepareParams) Collections(java.util.Collections) CallHierarchyIncomingCall(org.eclipse.lsp4j.CallHierarchyIncomingCall) Position(org.eclipse.lsp4j.Position) Reference(com.github._1c_syntax.bsl.languageserver.references.Reference) CallHierarchyItem(org.eclipse.lsp4j.CallHierarchyItem) URI(java.net.URI)

Example 2 with Reference

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));
}
Also used : ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) 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 Reference

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);
}
Also used : MethodSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Reference

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));
}
Also used : Position(org.eclipse.lsp4j.Position) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Reference

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()));
}
Also used : Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Position(org.eclipse.lsp4j.Position) Autowired(org.springframework.beans.factory.annotation.Autowired) TestUtils(com.github._1c_syntax.bsl.languageserver.util.TestUtils) Position(org.eclipse.lsp4j.Position) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)7 Position (org.eclipse.lsp4j.Position)7 RequiredArgsConstructor (lombok.RequiredArgsConstructor)5 Reference (com.github._1c_syntax.bsl.languageserver.references.Reference)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Component (org.springframework.stereotype.Component)4 SourceDefinedSymbol (com.github._1c_syntax.bsl.languageserver.context.symbol.SourceDefinedSymbol)3 ReferenceIndex (com.github._1c_syntax.bsl.languageserver.references.ReferenceIndex)3 ReferenceResolver (com.github._1c_syntax.bsl.languageserver.references.ReferenceResolver)3 URI (java.net.URI)3 Optional (java.util.Optional)3 Symbol (com.github._1c_syntax.bsl.languageserver.context.symbol.Symbol)2 MdoRefBuilder (com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2