forked from eclipse/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IRenameParticipant.doRename() is not conform with LSP-defined rename …
…result eclipse#1521
- Loading branch information
Showing
12 changed files
with
121 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* Copyright (c) 2019, 2023 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
|
@@ -11,6 +11,7 @@ | |
*******************************************************************************/ | ||
package org.eclipse.lemminx.services; | ||
|
||
import static org.eclipse.lemminx.utils.TextEditUtils.mergeOrAddTextEdits; | ||
import static org.eclipse.lemminx.utils.XMLPositionUtility.covers; | ||
import static org.eclipse.lemminx.utils.XMLPositionUtility.doesTagCoverPosition; | ||
import static org.eclipse.lemminx.utils.XMLPositionUtility.getTagNameRange; | ||
|
@@ -21,6 +22,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
@@ -38,16 +40,20 @@ | |
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.ResourceOperation; | ||
import org.eclipse.lsp4j.TextDocumentEdit; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.eclipse.lsp4j.VersionedTextDocumentIdentifier; | ||
import org.eclipse.lsp4j.WorkspaceEdit; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
|
||
/** | ||
* Handle all rename requests | ||
* | ||
* Author: Nikolas Komonen - [email protected] | ||
*/ | ||
public class XMLRename { | ||
class XMLRename { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(XMLRename.class.getName()); | ||
|
||
|
@@ -76,14 +82,14 @@ public WorkspaceEdit doRename(DOMDocument xmlDocument, Position position, String | |
if (node == null || (!node.isAttribute() && !node.isElement() && !node.isText()) | ||
|| (node.isElement() && !((DOMElement) node).hasTagName())) { | ||
|
||
return createWorkspaceEdit(xmlDocument.getDocumentURI(), Collections.emptyList()); | ||
cancelChecker.checkCanceled(); | ||
return createWorkspaceEdit(Collections.emptyList()); | ||
} | ||
|
||
List<TextEdit> textEdits = new ArrayList<>(); | ||
|
||
List<Either<TextDocumentEdit, ResourceOperation>> documentChanges = new ArrayList<>(); | ||
for (IRenameParticipant participant : extensionsRegistry.getRenameParticipants()) { | ||
try { | ||
participant.doRename(renameRequest, textEdits, cancelChecker); | ||
participant.doRename(renameRequest, documentChanges, cancelChecker); | ||
} catch (CancellationException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
|
@@ -93,13 +99,13 @@ public WorkspaceEdit doRename(DOMDocument xmlDocument, Position position, String | |
} | ||
} | ||
|
||
textEdits.addAll(getRenameTextEdits(xmlDocument, node, position, newText)); | ||
cancelChecker.checkCanceled(); | ||
mergeOrAddTextEdits(xmlDocument, getRenameTextEdits(xmlDocument, node, position, newText), documentChanges); | ||
|
||
cancelChecker.checkCanceled(); | ||
|
||
return createWorkspaceEdit(xmlDocument.getDocumentURI(), textEdits); | ||
return createWorkspaceEdit(documentChanges); | ||
} | ||
|
||
private List<TextEdit> getRenameTextEdits(DOMDocument xmlDocument, DOMNode node, Position position, | ||
String newText) { | ||
if (node == null || node.isText()) { | ||
|
@@ -279,6 +285,10 @@ private List<TextEdit> getXmlnsAttrRenameTextEdits(DOMDocument xmlDocument, DOME | |
return Collections.emptyList(); | ||
} | ||
|
||
private WorkspaceEdit createWorkspaceEdit(List<Either<TextDocumentEdit, ResourceOperation>> documentChanges) { | ||
return new WorkspaceEdit(documentChanges); | ||
} | ||
|
||
private WorkspaceEdit createWorkspaceEdit(String documentURI, List<TextEdit> textEdits) { | ||
Map<String, List<TextEdit>> changes = new HashMap<>(); | ||
changes.put(documentURI, textEdits); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.