-
Notifications
You must be signed in to change notification settings - Fork 93
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
Improved namespace renaming for XML/XSD #403
Improved namespace renaming for XML/XSD #403
Conversation
e5740b6
to
cf1404c
Compare
cf1404c
to
25d9b55
Compare
...ipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/contentmodel/model/CMDocument.java
Outdated
Show resolved
Hide resolved
String documentation = child.getDocumentation(); | ||
if (documentation != null) { | ||
item.setDetail(documentation); | ||
StringBuilder sb = new StringBuilder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code should ne set here but on the cm document implementation. I suggest you that you create an abstractcmdocument class which provides the getfulldocumentation method. This abstract class could store the uri too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMDTDDocument is already extending a class, while CMXSDDocument is not.
CMDTDElementDeclaration is also extending a class, while CMXSDElementDeclaration is not.
Is there something I could do to avoid this problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your right @NikolasKomonen please forget my comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A another suggestion is to set the documentation code with source in a static method in XMLGenerator. Set the build of documentation with source will help more how this doc is built.
094e9a2
to
f0d9a81
Compare
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLHighlighting.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLHighlighting.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLHighlighting.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLHighlighting.java
Outdated
Show resolved
Hide resolved
import org.eclipse.lsp4xml.dom.parser.TokenType; | ||
|
||
/** | ||
* XMLRename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain more what is the goal of this class like rename namespaces and add @author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before for the Rename feature, it was using XMLHighlighting to get Highlights and then it turned them into TextEdits. Also Highlighting would only work for 1 Element (Start Tag and End Tag) but with XMLRename it will handle many elements with the same name, namespaces and maybe other renaming in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks for the clarification
/** | ||
* XMLRename | ||
*/ | ||
public class XMLRename { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XMLRename is too generic I think. Perhaps XMLRenameNamespace should be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think so? We have XMLFormatter, XMLHighlighting, XMLCompletions ...
This class will do all renaming, not only namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank's for the clarification, I understand more now. Please add the 2 rename features (rename tag element and rename namespaces by using ui, li in the javadoc)
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLLanguageService.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Outdated
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Outdated
Show resolved
Hide resolved
bc45fa5
to
8fc1179
Compare
@angelozerr Updated, moved the methods to DOMAttr. Implemented doRename() to follow the pattern for XMLLanguageService |
@@ -528,4 +535,39 @@ public static Range getElementDeclMissingContentOrCategory(int offset, DOMDocume | |||
return null; | |||
} | |||
|
|||
public static boolean doesTagCoverPosition(Range startTagRange, Range endTagRange, Position position) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add javadoc
|| endTagRange != null && covers(endTagRange, position); | ||
} | ||
|
||
public static boolean covers(Range range, Position position) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add javadoc
return isBeforeOrEqual(range.getStart(), position) && isBeforeOrEqual(position, range.getEnd()); | ||
} | ||
|
||
public static boolean isBeforeOrEqual(Position pos1, Position pos2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add javadoc
|| (pos1.getLine() == pos2.getLine() && pos1.getCharacter() <= pos2.getCharacter()); | ||
} | ||
|
||
public static Range getTagNameRange(TokenType tokenType, int startOffset, DOMDocument xmlDocument) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add javadoc
@@ -38,9 +38,9 @@ public void testFilesCachePathPreference() throws Exception { | |||
@Test | |||
public void normalizePathTest() { | |||
assertEquals(Paths.get(System.getProperty("user.home"), "Test", "Folder").toString(), FilesUtils.normalizePath("~/Test/Folder")); | |||
assertEquals(Paths.get(separator, "Test", "~", "Folder").toString(), FilesUtils.normalizePath("/Test/~/Folder")); | |||
assertEquals(Paths.get(separator + "Test", "~", "Folder").toString(), FilesUtils.normalizePath("/Test/~/Folder")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should belong to another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be, but there was a problem with git history in master. This will fix the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok no pb
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Show resolved
Hide resolved
org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/services/XMLRename.java
Show resolved
Hide resolved
@@ -10,6 +10,9 @@ | |||
*/ | |||
package org.eclipse.lsp4xml.dom; | |||
|
|||
import static org.eclipse.lsp4xml.dom.DOMAttr.XMLNS_ATTR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the XMLNS_ATTR constants as private and provide a static method DOMAttr#isXmlns(String attributeName) which can be used in DOMAttr#isXmlNs and in DOMElement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is hard to make it private, DOMElement needs this value: https://github.com/angelozerr/lsp4xml/blob/master/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DOMElement.java#L123
But I did changes and made static isXmlns(String) and other methods too.
@NikolasKomonen I played with your PR and it seems it works great I will continue to play with it again). The rename of namespace prefix is working when you do a rename to the xmlns: attribute (I mean xmlns of xmlns:qq): <aa:a xmlns:aa="aa.com" xmlns:qq="qq.com">
<aa:b></aa:b>
<aa:b></aa:b>
<aa:c />
<t type="aa:b" />
<qq:b></qq:b>
</aa:a> It should be very cool if we could rename the aa of an element (I mean <aa by an another name) |
Fixes eclipse-lemminx#366 Can rename namespace declaration and all will change, renaming element with namespace does not wipe namespace, attribute values referencing a namespace will update if necessary Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
8fc1179
to
c4459ba
Compare
Fixes #366
Can rename namespace declaration and all will change, renaming element with namespace does not wipe
namespace, attribute values referencing a namespace will update if necessary