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

trimTrailingWhitespace option is not respected by textDocument/formatting #827

Closed
i-ky opened this issue Jul 20, 2020 · 3 comments · Fixed by #1000 or enxio/lsp4xml#119
Closed

trimTrailingWhitespace option is not respected by textDocument/formatting #827

i-ky opened this issue Jul 20, 2020 · 3 comments · Fixed by #1000 or enxio/lsp4xml#119
Assignees
Labels
bug Something isn't working formatting This issue or enhancement is related to formatting support
Milestone

Comments

@i-ky
Copy link

i-ky commented Jul 20, 2020

In short:

sending: {"params": {"textDocument": {"text": "<foo/>    \n\n", ...}}, "jsonrpc": "2.0", "method": "textDocument/didOpen"}
sending: {"params": {"textDocument": {"uri": "file:///tmp/test.xml"}, "options": {..., "trimTrailingWhitespace": false, ...}}, "jsonrpc": "2.0", "id": 1, "method": "textDocument/formatting"}
{u'jsonrpc': u'2.0', u'id': 1, u'result': [{u'newText': u'<foo/>\n', u'range': {u'start': {u'line': 0, u'character': 0}, u'end': {u'line': 2, u'character': 0}}}]}

Here is a full listings of communications (I'm using pylspclient in a Python script):

sending: {"params": {"processId": null, "initializationOptions": {"settings": {"xml": {"catalogs": [], "logs": {"client": true, "file": "/tmp/xml.log"}, "trace": {"server": "verbose"}}}}, "workspaceFolders": null, "trace": null, "rootUri": null, "rootPath": null, "capabilities": {}}, "jsonrpc": "2.0", "id": 0, "method": "initialize"}
Jul 20, 2020 4:30:21 PM org.eclipse.lemminx.XMLLanguageServer initialize
INFO: Initializing XML Language server
LemMinX Server info:
 - Version : 0.13.1
 - Java : /usr/lib/jvm/java-8-openjdk-amd64/jre
 - Git 3c6c0de - [maven-release-plugin] prepare release 0.13.1
Content-Length: 612

recieved message: {u'jsonrpc': u'2.0', u'id': 0, u'result': {u'capabilities': {u'renameProvider': True, u'foldingRangeProvider': True, u'typeDefinitionProvider': True, u'hoverProvider': True, u'definitionProvider': True, u'documentRangeFormattingProvider': True, u'codeLensProvider': {u'resolveProvider': False}, u'referencesProvider': True, u'documentLinkProvider': {u'resolveProvider': True}, u'textDocumentSync': 2, u'documentFormattingProvider': True, u'codeActionProvider': True, u'completionProvider': {u'triggerCharacters': [u'.', u':', u'<', u'"', u'=', u'/', u'\\', u'?', u"'", u'&'], u'resolveProvider': False}, u'documentSymbolProvider': True, u'documentHighlightProvider': True}}}
{u'jsonrpc': u'2.0', u'id': 0, u'result': {u'capabilities': {u'renameProvider': True, u'foldingRangeProvider': True, u'typeDefinitionProvider': True, u'hoverProvider': True, u'definitionProvider': True, u'documentRangeFormattingProvider': True, u'codeLensProvider': {u'resolveProvider': False}, u'referencesProvider': True, u'documentLinkProvider': {u'resolveProvider': True}, u'textDocumentSync': 2, u'documentFormattingProvider': True, u'codeActionProvider': True, u'completionProvider': {u'triggerCharacters': [u'.', u':', u'<', u'"', u'=', u'/', u'\\', u'?', u"'", u'&'], u'resolveProvider': False}, u'documentSymbolProvider': True, u'documentHighlightProvider': True}}}
{u'capabilities': {u'renameProvider': True, u'foldingRangeProvider': True, u'typeDefinitionProvider': True, u'hoverProvider': True, u'definitionProvider': True, u'documentRangeFormattingProvider': True, u'codeLensProvider': {u'resolveProvider': False}, u'referencesProvider': True, u'documentLinkProvider': {u'resolveProvider': True}, u'textDocumentSync': 2, u'documentFormattingProvider': True, u'codeActionProvider': True, u'completionProvider': {u'triggerCharacters': [u'.', u':', u'<', u'"', u'=', u'/', u'\\', u'?', u"'", u'&'], u'resolveProvider': False}, u'documentSymbolProvider': True, u'documentHighlightProvider': True}}
sending: {"params": {"textDocument": {"text": "<foo/>    \n\n", "version": 1, "uri": "file:///tmp/test.xml", "languageId": "xml"}}, "jsonrpc": "2.0", "method": "textDocument/didOpen"}
None
sending: {"params": {"textDocument": {"uri": "file:///tmp/test.xml"}, "options": {"preserveAttributeLineBreaks": true, "preservedNewlines": 5, "tabSize": 4, "trimTrailingWhitespace": false, "formatComments": false, "spaceBeforeEmptyCloseTag": false, "enabled": true, "insertSpaces": true, "preserveEmptyContent": true, "insertFinalNewline": true}}, "jsonrpc": "2.0", "id": 1, "method": "textDocument/formatting"}
Content-Length: 142

recieved message: {u'jsonrpc': u'2.0', u'id': 1, u'result': [{u'newText': u'<foo/>\n', u'range': {u'start': {u'line': 0, u'character': 0}, u'end': {u'line': 2, u'character': 0}}}]}
{u'jsonrpc': u'2.0', u'id': 1, u'result': [{u'newText': u'<foo/>\n', u'range': {u'start': {u'line': 0, u'character': 0}, u'end': {u'line': 2, u'character': 0}}}]}
Content-Length: 323

recieved message: {u'params': {u'uri': u'file:///tmp/test.xml', u'diagnostics': [{u'source': u'file:///tmp/test.xml', u'range': {u'start': {u'line': 0, u'character': 1}, u'end': {u'line': 0, u'character': 4}}, u'code': u'NoGrammarConstraints', u'message': u'No grammar constraints (DTD or XML Schema).', u'severity': 4}]}, u'jsonrpc': u'2.0', u'method': u'textDocument/publishDiagnostics'}
{u'params': {u'uri': u'file:///tmp/test.xml', u'diagnostics': [{u'source': u'file:///tmp/test.xml', u'range': {u'start': {u'line': 0, u'character': 1}, u'end': {u'line': 0, u'character': 4}}, u'code': u'NoGrammarConstraints', u'message': u'No grammar constraints (DTD or XML Schema).', u'severity': 4}]}, u'jsonrpc': u'2.0', u'method': u'textDocument/publishDiagnostics'}
sending: {"params": {}, "jsonrpc": "2.0", "id": 2, "method": "shutdown"}
Content-Length: 36

recieved message: {u'jsonrpc': u'2.0', u'id': 2, u'result': {}}
{u'jsonrpc': u'2.0', u'id': 2, u'result': {}}
{}
sending: {"params": {}, "jsonrpc": "2.0", "method": "exit"}
@datho7561 datho7561 added bug Something isn't working formatting This issue or enhancement is related to formatting support labels Jan 20, 2021
@datho7561 datho7561 self-assigned this Jan 21, 2021
@datho7561
Copy link
Contributor

datho7561 commented Mar 2, 2021

Hello,

In order to avoid the trailing newlines from being removed when formatting, please use xml.format.trimFinalNewlines = false.

If this addresses your issue, please let me know.

@datho7561 datho7561 added not a bug This is not a bug and works as intended and removed bug Something isn't working labels Mar 2, 2021
@i-ky
Copy link
Author

i-ky commented Mar 2, 2021

Hi @datho7561,

I don't really understand, how your suggestion is going to help, according to LSP Specification this is a completely different option:

Trim all newlines after the final newline at the end of the file.

vs.

Trim trailing whitespace on a line.

Note that my example shows space characters being trimmed despite "trimTrailingWhitespace": false.

I disagree with "not a bug" label.

@datho7561 datho7561 added bug Something isn't working and removed not a bug This is not a bug and works as intended labels Mar 3, 2021
@datho7561
Copy link
Contributor

Okay, sorry I missed the fact that the spaces were trimmed. I am able to reproduce it with unit tests, but not when running in VS Code. I'll do some more testing to figure out what's going on.

datho7561 added a commit to datho7561/lemminx that referenced this issue Mar 3, 2021
When `trimFinalNewlines = true`, the formatter removes `'\r'` and `'\n'`
from the end of the document instead of all whitespace.

Fixes eclipse#827

Signed-off-by: David Thompson <davthomp@redhat.com>
datho7561 added a commit that referenced this issue Mar 4, 2021
When `trimFinalNewlines = true`, the formatter removes `'\r'` and `'\n'`
from the end of the document instead of all whitespace.

Fixes #827

Signed-off-by: David Thompson <davthomp@redhat.com>
@angelozerr angelozerr added this to the 0.16.0 milestone Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatting This issue or enhancement is related to formatting support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants