Skip to content

Commit

Permalink
Merge branch 'main' into update-actionable-diagnostic-range
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceWarne committed Aug 5, 2023
2 parents 61363ee + f276070 commit d9f0b47
Show file tree
Hide file tree
Showing 58 changed files with 3,375 additions and 560 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.10"
version = "3.7.12"
runner.dialect = scala213
project.git = true
align.preset = none
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ lazy val metals = project
"io.undertow" % "undertow-core" % "2.2.20.Final",
"org.jboss.xnio" % "xnio-nio" % "3.8.9.Final",
// for persistent data like "dismissed notification"
"org.flywaydb" % "flyway-core" % "9.21.0",
"org.flywaydb" % "flyway-core" % "9.21.1",
"com.h2database" % "h2" % "2.1.214",
// for BSP
"org.scala-sbt.ipcsocket" % "ipcsocket" % "1.6.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class BuildServerConnection private (
if (isShuttingDown.compareAndSet(false, true)) {
conn.server.buildShutdown().get(2, TimeUnit.SECONDS)
conn.server.onBuildExit()
conn.livenessMonitor.shutdown()
scribe.info("Shut down connection with build server.")
// Cancel pending compilations on our side, this is not needed for Bloop.
cancel()
Expand Down Expand Up @@ -394,6 +395,11 @@ class BuildServerConnection private (
CancelTokens.future(_ => actionFuture)
}

def isBuildServerResponsive: Future[Boolean] = {
val original = connection
original.map(_.livenessMonitor.isBuildServerResponsive)
}

}

object BuildServerConnection {
Expand Down Expand Up @@ -422,13 +428,15 @@ object BuildServerConnection {
def setupServer(): Future[LauncherConnection] = {
connect().map { case conn @ SocketConnection(_, output, input, _, _) =>
val tracePrinter = Trace.setupTracePrinter("BSP", workspace)
val requestMonitor = new RequestMonitor
val launcher = new Launcher.Builder[MetalsBuildServer]()
.traceMessages(tracePrinter.orNull)
.setOutput(output)
.setInput(input)
.setLocalService(localClient)
.setRemoteInterface(classOf[MetalsBuildServer])
.setExecutorService(ec)
.wrapMessages(requestMonitor.wrapper(_))
.create()
val listening = launcher.startListening()
val server = launcher.getRemoteProxy
Expand All @@ -451,6 +459,14 @@ object BuildServerConnection {
stopListening,
result.getVersion(),
result.getCapabilities(),
new ServerLivenessMonitor(
requestMonitor,
server,
languageClient,
result.getDisplayName(),
config.metalsToIdleTime,
config.pingInterval,
),
)
}
}
Expand Down Expand Up @@ -541,6 +557,7 @@ object BuildServerConnection {
cancelServer: Cancelable,
version: String,
capabilities: BuildServerCapabilities,
livenessMonitor: ServerLivenessMonitor,
) {

def cancelables: List[Cancelable] =
Expand Down
26 changes: 22 additions & 4 deletions metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,12 @@ class Compilers(
// insert expression at the start of breakpoint's line and move the lines one down
val modified = s"$prev;$expressionText\n$indentation$succ"

val rangeEnd =
lineStart + expressionOffset(expressionText, indentation) + 1
val offsetParams = CompilerOffsetParams(
path.toURI,
modified,
lineStart + expressionOffset(expressionText, indentation) + 1,
rangeEnd,
token,
)

Expand Down Expand Up @@ -373,6 +375,12 @@ class Compilers(
toDebugCompletionItem(
_,
adjustStart,
Position.Range(
input.copy(value = modified),
// account for the added ;
lineStart + 1,
rangeEnd,
),
)
)
)
Expand Down Expand Up @@ -1132,14 +1140,24 @@ class Compilers(
private def toDebugCompletionItem(
item: CompletionItem,
adjustStart: Int,
insertTextPosition: Position,
): d.CompletionItem = {
val debugItem = new d.CompletionItem()
debugItem.setLabel(item.getLabel())
val (newText, range) = item.getTextEdit().asScala match {
case Left(textEdit) =>
val (newText, range) = Option(item.getTextEdit()).map(_.asScala) match {
case Some(Left(textEdit)) =>
(textEdit.getNewText, textEdit.getRange)
case Right(insertReplace) =>
case Some(Right(insertReplace)) =>
(insertReplace.getNewText, insertReplace.getReplace)
case None =>
Option(item.getInsertText()).orElse(Option(item.getLabel())) match {
case Some(text) =>
(text, insertTextPosition.toLsp)
case None =>
throw new RuntimeException(
"Completion item does not contain expected data"
)
}
}
val start = range.getStart().getCharacter + adjustStart

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ object Messages {
)

def moreInfo: String =
" Select 'More information' to learn how to fix this problem.."
" Select 'More information' to learn how to fix this problem."

def allProjectsMisconfigured: String =
"Navigation will not work for this build due to mis-configuration." + moreInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package scala.meta.internal.metals

import scala.concurrent.duration.Duration
import scala.util.Try

import scala.meta.internal.metals.Configs._
import scala.meta.internal.pc.PresentationCompilerConfigImpl
import scala.meta.pc.PresentationCompilerConfig.OverrideDefFormat
Expand Down Expand Up @@ -40,6 +43,8 @@ import scala.meta.pc.PresentationCompilerConfig.OverrideDefFormat
* @param macOsMaxWatchRoots The maximum number of root directories to watch on MacOS.
* @param maxLogFileSize The maximum size of the log file before it gets backed up and truncated.
* @param maxLogBackups The maximum number of backup log files.
* @param metalsToIdleTime The time that needs to pass with no action to consider metals as idle.
* @param pingInterval Interval in which we ping the build server.
*/
final case class MetalsServerConfig(
globSyntax: GlobSyntaxConfig = GlobSyntaxConfig.default,
Expand Down Expand Up @@ -102,6 +107,14 @@ final case class MetalsServerConfig(
.withFilter(_.forall(Character.isDigit(_)))
.map(_.toInt)
.getOrElse(10),
metalsToIdleTime: Duration =
Option(System.getProperty("metals.server-to-idle-time"))
.flatMap(opt => Try(Duration(opt)).toOption)
.getOrElse(Duration("10m")),
pingInterval: Duration =
Option(System.getProperty("metals.build-server-ping-interval"))
.flatMap(opt => Try(Duration(opt)).toOption)
.getOrElse(Duration("1m")),
) {
override def toString: String =
List[String](
Expand All @@ -122,6 +135,8 @@ final case class MetalsServerConfig(
s"loglevel=${loglevel}",
s"max-logfile-size=${maxLogFileSize}",
s"max-log-backup=${maxLogBackups}",
s"server-to-idle-time=${metalsToIdleTime}",
s"build-server-ping-interval=${pingInterval}",
).mkString("MetalsServerConfig(\n ", ",\n ", "\n)")
}
object MetalsServerConfig {
Expand Down
Loading

0 comments on commit d9f0b47

Please sign in to comment.