Skip to content

Commit

Permalink
bugfix: Fix not hanging on ProjectDirs
Browse files Browse the repository at this point in the history
We were printing error to standard output which was interfering with LSP messages since metals.log was being set
  • Loading branch information
tgodzik committed Oct 22, 2024
1 parent 05363a5 commit 43684ec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ object BspServers {
def globalInstallDirectories(implicit
ec: ExecutionContext
): List[AbsolutePath] = {
val dirs = MetalsProjectDirectories.fromPath("bsp")
val dirs = MetalsProjectDirectories.fromPath("bsp", silent = false)
dirs match {
case Some(dirs) =>
List(dirs.dataLocalDir, dirs.dataDir).distinct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,12 @@ object BloopServers {

def createBloopWorkingDir(implicit ec: ExecutionContext): AbsolutePath = {

val baseDir = MetalsProjectDirectories.from(null, null, "ScalaCli") match {
val baseDir = MetalsProjectDirectories.from(
null,
null,
"ScalaCli",
silent = false,
) match {
case None =>
val userHome = Paths.get(System.getProperty("user.home"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,36 @@ import dev.dirs.ProjectDirectories

object MetalsProjectDirectories {

def from(qualifier: String, organization: String, application: String)(
implicit ec: ExecutionContext
def from(
qualifier: String,
organization: String,
application: String,
silent: Boolean,
)(implicit
ec: ExecutionContext
): Option[ProjectDirectories] =
wrap { () =>
wrap(silent) { () =>
ProjectDirectories.from(qualifier, organization, application)
}

def fromPath(path: String)(implicit
def fromPath(path: String, silent: Boolean)(implicit
ec: ExecutionContext
): Option[ProjectDirectories] =
wrap { () =>
wrap(silent) { () =>
ProjectDirectories.fromPath(path)
}

private def wrap(
private def wrap(silent: Boolean)(
f: () => ProjectDirectories
)(implicit ec: ExecutionContext): Option[ProjectDirectories] = {
Try {
val dirs = Future { f() }
Await.result(dirs, 10.seconds)

Await.result(dirs, 5.seconds)
} match {
case Failure(exception) =>
case Failure(exception) if !silent =>
scribe.error("Failed to get project directories", exception)
None
case Failure(exception) => None
case Success(value) => Some(value)
}
}
Expand Down
7 changes: 6 additions & 1 deletion metals/src/main/scala/scala/meta/internal/metals/Trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ object Trace {
def globalDirectory(implicit ec: ExecutionContext): Option[AbsolutePath] =
Try {
val projectDirectories =
MetalsProjectDirectories.from("org", "scalameta", "metals")
MetalsProjectDirectories.from(
"org",
"scalameta",
"metals",
silent = true,
) // we dont want to log anything before redirecting
// NOTE(olafur): strictly speaking we should use `dataDir` instead of `cacheDir` but on
// macOS this maps to `$HOME/Library/Application Support` which has an annoying space in
// the path making it difficult to tail/cat from the terminal and cmd+click from VS Code.
Expand Down

0 comments on commit 43684ec

Please sign in to comment.