Skip to content

Commit

Permalink
Use System.lineSeparator() as a linebreak character
Browse files Browse the repository at this point in the history
  • Loading branch information
vrubezhny committed Mar 3, 2023
1 parent 9278c6e commit 5294392
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.eclipse.lsp4j.jsonrpc.CancelChecker;

public class MavenNoGrammarConstraintsCodeAction implements ICodeActionParticipant {
public static final String XSI_VALUE = " xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" //$NON-NLS-1$
public static final String XSI_VALUE = " xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + System.lineSeparator() //$NON-NLS-1$
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\""; //$NON-NLS-1$

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Optional<List<Diagnostic>> validatePluginResolution(DiagnosticRequest dia
diagnosticRequest.getXMLDocument());
diagnostics.add(artifactDiagnosticReq.createDiagnostic(
"Plugin could not be resolved. Ensure the plugin's groupId, artifactId and version are present."
+ MarkdownUtils.LINE_BREAK + "Additional information: " + errorMessage,
+ MarkdownUtils.getLineBreak(true) + "Additional information: " + errorMessage,
DiagnosticSeverity.Warning));
});
if (!diagnostics.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import org.eclipse.lsp4j.Range;

public class MarkdownUtils {
public static final String LINE_BREAK = "\n\n";
public static final String NL = System.lineSeparator();
private static final String LINE_BREAK = NL + NL; // Needed for markdown

private MarkdownUtils() {}

public static String getLineBreak(boolean supportsMarkdown) {
return supportsMarkdown ? MarkdownUtils.LINE_BREAK : "\n";
return supportsMarkdown ? MarkdownUtils.LINE_BREAK : NL;
}

public static String toBold(String message) {
Expand All @@ -45,7 +46,7 @@ public static String htmlXMLToMarkdown(String description) {
description = description.substring(0, openPre);
xmlContent = xmlContent.replaceAll("&lt;", "<");
xmlContent = xmlContent.replaceAll("&gt;", ">");
xmlContent = "```XML" + "\n" + xmlContent + "\n" + "```";
xmlContent = "```XML" + "" + NL + xmlContent + NL + "```";
description = description + LINE_BREAK + xmlContent;
}
return description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.extensions.contentmodel.settings.ContentModelSettings;
import org.eclipse.lemminx.extensions.maven.NoMavenCentralExtension;
import org.eclipse.lemminx.extensions.maven.utils.MarkdownUtils;
import org.eclipse.lemminx.extensions.maven.utils.ParticipantUtils;
import org.eclipse.lemminx.services.XMLLanguageService;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -32,6 +33,8 @@
public class MavenPropertyHoverTest {
private XMLLanguageService languageService;

private static String NL = MarkdownUtils.getLineBreak(true);

@BeforeEach
public void setUp() throws IOException {
languageService = new XMLLanguageService();
Expand All @@ -50,12 +53,9 @@ public void testHpverForVariablePropertyDefinedInSameDocument()
String text = document.getText();
int offset = text.indexOf("${anotherProperty}") + "${".length();
text = text.substring(0, offset) + '|' + text.substring(offset);
String expectedHoverText = """
**Property:** anotherProperty
**Value:** $
**The property is defined in [org.test:child:0.0.1-SNAPSHOT](%s#L16,3-L16,39)**""";
String expectedHoverText = "**Property:** anotherProperty" + NL //
+ "**Value:** $" + NL //
+ "**The property is defined in [org.test:child:0.0.1-SNAPSHOT](%s#L16,3-L16,39)**";

ContentModelSettings settings = new ContentModelSettings();
settings.setUseCache(false);
Expand All @@ -71,12 +71,9 @@ public void testHpverForVariablePropertyDefinedInParentDocument()
String text = document.getText();
int offset = text.indexOf("${myProperty}") + "${".length();
text = text.substring(0, offset) + '|' + text.substring(offset);
String expectedHoverText = """
**Property:** myProperty
**Value:** $
**The property is defined in [org.test:test:0.0.1-SNAPSHOT](%s#L12,3-L12,29)**""";
String expectedHoverText = "**Property:** myProperty" + NL //
+ "**Value:** $" + NL //
+ "**The property is defined in [org.test:test:0.0.1-SNAPSHOT](%s#L12,3-L12,29)**";

File documentFile = new File(ParticipantUtils.normalizedUri(document.getDocumentURI()).getPath());
File expectedFile = new File(documentFile.getParent(), "pom-with-properties-for-definition.xml");
Expand Down

0 comments on commit 5294392

Please sign in to comment.