From 3cef32b1ca4231d660419cb00f55075127ea173f Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 16 Oct 2023 16:38:43 +0200 Subject: [PATCH] chore: Take into account charset --- .../meta/internal/metals/InteractiveSemanticdbs.scala | 4 +++- .../scala/meta/internal/metals/MetalsLspService.scala | 1 + .../meta/internal/mtags/ScalametaCommonEnrichments.scala | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala b/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala index bbd9cb2306e..fe8d9a78050 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/InteractiveSemanticdbs.scala @@ -1,5 +1,6 @@ package scala.meta.internal.metals +import java.nio.charset.Charset import java.util.Collections import java.util.concurrent.atomic.AtomicReference @@ -32,6 +33,7 @@ import org.eclipse.{lsp4j => l} final class InteractiveSemanticdbs( workspace: AbsolutePath, buildTargets: BuildTargets, + charset: Charset, client: MetalsLanguageClient, tables: Tables, statusBar: StatusBar, @@ -86,7 +88,7 @@ final class InteractiveSemanticdbs( source, (path, existingDoc) => { unsavedContents.orElse(buffers.get(source).orElse { - if (source.exists) Some(source.readText) + if (source.exists) Some(source.readText(charset)) else None }) match { case None => null diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index 7f621603b24..a98a9308318 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -359,6 +359,7 @@ class MetalsLspService( new InteractiveSemanticdbs( folder, buildTargets, + charset, languageClient, tables, statusBar, diff --git a/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala b/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala index 29968293341..42c53dd498f 100644 --- a/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala +++ b/mtags/src/main/scala/scala/meta/internal/mtags/ScalametaCommonEnrichments.scala @@ -1,6 +1,7 @@ package scala.meta.internal.mtags import java.net.URI +import java.nio.charset.Charset import java.nio.charset.StandardCharsets import java.nio.file.Files import java.nio.file.Path @@ -285,8 +286,12 @@ trait ScalametaCommonEnrichments extends CommonMtagsEnrichments { } } + def readText(charset: Charset): String = { + FileIO.slurp(path, charset) + } + def readText: String = { - FileIO.slurp(path, StandardCharsets.UTF_8) + readText(StandardCharsets.UTF_8) } def readTextOpt: Option[String] = {