org.eclipse.lsp4j.ReferenceParams Java Examples

The following examples show how to use org.eclipse.lsp4j.ReferenceParams. 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: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
		return getXMLLanguageService().findReferences(xmlDocument, params.getPosition(), params.getContext(),
				cancelChecker);
	});
}
 
Example #3
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public List<? extends Location> getReferences(Document document, XtextResource resource, ReferenceParams params,
		IReferenceFinder.IResourceAccess resourceAccess, IResourceDescriptions indexData,
		CancelIndicator cancelIndicator) {
	int offset = document.getOffSet(params.getPosition());
	List<? extends Location> definitions = Collections.emptyList();
	if (params.getContext().isIncludeDeclaration()) {
		definitions = getDefinitions(resource, offset, resourceAccess, cancelIndicator);
	}
	List<? extends Location> references = getReferences(resource, offset, resourceAccess, indexData,
			cancelIndicator);
	List<Location> result = new ArrayList<>();
	result.addAll(definitions);
	result.addAll(references);
	return result;
}
 
Example #4
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 #5
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	URI uri = getURI(params);
	return openFilesManager.runInOpenFileContext(uri, "references", (ofc, ci) -> {
		return references(ofc, params, ci);
	});
}
 
Example #6
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute the references. Executed in read request.
 */
protected List<? extends Location> references(OpenFileContext ofc, ReferenceParams params,
		CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	DocumentSymbolService documentSymbolService = getService(uri, DocumentSymbolService.class);
	if ((documentSymbolService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	return documentSymbolService.getReferences(doc, res, params, resourceAccess,
			openFilesManager.createLiveScopeIndex(), cancelIndicator);
}
 
Example #7
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute the references. Executed in read request.
 * @since 2.20
 */
protected List<? extends Location> references(ReferenceParams params, CancelIndicator cancelIndicator) {
	URI uri = getURI(params);
	DocumentSymbolService documentSymbolService = getService(uri, DocumentSymbolService.class);
	if (documentSymbolService == null) {
		return Collections.emptyList();
	}
	return workspaceManager.doRead(uri, (document, resource) -> documentSymbolService.getReferences(document,
			resource, params, resourceAccess, workspaceManager.getIndex(), cancelIndicator));
}
 
Example #8
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 #9
Source File: GroovyServices.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	URI uri = URI.create(params.getTextDocument().getUri());
	recompileIfContextChanged(uri);

	ReferenceProvider provider = new ReferenceProvider(astVisitor);
	return provider.provideReferences(params.getTextDocument(), params.getPosition());
}
 
Example #10
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all references of the definition referenced at the current position
 * in a text document. Does not necessarily get called where a definition is
 * defined, but may be at one of the references.
 */
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params)
{
    return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
    {
        cancelToken.checkCanceled();

        //make sure that the latest changes have been passed to
        //workspace.fileChanged() before proceeding
        if(realTimeProblemsChecker != null)
        {
            realTimeProblemsChecker.updateNow();
        }

        compilerWorkspace.startBuilding();
        try
        {
            ReferencesProvider provider = new ReferencesProvider(workspaceFolderManager, fileTracker);
            return provider.references(params, cancelToken);
        }
        finally
        {
            compilerWorkspace.doneBuilding();
        }
    });
}
 
Example #11
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());
}
 
Example #12
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	logInfo(">> document/references");
	ReferencesHandler handler = new ReferencesHandler(this.preferenceManager);
	return computeAsync((monitor) -> handler.findReferences(params, monitor));
}
 
Example #13
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	return requestManager.runRead(cancelIndicator -> references(params, cancelIndicator));
}
 
Example #14
Source File: ReferencesHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public List<Location> findReferences(ReferenceParams param, IProgressMonitor monitor) {

		final List<Location> locations = new ArrayList<>();
		try {
			IJavaElement elementToSearch = JDTUtils.findElementAtSelection(JDTUtils.resolveTypeRoot(param.getTextDocument().getUri()), param.getPosition().getLine(), param.getPosition().getCharacter(), this.preferenceManager, monitor);

			if (elementToSearch == null) {
				return locations;
			}

			boolean includeClassFiles = preferenceManager.isClientSupportsClassFileContent();
			SearchEngine engine = new SearchEngine();
			SearchPattern pattern = SearchPattern.createPattern(elementToSearch, IJavaSearchConstants.REFERENCES);

			engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, createSearchScope(), new SearchRequestor() {

				@Override
				public void acceptSearchMatch(SearchMatch match) throws CoreException {
					Object o = match.getElement();
					if (o instanceof IJavaElement) {
						IJavaElement element = (IJavaElement) o;
						ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
						Location location = null;
						if (compilationUnit != null) {
							location = JDTUtils.toLocation(compilationUnit, match.getOffset(), match.getLength());
						} else if (includeClassFiles) {
							IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE);
							if (cf != null && cf.getSourceRange() != null) {
								location = JDTUtils.toLocation(cf, match.getOffset(), match.getLength());
							}
						}
						if (location != null) {
							locations.add(location);
						}
					}
				}
			}, monitor);

		} catch (CoreException e) {
			JavaLanguageServerPlugin.logException("Find references failure ", e);
		}
		return locations;
	}
 
Example #15
Source File: TeiidDdlTextDocumentService.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
Example #16
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams arg0) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #17
Source File: CamelTextDocumentService.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	LOGGER.info("references: {}", params.getTextDocument());
	return new ReferencesProcessor(this, openedDocuments.get(params.getTextDocument().getUri())).getReferences(params.getPosition());
}
 
Example #18
Source File: TextDocumentService.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The references request is sent from the client to the server to resolve
 * project-wide references for the symbol denoted by the given text document
 * position.
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonRequest
default CompletableFuture<List<? extends Location>> references(ReferenceParams params) {
	throw new UnsupportedOperationException();
}