use of org.eclipse.n4js.xtext.ide.server.ResourceTaskContext in project n4js by eclipse.
the class N4JSRenameService method rename.
// #################################################################################################################
// rename
//
// In case of #rename() we entirely replace the implementation from the super class by our own implementation (in
// order to reuse reference finding as far as possible, for consistency):
@Override
public WorkspaceEdit rename(Options options) {
RenameParams renameParams = options.getRenameParams();
CancelIndicator cancelIndicator = options.getCancelIndicator();
ResourceTaskContext rtc = resourceTaskManager.currentContext();
if (rtc == null || !rtc.isTemporary()) {
throw new IllegalStateException("N4JSRenameService#rename expects to be invoked within a temporary resource task context");
}
ResourceSet resourceSet = rtc.getResourceSet();
XtextResource resource = rtc.getResource();
XDocument document = rtc.getDocument();
int offset = document.getOffSet(renameParams.getPosition());
// in case the temporary resource task context we are using was created without 'resolveAndValidate' we need to
// trigger resolution (not validation) here:
EcoreUtil2.resolveLazyCrossReferences(resource, cancelIndicator);
EObject element = getElementToBeRenamed(resource, offset);
if (element == null) {
// empty edit
return new WorkspaceEdit();
}
WorkspaceEdit result = computeRenameEdits(resourceSet, element, renameParams.getNewName(), resourceTaskManager.createLiveScopeIndex(), cancelIndicator);
return result;
}
use of org.eclipse.n4js.xtext.ide.server.ResourceTaskContext in project n4js by eclipse.
the class XWorkspaceResourceAccess method readOnly.
@Override
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
// note: targetURI may point to an EObject inside an EMF resource!
URI uri = targetURI.trimFragment();
ResourceTaskContext currRTC = resourceTaskManager.currentContext();
if (currRTC != null) {
return doWork(currRTC.getResourceSet(), work, CancelIndicator.NullImpl);
}
// TODO consider making a current context mandatory by removing the following (see GH-1774):
CompletableFuture<R> future = resourceTaskManager.runInTemporaryContext(uri, "XWorkspaceResourceAccess", resolveAndValidate, (ofc, ci) -> doWork(ofc.getResourceSet(), work, ci));
return FutureUtil.getCancellableResult(future);
}
Aggregations