Skip to content

Commit

Permalink
Ensure that the plugin always uses \n. (#1069)
Browse files Browse the repository at this point in the history
closes #1042
  • Loading branch information
belav committed Dec 14, 2023
1 parent 5fcee11 commit 77b20b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Src/CSharpier.Rider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Rider/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ 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");

if (result.length() == 0 || currentDocumentText.equals(result)) {
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);
});
}
}
Expand Down

0 comments on commit 77b20b6

Please sign in to comment.