use of org.eclipse.xtext.resource.EObjectAtOffsetHelper in project n4js by eclipse.
the class TestDiscoveryUIUtils method getSelectedElement.
private static EObject getSelectedElement(final XtextEditor editor, final ITextSelection textSelection) {
return editor.getDocument().modify(resource -> {
final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
final EObjectAtOffsetHelper offsetHelper = serviceProvider.get(EObjectAtOffsetHelper.class);
return offsetHelper.resolveElementAt(resource, textSelection.getOffset());
});
}
use of org.eclipse.xtext.resource.EObjectAtOffsetHelper in project xtext-core by eclipse.
the class DiagnosticResolution method apply.
public WorkspaceEdit apply() {
DiagnosticModificationContext modificationContext = factory.createModificationContext();
try {
XtextResource resource = options.getResource();
URI uri = resource.getURI();
ILanguageServerAccess access = options.getLanguageServerAccess();
WorkspaceEdit edit = new WorkspaceEdit();
ChangeConverter2 changeConverter = modificationContext.getConverterFactory().create(edit, access);
ResourceSet resourceSet = access.newLiveScopeResourceSet(uri);
XtextResource tmpResource = (XtextResource) resourceSet.getResource(uri, true);
CodeActionParams params = options.getCodeActionParams();
int offset = options.getDocument().getOffSet(params.getRange().getStart());
EObjectAtOffsetHelper helper = new EObjectAtOffsetHelper();
EObject obj = helper.resolveContainedElementAt(tmpResource, offset);
IChangeSerializer serializer = modificationContext.getSerializer();
serializer.addModification(obj, modification);
serializer.applyModifications(changeConverter);
return edit;
} catch (Exception exc) {
throw new WrappedException(exc);
}
}
Aggregations