Skip to content

Use destination URI when creating resource during copy refactoring#3588

Open
mx990 wants to merge 2 commits intoeclipse-xtext:mainfrom
mx990:refactoring-copy-uri-fix
Open

Use destination URI when creating resource during copy refactoring#3588
mx990 wants to merge 2 commits intoeclipse-xtext:mainfrom
mx990:refactoring-copy-uri-fix

Conversation

@mx990
Copy link
Copy Markdown
Contributor

@mx990 mx990 commented Jan 26, 2026

When performing a COPY refactoring, the ResourceRelocationContext created the resource with the original URI and then changed the URI of the resource after loading. This left any proxy URIs in the loaded resource still pointing to the original file. When later resolving the proxies, a second resource for the original file was created on demand and any local references were resolved into that resource and not the copy.

This avoids the problem by creating the resource with the destination URI instead, so that any proxies will be created with the correct URI.

Fixes #3587

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 26, 2026

Test Results

  8 050 files   -  22    8 050 suites   - 22   3h 48m 6s ⏱️ - 20m 46s
 43 246 tests +  5   42 661 ✅ +  5    584 💤 ±0  1 ❌ ±0 
212 337 runs   - 148  209 416 ✅  - 150  2 920 💤 +2  1 ❌ ±0 

For more details on these failures, see this check.

Results for commit 5a9216d. ± Comparison against base commit 088392b.

♻️ This comment has been updated with latest results.

@cdietrich
Copy link
Copy Markdown
Contributor

Wonder if this can somehow be tested

@LorenzoBettini
Copy link
Copy Markdown
Contributor

@mx990 just for confirmation: are the added tests FAIL without your patch?
Just to be sure tests are effective.

@mx990
Copy link
Copy Markdown
Contributor Author

mx990 commented Jan 27, 2026

Yes, (most of) the added tests fail without my patch when running them locally against main.

@mx990 mx990 force-pushed the refactoring-copy-uri-fix branch from a69c9c0 to d083cf6 Compare January 27, 2026 15:11
@mx990 mx990 force-pushed the refactoring-copy-uri-fix branch from d083cf6 to f871b91 Compare January 29, 2026 20:02
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.ICopyPolicy;
import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgDestinationFactory;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm internal imports ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely dep in manifest also missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm internal imports ...

There is, unfortunetaly, no generic copy processor for resources, so the test currently uses internal classes from JDT for that purpose. I could also create a mock copy processor to avoid the internal imports?

Likely dep in manifest also missing.

I have added the missing dependency for org.eclipse.jdt.core.manipulation in the manifest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szarnekow @LorenzoBettini i really dislike the new big bunch of internal deps but also have no better idea
for a more isolated tests we seem to miss a ton of infra in ide.tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tests it might acceptable. Otherwise, he suggested to use a mock avoiding the internal stuff

*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ui.tests.refactoring;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this could me moved to ide tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to move the following related classes to org.eclipse.xtext.ide.tests:

  • AbstractResourceRelocationTest,
  • ProgressReportingTest,
  • ResourceCopyTest,
  • ResourceMoveTest,
  • ResourceRenameTest,

but this would require the following additional dependencies:

  • org.eclipse.core.resources,
  • org.eclipse.jdt.core,
  • org.eclipse.jdt.core.manipulation,
  • org.eclipse.ltk.core.refactoring,
  • org.eclipse.xtext.testlanguages.ui,
  • org.eclipse.xtext.ui.testing.

Would you still like me to move the classes and add the additional dependencies?

Copy link
Copy Markdown
Contributor

@cdietrich cdietrich Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought based on a lsp test or xtext.ide.tests this could be done without any of these dependencies....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(e.g. renameTestLanguage)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick look at the lsp server implementation and Xtext does not seem to support any copy resource refactoring via lsp, since it handles neither willCreateFiles nor didCreateFiles from org.eclipse.lsp4j.services.WorkspaceService?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm. thats bad. is there really no way to avoid the new internal deps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I could also create a mock copy processor to avoid the internal deps?

mx990 added 2 commits March 18, 2026 20:52
When performing a COPY refactoring, the ResourceRelocationContext
created the resource with the original URI and then changed the URI of
the resource after loading. This left any proxy URIs in the loaded
resource still pointing to the original file. When later resolving the
proxies, a second resource for the original file was created on demand
and any local references were resolved into that resource and not the
copy.

This avoids the problem by creating the resource with the destination
URI instead, so that any proxies will be created with the correct URI.
This adds tests for the copy resource refactoring based on the Java
copy processor.
@mx990 mx990 force-pushed the refactoring-copy-uri-fix branch from f871b91 to 5a9216d Compare March 18, 2026 20:32
@cdietrich
Copy link
Copy Markdown
Contributor

can you also rebase your pr

@mx990
Copy link
Copy Markdown
Contributor Author

mx990 commented Mar 19, 2026

can you also rebase your pr

it is already on top of current main 088392b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale proxy URIs after changing resource URI during copy refactoring

3 participants