Skip to content

Commit

Permalink
Forward --debug option to BSP server
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou committed Aug 17, 2022
1 parent cc03392 commit 3328d99
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
7 changes: 3 additions & 4 deletions bsp/src/mill/bsp/BSP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ object BSP extends ExternalModule {
val bspFile = bspDirectory / s"${serverName}.json"
if (os.exists(bspFile)) T.log.info(s"Overwriting BSP connection file: ${bspFile}")
else T.log.info(s"Creating BSP connection file: ${bspFile}")
os.write.over(bspFile, createBspConnectionJson(jobs), createFolders = true)
os.write.over(bspFile, createBspConnectionJson(jobs, T.log.debugEnabled), createFolders = true)
}

// creates a Json with the BSP connection details
def createBspConnectionJson(jobs: Int): String = {
def createBspConnectionJson(jobs: Int, debug: Boolean): String = {
// we assume, the classpath is an executable jar here, FIXME
val millPath = sys.props
.get("java.class.path")
Expand All @@ -69,8 +69,7 @@ object BSP extends ExternalModule {
"false",
"--jobs",
s"${jobs}"
// s"${BSP.getClass.getCanonicalName.split("[$]").head}/start"
),
) ++ (if(debug) Seq("--debug") else Seq()),
millVersion = BuildInfo.millVersion,
bspVersion = bspProtocolVersion,
languages = languages
Expand Down
2 changes: 1 addition & 1 deletion main/api/src/mill/api/Logger.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.api

import java.io._
import java.io.{InputStream, PrintStream}

/**
* The standard logging interface of the Mill build tool.
Expand Down
4 changes: 3 additions & 1 deletion main/core/src/mill/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,10 @@ class Evaluator private[Evaluator] (
case Some(path) => MultiLogger(
logger.colored,
logger,
// we always enable debug here, to get some more context in log files
new FileLogger(logger.colored, path, debugEnabled = true),
logger.inStream
logger.inStream,
debugEnabled = logger.debugEnabled
)
}

Expand Down
35 changes: 32 additions & 3 deletions main/util/src/mill/util/Loggers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,13 @@ class MultiStream(stream1: OutputStream, stream2: OutputStream)
}
})

case class MultiLogger(colored: Boolean, logger1: Logger, logger2: Logger, inStream: InputStream)
extends Logger {
class MultiLogger(
override val colored: Boolean,
logger1: Logger,
logger2: Logger,
override val inStream: InputStream,
override val debugEnabled: Boolean
) extends Logger {

lazy val outputStream: PrintStream = new MultiStream(logger1.outputStream, logger2.outputStream)

Expand Down Expand Up @@ -264,8 +269,32 @@ case class MultiLogger(colored: Boolean, logger1: Logger, logger2: Logger, inStr
logger1.close()
logger2.close()
}
}

override def debugEnabled: Boolean = logger1.debugEnabled || logger2.debugEnabled
object MultiLogger {

def apply(
colored: Boolean,
logger1: Logger,
logger2: Logger,
inStream: InputStream,
debugEnabled: Boolean
): MultiLogger =
new MultiLogger(colored, logger1, logger2, inStream, debugEnabled)

def apply(
colored: Boolean,
logger1: Logger,
logger2: Logger,
inStream: InputStream
): MultiLogger =
MultiLogger(
colored,
logger1,
logger2,
inStream,
debugEnabled = logger1.debugEnabled || logger2.debugEnabled
)
}

/**
Expand Down

0 comments on commit 3328d99

Please sign in to comment.