Search in sources :

Example 1 with ReferenceContext

use of org.eclipse.lsp4j.ReferenceContext in project eclipse.jdt.ls by eclipse.

the class ReferencesHandlerTest method testEmpty.

@Test
public void testEmpty() {
    ReferenceParams param = new ReferenceParams();
    param.setPosition(new Position(1, 1));
    param.setContext(new ReferenceContext(false));
    param.setTextDocument(new TextDocumentIdentifier("/foo/bar"));
    List<Location> references = handler.findReferences(param, monitor);
    assertNotNull(references);
    assertTrue("references are not empty", references.isEmpty());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) Location(org.eclipse.lsp4j.Location) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Example 2 with ReferenceContext

use of org.eclipse.lsp4j.ReferenceContext in project xtext-core by eclipse.

the class AbstractLanguageServerTest method testReferences.

protected void testReferences(final Procedure1<? super ReferenceTestConfiguration> configurator) {
    try {
        @Extension final ReferenceTestConfiguration configuration = new ReferenceTestConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String fileUri = this.initializeContext(configuration).getUri();
        ReferenceParams _referenceParams = new ReferenceParams();
        final Procedure1<ReferenceParams> _function = (ReferenceParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
            it.setTextDocument(_textDocumentIdentifier);
            int _line = configuration.getLine();
            int _column = configuration.getColumn();
            Position _position = new Position(_line, _column);
            it.setPosition(_position);
            boolean _isIncludeDeclaration = configuration.isIncludeDeclaration();
            ReferenceContext _referenceContext = new ReferenceContext(_isIncludeDeclaration);
            it.setContext(_referenceContext);
        };
        ReferenceParams _doubleArrow = ObjectExtensions.<ReferenceParams>operator_doubleArrow(_referenceParams, _function);
        final CompletableFuture<List<? extends Location>> referencesFuture = this.languageServer.references(_doubleArrow);
        final List<? extends Location> references = referencesFuture.get();
        Procedure1<? super List<? extends Location>> _assertReferences = configuration.getAssertReferences();
        boolean _tripleNotEquals = (_assertReferences != null);
        if (_tripleNotEquals) {
            configuration.getAssertReferences().apply(references);
        } else {
            final String actualReferences = this.toExpectation(references);
            this.assertEquals(configuration.getExpectedReferences(), actualReferences);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Extension(org.eclipse.xtext.xbase.lib.Extension) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) Location(org.eclipse.lsp4j.Location)

Example 3 with ReferenceContext

use of org.eclipse.lsp4j.ReferenceContext in project eclipse.jdt.ls by eclipse.

the class ReferencesHandlerTest method testReference.

@Test
public void testReference() {
    URI uri = project.getFile("src/java/Foo2.java").getRawLocationURI();
    String fileURI = ResourceUtils.fixURI(uri);
    ReferenceParams param = new ReferenceParams();
    param.setPosition(new Position(5, 16));
    param.setContext(new ReferenceContext(true));
    param.setTextDocument(new TextDocumentIdentifier(fileURI));
    List<Location> references = handler.findReferences(param, monitor);
    assertNotNull("findReferences should not return null", references);
    assertEquals(1, references.size());
    Location l = references.get(0);
    String refereeUri = ResourceUtils.fixURI(project.getFile("src/java/Foo3.java").getRawLocationURI());
    assertEquals(refereeUri, l.getUri());
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ReferenceParams(org.eclipse.lsp4j.ReferenceParams) Position(org.eclipse.lsp4j.Position) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) URI(java.net.URI) Location(org.eclipse.lsp4j.Location) Test(org.junit.Test) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)

Aggregations

Location (org.eclipse.lsp4j.Location)3 Position (org.eclipse.lsp4j.Position)3 ReferenceContext (org.eclipse.lsp4j.ReferenceContext)3 ReferenceParams (org.eclipse.lsp4j.ReferenceParams)3 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)3 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)2 Test (org.junit.Test)2 URI (java.net.URI)1 List (java.util.List)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)1 Extension (org.eclipse.xtext.xbase.lib.Extension)1