Java Code Examples for org.eclipse.lsp4j.ReferenceParams#setPosition()

The following examples show how to use org.eclipse.lsp4j.ReferenceParams#setPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReferencesHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: AbstractCamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected CompletableFuture<List<? extends Location>> getReferencesFor(CamelLanguageServer camelLanguageServer, Position position, String uri) {
	TextDocumentService textDocumentService = camelLanguageServer.getTextDocumentService();
	ReferenceParams params = new ReferenceParams();
	params.setPosition(position);
	params.setTextDocument(new TextDocumentIdentifier(uri));
	return textDocumentService.references(params);
}
 
Example 3
Source File: ImplementationsSearchQuery.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@Override public IStatus run(IProgressMonitor monitor) {
	startTime = System.currentTimeMillis();
	// Cancel last references future if needed.
	if (references != null) {
		references.cancel(true);
	}
	AbstractTextSearchResult textResult = (AbstractTextSearchResult) getSearchResult();
	textResult.removeAll();

	try {
		// Execute LSP "references" service
		ReferenceParams params = new ReferenceParams();
		params.setContext(new ReferenceContext(true));
		params.setTextDocument(new TextDocumentIdentifier(info.getFileUri().toString()));
		params.setPosition(position);
		info.getInitializedLanguageClient().thenCompose(languageServer -> ((RLSServerInterface) languageServer).implementations(params)).thenAccept(locs -> {
			// Loop for each LSP Location and convert it to Match search.
			for (Location loc : locs) {
				Match match = toMatch(loc);
				result.addMatch(match);
			}
		});
		return Status.OK_STATUS;
	} catch (Exception ex) {
		return new Status(IStatus.ERROR, LanguageServerPlugin.getDefault().getBundle().getSymbolicName(), ex.getMessage(), ex);
	}
}
 
Example 4
Source File: ReferencesHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@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());
}