Skip to content

Commit

Permalink
use utf-8 when formatting rescript file #398
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Jan 24, 2023
1 parent b7c4656 commit b4a981e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## Unreleased

- :bug: [#398](https://github.com/giraud/reasonml-idea-plugin/issues/398) Rescript format doesn’t respect UTF-8 encoding

## 0.109.1 - 2022/12/06

- :bug: [#392](https://github.com/giraud/reasonml-idea-plugin/issues/392) Attempting to open editorconfig causes IDE exception
Expand Down
2 changes: 1 addition & 1 deletion src/com/reason/comp/rescript/ResFormatProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String format(@NotNull VirtualFile sourceFile, boolean isInterface, @NotN
}

try (AutoDeletingTempFile tempFile = new AutoDeletingTempFile("fileToFormat", isInterface ? ".resi" : ".res")) {
tempFile.write(code);
tempFile.write(code, UTF8);

ProcessBuilder processBuilder = new ProcessBuilder(fmtBin.getPath(), "-format", tempFile.getPath());
Process fmt = null;
Expand Down
4 changes: 2 additions & 2 deletions src/com/reason/ide/annotations/ORErrorAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void cleanTempDirectory(@NotNull File directory, @NotNull String fileName
}
}

@Nullable static File copyToTempFile(@NotNull File tempCompilationDirectory, @NotNull PsiFile psiFile, @NotNull String nameWithoutExtension) {
static @Nullable File copyToTempFile(@NotNull File tempCompilationDirectory, @NotNull PsiFile psiFile, @NotNull String nameWithoutExtension) {
File sourceTempFile;

try {
Expand All @@ -216,7 +216,7 @@ static void cleanTempDirectory(@NotNull File directory, @NotNull String fileName

try {
String psiText = ReadAction.compute(psiFile::getText);
FileUtil.writeToFile(sourceTempFile, psiText.getBytes());
FileUtil.writeToFile(sourceTempFile, psiText.getBytes(Platform.UTF8));
} catch (IOException e) {
// Sometimes, file is locked by another process, not a big deal, skip it
LOG.trace("Write failed: " + e.getLocalizedMessage());
Expand Down
8 changes: 5 additions & 3 deletions src/jpsplugin/com/reason/AutoDeletingTempFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jetbrains.annotations.*;

import java.io.*;
import java.nio.charset.*;

public class AutoDeletingTempFile implements AutoCloseable {
private final File myFile;
Expand All @@ -17,11 +18,12 @@ public AutoDeletingTempFile(@NotNull String prefix, @NotNull String extension) t
return myFile.getPath();
}

public void write(@NotNull String text) throws IOException {
FileUtil.writeToFile(myFile, text.getBytes());
public void write(@NotNull String text, @NotNull Charset charset) throws IOException {
FileUtil.writeToFile(myFile, text, charset);
}

@Override public void close() {
@Override
public void close() {
FileUtilRt.delete(myFile);
}
}

0 comments on commit b4a981e

Please sign in to comment.