Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of qualified names when renaming #531

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

toinehartman
Copy link
Contributor

@toinehartman toinehartman commented Nov 26, 2024

  • Support renaming fully qualified modules names (instead of last name segment only)
  • Reject renaming of modules from qualified declaration names.
  • Explicitly do not support external imports
  • Support module renames from explorer view.
  • Escape name segments (\syntax) and v.v.
  • Resolve module names via dependencies
  • Use 'did rename' instead of 'will rename' callback, to prevent problems in case the evaluator is locked
  • Add UI test for module move

@toinehartman toinehartman force-pushed the fix/rename-refactoring/module-names branch from 046df83 to 7b62cb2 Compare November 27, 2024 15:00
@toinehartman toinehartman force-pushed the fix/rename-refactoring/module-names branch from 63a2866 to 9f8d64b Compare December 2, 2024 11:50
@toinehartman toinehartman force-pushed the fix/rename-refactoring/module-names branch from ab74b9e to 2eb84b2 Compare December 4, 2024 15:17
@toinehartman toinehartman force-pushed the fix/rename-refactoring/module-names branch from 83be677 to 9dc8e7d Compare December 5, 2024 10:50
Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

Looks good, with some exceptions that I marked down.

@toinehartman toinehartman force-pushed the fix/rename-refactoring/module-names branch from 05284c1 to dd91729 Compare December 9, 2024 13:08
This works around a more generic solution of sharing evaluators beteen
the document and workspace services, whic is being tracked in #541.
@toinehartman toinehartman marked this pull request as ready for review December 10, 2024 14:00
Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

Some small changes, looks mostly fine 👍🏼

Copy link

sonarcloud bot commented Dec 12, 2024

Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

Looks good, 2 points that we should still pay attention to:

  1. the work inside the eval closure should really only call the evaluator, nothing more (just to avoid deadlocks), I've left a comment where it's happening.
  2. the test currently fails.

ISourceLocation newLoc = sourceLocationFromUri(rename.getNewUri());

ISourceLocation currentWsFolder = findContainingWorkspaceFolder(currentLoc, sortedWorkspaceFolders)
.orElseThrow(() -> new RuntimeException(String.format("Cannot automatically change uses of %s, since it is outside the current workspace.", currentLoc)));
Copy link
Member

Choose a reason for hiding this comment

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

nit: if we move this orElseThrow into the findContainingWorkspaceFolder we don't have to repeat it at the call site. (since it happens twice)

}

private static String readFile(ISourceLocation loc) {
URIResolverRegistry reg = URIResolverRegistry.getInstance();
Copy link
Member

Choose a reason for hiding this comment

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

nit: reg can be inlined.


return runEvaluator("Rascal module rename", semanticEvaluator, eval -> {
IFunction rascalGetPathConfig = eval.getFunctionValueFactory().function(getPathConfigType, (t, u) -> addResources(getPathConfig.apply((ISourceLocation) t[0])));
ISet qualifiedNameChanges = qualfiedNameChangesFromRenames(fileRenames, workspaceFolders, getPathConfig);
Copy link
Member

Choose a reason for hiding this comment

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

ideally we keep the work inside the eval lock as small as possible. especially since the qualifiedNameChangesFromRenames can end up callin maven (where there is some different locking happening in the latest version of rascal) we would hate to see a deadlock there.

So I would prefer if we can move this code to a completable future "before" this one, and only after that compose that to the runEvaluator closure.

}
})
.exceptionally(e -> {
client.showMessage(new MessageParams(MessageType.Error, e.getCause().getMessage()));
Copy link
Member

Choose a reason for hiding this comment

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

also add a logger.catching call to log the original error in case we want to debug it.

.stream()
.map(f -> Locations.toLoc(f.getUri()))
.collect(Collectors.toSet()), getExecuter())
.thenAccept(folders -> ((RascalTextDocumentService) docService).didRenameFiles(params, folders));
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think the .thenAccept should not be indented as a "sub" of the stream operator, but higher up. It think that the stream chain should be 2 levels of indentation, and then .thenAccept at 1 level of indentation.

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.

2 participants