diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java index 35db1da0bb..4b21dc8886 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java @@ -123,7 +123,7 @@ public void updateSettings(Object initializationOptionsSettings) { // Update format settings XMLFormattingOptions formatterSettings = clientSettings.getFormat(); if (formatterSettings != null) { - xmlTextDocumentService.setSharedFormattingOptions(formatterSettings); + xmlTextDocumentService.getSharedFormattingOptions().merge(formatterSettings); } CompletionSettings newCompletions = clientSettings.getCompletion(); diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DocumentType.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DocumentType.java index e41b699144..a00d7b43f5 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DocumentType.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/dom/DocumentType.java @@ -44,10 +44,8 @@ public int getEndContent() { return endContent; } - /* - * (non-Javadoc) - * - * @see org.w3c.dom.DocumentType#getName() + /** + * The text immediately after DOCTYPE, " // - this.putIfAbsent(entry.getKey(), entry.getValue()) // + formattingOptions.entrySet().stream().forEach(entry -> { + String key = entry.getKey(); + if(!key.equals("tabSize") && !key.equals("insertSpaces")) { + this.put(entry.getKey(), entry.getValue()); + } + else { + this.putIfAbsent(entry.getKey(), entry.getValue()); + } + } ); return this; } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java index 91642216f2..85a24737ff 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/XMLBuilder.java @@ -72,7 +72,10 @@ public XMLBuilder closeStartElement() { } public XMLBuilder endElement() { - xml.append(" />"); + if(formattingOptions.isSpaceBeforeEmptyCloseTag()) { + xml.append(" "); + } + xml.append("/>"); return this; } diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/XMLFormatterTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/XMLFormatterTest.java index a350861f68..e59e059181 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/XMLFormatterTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/services/XMLFormatterTest.java @@ -596,6 +596,36 @@ public void testContentFormatting6() throws BadLocationException { format(content, expected, formattingOptions); } + @Test public void testSelfCloseTagSpace() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setSpaceBeforeEmptyCloseTag(true); + + String content = + "\r" + // + " \r" + // + ""; + String expected = + "\r" + // + " \r" + // + ""; + format(content, expected, formattingOptions); + } + + @Test public void testSelfCloseTagSpaceFalse() throws BadLocationException { + XMLFormattingOptions formattingOptions = createDefaultFormattingOptions(); + formattingOptions.setSpaceBeforeEmptyCloseTag(false); + + String content = + "\r" + // + " \r" + // + ""; + String expected = + "\r" + // + " \r" + // + ""; + format(content, expected, formattingOptions); + } + //-------------------------Tools----------------------------------------- diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/SettingsTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/SettingsTest.java index bab6123112..4f4301bdfc 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/SettingsTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/SettingsTest.java @@ -50,7 +50,9 @@ public void initializationOptionsSettings() { " \"joinCDATALines\": true,\r\n" + // " \"formatComments\": true,\r\n" + // " \"joinCommentLines\": true\r\n" + // - " }\r\n" + " }\r\n" + "}"; + " }\r\n" + + " }\r\n" + + "}"; // Emulate InitializeParams#getInitializationOptions() object created as // JSONObject when XMLLanguageServer#initialize(InitializeParams params) is // called @@ -85,7 +87,7 @@ private static InitializeParams createInitializeParams(String json) { @Test public void formatSettings() { - XMLFormattingOptions sharedXMLFormattingOptions = new XMLFormattingOptions(); + XMLFormattingOptions sharedXMLFormattingOptions = new XMLFormattingOptions(true); sharedXMLFormattingOptions.setTabSize(10); sharedXMLFormattingOptions.setInsertSpaces(true); sharedXMLFormattingOptions.setJoinCommentLines(true); @@ -93,22 +95,23 @@ public void formatSettings() { // formatting options coming from request FormattingOptions formattingOptions = new FormattingOptions(); formattingOptions.setTabSize(5); + formattingOptions.setInsertSpaces(false); XMLFormattingOptions xmlFormattingOptions = new XMLFormattingOptions(formattingOptions); Assert.assertEquals(5, xmlFormattingOptions.getTabSize()); // value coming from the request formattingOptions Assert.assertFalse(xmlFormattingOptions.isInsertSpaces()); // formattingOptions doesn't defines insert spaces // flag - Assert.assertFalse(xmlFormattingOptions.isJoinCommentLines()); + Assert.assertFalse(xmlFormattingOptions.isJoinCommentLines());//Since default for JoinCommentLines is False // merge with shared sharedXMLFormattingOptions (formatting settings created in // the InitializeParams xmlFormattingOptions.merge(sharedXMLFormattingOptions); - Assert.assertEquals(5, xmlFormattingOptions.getTabSize()); // tab size is kept to 5 (and not updated with - // shared value 10), because request - // formattingOptions defines it. - Assert.assertTrue(xmlFormattingOptions.isInsertSpaces()); // insert spaces is to true (shared value), because - // request formatting options doesn't define it. + Assert.assertEquals(5, xmlFormattingOptions.getTabSize()); // tab size is kept as 5 (and not updated with + // shared value 10), because only the request's + // formattingOptions object is allowed to define it. + Assert.assertFalse(xmlFormattingOptions.isInsertSpaces()); // insert spaces is kept as false because only the request's + // formattingOptions object is allowed to define it. Assert.assertTrue(xmlFormattingOptions.isJoinCommentLines()); } } diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/capabilities/XMLCapabilitiesTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/capabilities/XMLCapabilitiesTest.java index 1f9564a6cc..6e2c21e10d 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/capabilities/XMLCapabilitiesTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/settings/capabilities/XMLCapabilitiesTest.java @@ -57,7 +57,7 @@ public class XMLCapabilitiesTest { @Before public void startup() { - XMLFormattingOptions formattingOptions = new XMLFormattingOptions(); + XMLFormattingOptions formattingOptions = new XMLFormattingOptions(true); formattingOptions.setEnabled(true); textDocumentService = new XMLTextDocumentService(null);