uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Error updating text editor (copying lib resources) #1083

Closed fdodino closed 7 years ago

fdodino commented 7 years ago

If you rename a project, change display resolution, and sometimes when you rename a method, you get

image

It happens apparently if you need to copy or refresh a wollok library, that is cached now.

org.eclipse.xtext.resource.ClasspathUriResolutionException: classpath:/wollok/lang.wlk#//@elements.5
    at org.eclipse.xtext.resource.XtextResourceSet$1.normalize(XtextResourceSet.java:286)
    at org.eclipse.xtext.EcoreUtil2.getPlatformResourceOrNormalizedURI(EcoreUtil2.java:620)
    at org.eclipse.xtext.resource.impl.DefaultReferenceDescription.<init>(DefaultReferenceDescription.java:29)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.createReferenceDescription(DefaultResourceDescriptionStrategy.java:112)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.createReferenceDescriptions(DefaultResourceDescriptionStrategy.java:100)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription.computeReferenceDescriptions(DefaultResourceDescription.java:141)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription$2.get(DefaultResourceDescription.java:123)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription$2.get(DefaultResourceDescription.java:120)
    at org.eclipse.xtext.util.OnChangeEvictingCache.get(OnChangeEvictingCache.java:77)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription.getReferenceDescriptions(DefaultResourceDescription.java:120)
    at org.eclipse.xtext.resource.DescriptionUtils.collectOutgoingReferences(DescriptionUtils.java:29)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager.isAffected(DefaultResourceDescriptionManager.java:117)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport.isReparseRequired(DirtyStateEditorSupport.java:649)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob$1.exec(DirtyStateEditorSupport.java:161)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob$1.exec(DirtyStateEditorSupport.java:1)
    at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:91)
    at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.internalReadOnly(XtextDocument.java:520)
    at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.readOnly(XtextDocument.java:492)
    at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:133)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob.run(DirtyStateEditorSupport.java:146)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

org.eclipse.xtext.resource.ClasspathUriResolutionException: classpath:/wollok/lang.wlk#//@elements.5
    at org.eclipse.xtext.resource.XtextResourceSet$1.normalize(XtextResourceSet.java:286)
    at org.eclipse.xtext.EcoreUtil2.getPlatformResourceOrNormalizedURI(EcoreUtil2.java:620)
    at org.eclipse.xtext.resource.impl.DefaultReferenceDescription.<init>(DefaultReferenceDescription.java:29)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.createReferenceDescription(DefaultResourceDescriptionStrategy.java:112)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy.createReferenceDescriptions(DefaultResourceDescriptionStrategy.java:100)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription.computeReferenceDescriptions(DefaultResourceDescription.java:141)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription$2.get(DefaultResourceDescription.java:123)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription$2.get(DefaultResourceDescription.java:120)
    at org.eclipse.xtext.util.OnChangeEvictingCache.get(OnChangeEvictingCache.java:77)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescription.getReferenceDescriptions(DefaultResourceDescription.java:120)
    at org.eclipse.xtext.resource.DescriptionUtils.collectOutgoingReferences(DescriptionUtils.java:29)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager.isAffected(DefaultResourceDescriptionManager.java:117)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport.isReparseRequired(DirtyStateEditorSupport.java:649)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob$1.exec(DirtyStateEditorSupport.java:161)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob$1.exec(DirtyStateEditorSupport.java:1)
    at org.eclipse.xtext.resource.OutdatedStateManager.exec(OutdatedStateManager.java:91)
    at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.internalReadOnly(XtextDocument.java:520)
    at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.readOnly(XtextDocument.java:492)
    at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:133)
    at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob.run(DirtyStateEditorSupport.java:146)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
fdodino commented 7 years ago

Maybe related to https://github.com/eclipse/xtext-xtend/issues/166 (fixed in... 2.12)

I thought that I could add a subclass to DefaultRenameStrategy for applyDeclarationChange, but debugging show no breakpoint.

Problem occurs only when you keep open files of project renamed in editor. If you close them and reopen everything works fine

fdodino commented 7 years ago

So... after debugging for 1 hour, I came with this conclusion:

You rename a project, a file... so, you change context. Let's say you have a class A. Its parent is class Object. So cache resource triggers a linking process from editor. But, Object (element 5 in lang.wlk) fails when trying to get that URI in a deprecated project. If you had "project1" and you rename it to "project2", context still points to "project1":

JdtClasspathUriResolver class

    @Override
    public URI resolve(Object context, URI classpathUri) {
        if (!(context instanceof IJavaElement)) {
            throw new IllegalArgumentException("Context must implement IResource");
        }
        javaElement = (IJavaElement) context;  (1)
        try {
            if (ClasspathUriUtil.isClasspathUri(classpathUri)) {
                IJavaProject javaProject = javaElement.getJavaProject();
                URI result = findResourceInWorkspace(javaProject, classpathUri); (2)
                if (classpathUri.fragment() != null)
                    result = result.appendFragment(classpathUri.fragment());
                return result;
            }
        }
        catch (Exception exc) {
            throw new ClasspathUriResolutionException(exc);
        }
        return classpathUri;
    }

So, that's why context is a java element (1), but you can't find resource in workspace any more (2). So you get the same uri as result, and caller fails subsequently:

XtextResourceSet class

                    if (ClasspathUriUtil.isClasspathUri(uri)) {
                        URI result = XtextResourceSet.this.resolveClasspathURI(uri);
                        if (ClasspathUriUtil.isClasspathUri(result))
                            throw new ClasspathUriResolutionException(result);

What do you think @Juancete @npasserini @tesonep ?

fdodino commented 7 years ago

I think this could be a good clue: http://koehnlein.blogspot.com.ar/2011/06/rename-refactoring-in-xtext-20.html

Update: no, it is useful but for refactoring issues.

Currently the problem is in Rename resources, so Refactoring rename is not triggered. But a dev called Stephane has a good point here: https://www.eclipse.org/forums/index.php/t/1080002/