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

Support Rename refactoring #9636

Merged
merged 1 commit into from
Jun 5, 2018
Merged

Support Rename refactoring #9636

merged 1 commit into from
Jun 5, 2018

Conversation

svor
Copy link
Contributor

@svor svor commented May 7, 2018

What does this PR do?

Make it possible to do Rename operation by using jdt.ls.
The result of this PR is here: https://youtu.be/HkCKpGSP05o

Depends on

What issues does this PR fix or reference?

#8939

@svor svor added kind/enhancement A feature request - must adhere to the feature request template. team/languages labels May 7, 2018
@svor svor self-assigned this May 7, 2018
@benoitf benoitf added target/branch Indicates that a PR will be merged into a branch other than master. status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. labels May 7, 2018
@svor svor changed the title [WIP]Support Rename refactoring Support Rename refactoring May 8, 2018
@svor svor requested review from tolusha and tsmaeder May 8, 2018 07:29
});
applyWorkspaceEditAction.applyWorkspaceEdit(edit);
view.close();
refactoringActionDelegate.closeWizard();
Copy link
Contributor

Choose a reason for hiding this comment

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

It invokes onCancelButtonClicked();
I think view.close() is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

view.close() closes just Preview window, but also we need to close the other one (Rename or Move) window which was opened previously

final JavaLanguageExtensionServiceClient service) {
eventBus.addHandler(
EditorOpenedEvent.TYPE,
new EditorOpenedEventHandler() {
@Override
public void onEditorOpened(EditorOpenedEvent event) {
String uri = buildHelper.getUri(event.getFile());
if (uri.endsWith(POM_FILE)) {
if (!uri.endsWith(POM_FILE)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's right

if (!arg.isPresent()) {
return;
}
File existedFile = arg.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

"existingFile"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
PreviewNode node = nodes.get(selectedNode.getUri());
List<TextEdit> edits = new ArrayList<>();
if (node.getId().equals(selectedNode.getId())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite sure what we are doing here. Refactor so it's obvious or add comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored and added some comments


private RefactorInfo refactorInfo;
private RefactoringSession session;
private Map<String, PreviewNode> nodes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all nodes in this map? If not, this needs a different name. fileNodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to fileNodes

this.refactoringActionDelegate = refactoringActionDelegate;
nodes = new LinkedHashMap<>();

prepareNodes(workspaceEdit);
Copy link
Contributor

Choose a reason for hiding this comment

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

As I see it, prepareNodes just fills in the nodes map. why not do
nodes= prepareNodes(workspaceEdit);
If you make prepareNodes static, you can show that there are no side-effects in the method. Making stuff side-effect free simplifies understanding the code.

}
undoChanges();
Copy link
Contributor

Choose a reason for hiding this comment

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

What?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you clarify please?
If you're thinking about why I undo changes here. It is because before applying all TextEdit changes we need to have initial state of the content where linked mode was activated.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that's what I was thinking of.

edit.setChanges(workspaceEdit.getChanges());
edit.setResourceChanges(new LinkedList<>());
for (ResourceChange resourceChange : workspaceEdit.getResourceChanges()) {
edit.getResourceChanges().add(Either.forLeft(resourceChange));
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity...I thought sending WorkspaceChange over the wire did not work? What has changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sending List<Either<ResourceChange, TextEdit>> which is described in org.eclipse.lsp4j.WorkspaceEdit doesn't work.
So here workspaceEdit is an instance of custom object (org.eclipse.che.jdt.ls.extension.api.dto.CheWorkspaceEdit) where I already have all actual changes and I take all changes from it and put them to the edit (org.eclipse.lsp4j.WorkspaceEdit) to sent it to class which applies org.eclipse.lsp4j.WorkspaceEdit (org.eclipse.che.plugin.languageserver.ide.editor.quickassist.ApplyWorkspaceEditAction#ApplyWorkspaceEditAction)

String newUri = change.getNewUri();
String current = change.getCurrent();

Path path = toPath(newUri).removeFirstSegments(1).makeAbsolute();
Copy link
Contributor

Choose a reason for hiding this comment

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

Transformation of file uri's to paths is usually done in WSMaster, so results from lsp servers contain either workspace paths of non-file URI's. See LanguageServiceUtils.removePrefixURI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GWT doesn't support java.net.* so we can't use LanguageServiceUtils.java on the client. I've created utility class org.eclipse.che.api.languageserver.util.URIUtil which transforms uri to path.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not what I mean, I've tried to explain in chat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

.getResource(path)
.then(
resource -> {
if (isNullOrEmpty(path.getFileExtension())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont' think this is a valid condition. It's perfectly valid to create files without extensions and folders with.

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, but I don't see another way to recognize which type of resource is here. Is it a folder or is a file.

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 we need to fix this in CheWorkspaceEdit (make CheResourceChange.java) and have a "resourceType" enum to be used on create.

resource
.move(path)
.then(
arg -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

arg is not a good name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

@tsmaeder tsmaeder force-pushed the 5730_java_ls_poc branch 2 times, most recently from 6901019 to 518f5f6 Compare June 4, 2018 09:34
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
@tsmaeder tsmaeder mentioned this pull request Jun 5, 2018
22 tasks
@svor svor merged commit 0558d31 into 5730_java_ls_poc Jun 5, 2018
@svor svor deleted the rename branch June 5, 2018 12:36
@benoitf benoitf removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Jun 5, 2018
tsmaeder pushed a commit that referenced this pull request Jun 13, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Jun 13, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
@tsmaeder tsmaeder mentioned this pull request Jun 18, 2018
26 tasks
tsmaeder pushed a commit that referenced this pull request Jun 26, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Jul 13, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Jul 27, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tolusha pushed a commit that referenced this pull request Aug 7, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Aug 22, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Aug 29, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tolusha pushed a commit that referenced this pull request Sep 5, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Sep 13, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Sep 20, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Sep 26, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 1, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 5, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 12, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 16, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 17, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 17, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 17, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 17, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
tsmaeder pushed a commit that referenced this pull request Oct 17, 2018
Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template. target/branch Indicates that a PR will be merged into a branch other than master.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants