diff --git a/Src/CSharpier.Rider/CHANGELOG.md b/Src/CSharpier.Rider/CHANGELOG.md index 5475cd921..780b81338 100644 --- a/Src/CSharpier.Rider/CHANGELOG.md +++ b/Src/CSharpier.Rider/CHANGELOG.md @@ -2,6 +2,9 @@ # csharpier-rider Changelog +## [1.5.1] +- Ensure rider plugin always uses \n as a line separator + ## [1.5.0] - Improved error handling and reporting around csharpier failing to install or run diff --git a/Src/CSharpier.Rider/gradle.properties b/Src/CSharpier.Rider/gradle.properties index d07fe0c4b..63d362e6c 100644 --- a/Src/CSharpier.Rider/gradle.properties +++ b/Src/CSharpier.Rider/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = com.intellij.csharpier pluginName = csharpier -pluginVersion = 1.5.0 +pluginVersion = 1.5.1 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/FormattingService.java b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/FormattingService.java index 7da94d3e4..c19cd9caa 100644 --- a/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/FormattingService.java +++ b/Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/FormattingService.java @@ -56,6 +56,7 @@ public void format(@NotNull Document document, @NotNull Project project) { this.logger.info("Formatting started for " + filePath + "."); var start = Instant.now(); var result = cSharpierProcessProvider.getProcessFor(filePath).formatFile(currentDocumentText, filePath); + var end = Instant.now(); this.logger.info("Formatted in " + (Duration.between(start, end).toMillis()) + "ms"); @@ -63,8 +64,13 @@ public void format(@NotNull Document document, @NotNull Project project) { this.logger.debug("Skipping write because " + (result.length() == 0 ? "result is empty" : "current document equals result")); } else { WriteCommandAction.runWriteCommandAction(project, () -> { - // why replace instead of setText? - document.replaceString(0, currentDocumentText.length(), result); + var finalResult = result; + if (result.indexOf('\r') >= 0) { + // rider always wants \n in files so remove any \r + finalResult = result.replaceAll("\\r", ""); + } + + document.replaceString(0, currentDocumentText.length(), finalResult); }); } }