-
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
Insert final newline depending on lsp4j formatting settings #649
Conversation
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java
Outdated
Show resolved
Hide resolved
In my latest commit, the code now trims the final newline only if the lsp4j trimFinalNewlines option is true. With vscode-xml, the option is currently null, so Some tests are failing right now, partly because the current code does not trim final spaces. (I think the code should always trim final spaces? If yes, I will go ahead and implement that) For example, if
after formatting
|
And for cases where Like so: before formatting
before formatting
|
The latest commit makes the formatting settings/behaviour be more consistent with HTML's HTML's "preserve new lines" settings preserve newlines in between tags, therefore does not affect the newlines at the end of the document whatsoever. This PR implements that behaviour, the In HTML, there is no HTML setting to keep more than 1 newline at the end of the document after formatting. Either there are no newlines, or there are only one. To have this in vscode-xml, we should introduce a So as it stands right now, to keep consistency with HTML, I think it makes sense to always trim final lines at the end, and only add the newline if All of this is (with the exception of the vscode-xml preference, this would be handled in a PR in vscode-xml) implemented in the latest commit of this PR |
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLFormatter.java
Show resolved
Hide resolved
With this vscode-xml PR: redhat-developer/vscode-xml#248 the Because of this line: https://github.com/xorye/lsp4xml/blob/ea1669063effe5d842abcc11405b4613354c7179/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLFormattingOptions.java#L354 If the formatting options from the formatting request has the |
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java
Outdated
Show resolved
Hide resolved
org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLFormatterTest.java
Show resolved
Hide resolved
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLBuilder.java
Outdated
Show resolved
Hide resolved
@@ -168,7 +168,7 @@ public void formatSettings() { | |||
formattingOptions.setTabSize(5); | |||
formattingOptions.setInsertSpaces(false); | |||
|
|||
XMLFormattingOptions xmlFormattingOptions = new XMLFormattingOptions(formattingOptions); | |||
XMLFormattingOptions xmlFormattingOptions = new XMLFormattingOptions(formattingOptions, false); |
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 did this because since initializeDefaultSettings
calls super.setTabSize(DEFAULT_TAB_SIZE);
. When merging formattingOptions
, the tabSize
will not get updated because it has already been set: https://github.com/eclipse/lemminx/blob/55e92f3c0f51717787f2c3b161181dc2654c293d/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLFormattingOptions.java#L346-L356
Signed-off-by: David Kwon <[email protected]>
Great job @xorye ! Could you add a section which explains those 2 settings (bound with vscode-xml) in https://github.com/redhat-developer/vscode-xml/wiki/Formatting please |
First step to fix redhat-developer/vscode-xml#196
Signed-off-by: David Kwon [email protected]