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

Refactor Preview for WorkspaceEdit with needsConfirmation flag #953

Merged
merged 3 commits into from
Mar 26, 2024

Conversation

BoykoAlex
Copy link
Contributor

WorkspaceEdit has a map of change annotations where any change annotation is associated with edits from the workspace edit. If any of change annotations has needsConfirmation flag on then VSCode would bring up the refactor preview with annotated changes unchecked.

This PR proposes similar (but not the same, there are limitations) behaviour into Eclipse.
If there is at lease one change annotation that requires confirmation then refactor wizard is opened with the Preview page opened. All changes would be checked marked as I couldn't find how to control this piece. Another limitation is Eclipse text edits are in reverse order (they are applied in reverse order for a reason) but the preview doesn't allow to set the tree sorter on the preview tree.

@rubenporras @mickaelistria @martinlippert feedback, ideas are welcomed :-)

Copy link
Contributor

@rubenporras rubenporras left a comment

Choose a reason for hiding this comment

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

Hi Alex,
the PR makes sense to me. I looks good to me but I do not know the Refactoring API at all.
My only comments are just some minor improvements on the code structure. If @martinlippert or @mickaelistria don't have further comments I would be happy if we merge it

});

if (wsEdit.getChangeAnnotations() != null && wsEdit.getChangeAnnotations().values().stream().anyMatch(ca -> ca.getNeedsConfirmation())) {
Refactoring refactoring = new Refactoring() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we move lines 938-973 into runRefactorWizardOperation passing the change to that method instead of the wizard as now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, definitely!

}

};
if (Display.getCurrent() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency within this method, could we invert the condition on Display.getCurrent() in the new or the old code so that they use the same condition and the the if/else is in the same order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll create runOnUiThread(Runnable) in the UI class and use it here in both places

Copy link
Contributor

@mickaelistria mickaelistria left a comment

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 and it seems good overally,
I'm disappointed that there isn't a utility for that already in Platform, something like new ChangeRefactoringWizard(change), nor nothing alike (as far as I search it). So in absence of such a more straightforward API, this implementation seems to use the correct bits.
I support the overall comments about factorizing more stuff into the runRefactorWizardOperation.

Comment on lines 974 to 978
if (Display.getCurrent() == null) {
UI.getDisplay().asyncExec(() -> runRefactorWizardOperation(wizard, label));
} else {
runRefactorWizardOperation(wizard, label);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to put the UI thread check directly in runRefactorWizardOperation.

@mickaelistria
Copy link
Contributor

By the way, I'd like to add that if such a wizard taking a Change as input is useful to you in other places, you could consider creating such a wizard as an API directly in Platform, that would be welcome. We could keep this code in LSP4E until Platform provides a more generic API for it and then we adopt it.

@BoykoAlex
Copy link
Contributor Author

@rubenporras @mickaelistria Thank you both very much for the prompt review :-)
I have added a commit to address the review comments with a few more changes:

  1. Even if the workspace change is for one file that is opened in the editor in the case of needsConfirmation flag set to true we would still bring up the refactor preview. (I think this is rather obvious change)
  2. Added runOnUIThread(Runnable) to the UI class add used it in LSPEclipseUtils
  3. ServerMessageHandler use current active shell as the parent for MessageDialog instead of creating a new one - don't think you'd ever need to create a parent shell in Eclipse for a dialog. Creation of a new shell leaves its bounds undetermined the consequence of which is dialog box moves to bottom-right every time a new one is opened.

@rubenporras rubenporras merged commit 39d7594 into eclipse-lsp4e:master Mar 26, 2024
2 checks passed
@rubenporras
Copy link
Contributor

thank you

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.

3 participants