Skip to content

Commit

Permalink
Use absolute/relative paths more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
laughedelic committed Apr 12, 2018
1 parent ea5c625 commit d7eb533
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class MetalsServices(
path: AbsolutePath
)(fallback: => Unit): Unit = {
logger.info(s"File $path changed")
path.toNIO match {
path.toRelative(cwd) match {
case Semanticdbs.File() =>
fileSystemSemanticdbSubscriber.onNext(path)
case CompilerConfig.File() =>
Expand Down
5 changes: 3 additions & 2 deletions metals/src/main/scala/scala/meta/metals/Semanticdbs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import scala.tools.nsc.reporters.StoreReporter
import scala.util.control.NonFatal
import scala.{meta => m}
import com.typesafe.scalalogging.LazyLogging
import java.nio.file.Path
import org.langmeta.inputs.Input
import org.langmeta.internal.io.PathIO
import org.langmeta.internal.semanticdb.schema.Database
import org.langmeta.io.AbsolutePath
import org.langmeta.io.RelativePath

object Semanticdbs extends LazyLogging {

object File {
def unapply(path: Path): Boolean = PathIO.extension(path) == "semanticdb"
def unapply(path: RelativePath): Boolean =
PathIO.extension(path.toNIO) == "semanticdb"
}

def toSemanticdb(
Expand Down
9 changes: 4 additions & 5 deletions metals/src/main/scala/scala/meta/metals/Workspace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
import org.langmeta.internal.io.FileIO
import org.langmeta.io.AbsolutePath
import org.langmeta.io.RelativePath
import scala.meta.metals.compiler.CompilerConfig
import scala.meta.metals.sbtserver.SbtServer

object Workspace {

def compilerConfigFiles(cwd: AbsolutePath): Iterable[AbsolutePath] = {
val configDir = cwd.resolve(RelativePath(CompilerConfig.Directory))
val configDir = CompilerConfig.dir(cwd)
if (configDir.isDirectory) {
FileIO.listAllFilesRecursively(configDir)
} else {
Expand All @@ -34,9 +33,9 @@ object Workspace {
file: Path,
attrs: BasicFileAttributes
): FileVisitResult = {
file match {
case Semanticdbs.File() =>
action(AbsolutePath(file))
val absPath = AbsolutePath(file)
absPath.toRelative(cwd) match {
case Semanticdbs.File() => action(absPath)
case _ => // ignore, to avoid spamming console.
}
FileVisitResult.CONTINUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import java.util.Properties
import scala.tools.nsc.settings.ScalaVersion
import scala.tools.nsc.settings.SpecificScalaVersion
import com.typesafe.scalalogging.LazyLogging
import java.nio.file.Path
import org.langmeta.internal.io.PathIO
import org.langmeta.io.AbsolutePath
import org.langmeta.io.RelativePath
import scala.util.control.NonFatal

/**
Expand Down Expand Up @@ -58,12 +58,16 @@ case class CompilerConfig(
}

object CompilerConfig extends LazyLogging {
val Directory: Path = Paths.get(".metals").resolve("buildinfo")
private val relativeDir: RelativePath =
RelativePath(".metals").resolve("buildinfo")

def dir(cwd: AbsolutePath): AbsolutePath =
cwd.resolve(relativeDir)

object File {
def unapply(path: Path): Boolean = {
Files.exists(path) &&
path.getParent.getParent.endsWith(Directory) &&
PathIO.extension(path) == "properties"
def unapply(path: RelativePath): Boolean = {
path.toNIO.startsWith(relativeDir.toNIO) &&
PathIO.extension(path.toNIO) == "properties"
}
}

Expand Down

0 comments on commit d7eb533

Please sign in to comment.