Skip to content

Commit 36b543a

Browse files
committed
Ensure that the plugin always uses \n. (#1069)
closes #1042
1 parent f73c2c2 commit 36b543a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Src/CSharpier.Rider/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# csharpier-rider Changelog
44

5+
## [1.5.1]
6+
- Ensure rider plugin always uses \n as a line separator
7+
58
## [1.5.0]
69
- Improved error handling and reporting around csharpier failing to install or run
710

Src/CSharpier.Rider/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pluginGroup = com.intellij.csharpier
55
pluginName = csharpier
6-
pluginVersion = 1.5.0
6+
pluginVersion = 1.5.1
77

88
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
99
# for insight into build numbers and IntelliJ Platform versions.

Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/FormattingService.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,21 @@ public void format(@NotNull Document document, @NotNull Project project) {
5656
this.logger.info("Formatting started for " + filePath + ".");
5757
var start = Instant.now();
5858
var result = cSharpierProcessProvider.getProcessFor(filePath).formatFile(currentDocumentText, filePath);
59+
5960
var end = Instant.now();
6061
this.logger.info("Formatted in " + (Duration.between(start, end).toMillis()) + "ms");
6162

6263
if (result.length() == 0 || currentDocumentText.equals(result)) {
6364
this.logger.debug("Skipping write because " + (result.length() == 0 ? "result is empty" : "current document equals result"));
6465
} else {
6566
WriteCommandAction.runWriteCommandAction(project, () -> {
66-
// why replace instead of setText?
67-
document.replaceString(0, currentDocumentText.length(), result);
67+
var finalResult = result;
68+
if (result.indexOf('\r') >= 0) {
69+
// rider always wants \n in files so remove any \r
70+
finalResult = result.replaceAll("\\r", "");
71+
}
72+
73+
document.replaceString(0, currentDocumentText.length(), finalResult);
6874
});
6975
}
7076
}

0 commit comments

Comments
 (0)