Search in sources :

Example 1 with ChangeConverter2

use of org.eclipse.xtext.ide.server.rename.ChangeConverter2 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);
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) WrappedException(org.eclipse.emf.common.util.WrappedException) XtextResource(org.eclipse.xtext.resource.XtextResource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) WrappedException(org.eclipse.emf.common.util.WrappedException) IChangeSerializer(org.eclipse.xtext.ide.serializer.IChangeSerializer) ChangeConverter2(org.eclipse.xtext.ide.server.rename.ChangeConverter2) EObjectAtOffsetHelper(org.eclipse.xtext.resource.EObjectAtOffsetHelper) EObject(org.eclipse.emf.ecore.EObject) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess)

Aggregations

URI (org.eclipse.emf.common.util.URI)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 EObject (org.eclipse.emf.ecore.EObject)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)1 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)1 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)1 ILanguageServerAccess (org.eclipse.xtext.ide.server.ILanguageServerAccess)1 ChangeConverter2 (org.eclipse.xtext.ide.server.rename.ChangeConverter2)1 EObjectAtOffsetHelper (org.eclipse.xtext.resource.EObjectAtOffsetHelper)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1