Created
October 10, 2019 10:44
-
-
Save olafurpg/a5680c662fb68d5d925bc79df5c8f670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 3f09ac8e6c921586b4dc8949b25ce4759f064776 | |
Author: Olafur Pall Geirsson <lgeirsson@twitter.com> | |
Date: Thu Oct 10 12:44:44 2019 +0200 | |
Experiment with debugging breakpoints | |
diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala | |
index 4736d6e..04f9e28 100644 | |
--- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala | |
+++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProtocol.scala | |
@@ -6,10 +6,24 @@ import org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage | |
import org.eclipse.lsp4j.jsonrpc.messages.RequestMessage | |
import scala.util.Success | |
+import org.eclipse.lsp4j.debug.SetBreakpointsArguments | |
private[debug] object DebugProtocol { | |
import scala.meta.internal.metals.JsonParser._ | |
+ object SetBreakpoints { | |
+ def unapply(request: RequestMessage): Option[SetBreakpointsArguments] = { | |
+ if (request.getMethod != "setBreakpoints") None | |
+ else { | |
+ request.getParams match { | |
+ case json: JsonElement => | |
+ json.as[SetBreakpointsArguments].toOption | |
+ case _ => None | |
+ } | |
+ } | |
+ } | |
+ } | |
+ | |
object RestartRequest { | |
def unapply(request: RequestMessage): Option[RequestMessage] = { | |
if (request.getMethod != "disconnect") None | |
diff --git a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala | |
index e0e29a0..47bd260 100644 | |
--- a/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala | |
+++ b/metals/src/main/scala/scala/meta/internal/metals/debug/DebugProxy.scala | |
@@ -6,10 +6,14 @@ import org.eclipse.lsp4j.jsonrpc.MessageConsumer | |
import scala.concurrent.Promise | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
+import scala.meta.internal.tvp.EnclosingClasses | |
import scala.meta.internal.metals.Cancelable | |
import scala.meta.internal.metals.debug.DebugProtocol.OutputNotification | |
import scala.meta.internal.metals.debug.DebugProtocol.RestartRequest | |
import scala.meta.internal.metals.debug.DebugProxy._ | |
+import scala.meta.internal.metals.debug.DebugProtocol.SetBreakpoints | |
+import scala.meta.internal.metals.MetalsEnrichments._ | |
+import java.util.concurrent.CompletableFuture | |
private[debug] final class DebugProxy( | |
sessionName: String, | |
@@ -38,6 +42,18 @@ private[debug] final class DebugProxy( | |
private val handleClientMessage: MessageConsumer = { | |
case _ if cancelled.get() => | |
+ case params @ SetBreakpoints(message) => | |
+ for { | |
+ source <- message.getSource().getSources() | |
+ // _ = source. | |
+ input = source.getPath().toAbsolutePath.toInput | |
+ // pos = source.get | |
+ // occ <- EnclosingClasses.closestClass(input) | |
+ } { | |
+ // source.setAdapterData(occ.symbol) | |
+ } | |
+ // message.setSource() | |
+ server.consume(params) | |
// ignore | |
case RestartRequest(message) => | |
// set the status first, since the server can kill the connection | |
diff --git a/metals/src/main/scala/scala/meta/internal/tvp/EnclosingClasses.scala b/metals/src/main/scala/scala/meta/internal/tvp/EnclosingClasses.scala | |
new file mode 100644 | |
index 0000000..18e94a9 | |
--- /dev/null | |
+++ b/metals/src/main/scala/scala/meta/internal/tvp/EnclosingClasses.scala | |
@@ -0,0 +1,27 @@ | |
+package scala.meta.internal.tvp | |
+ | |
+import scala.meta.internal.semanticdb.SymbolOccurrence | |
+import scala.meta.inputs.Input | |
+import scala.meta.internal.mtags.Mtags | |
+import scala.meta.internal.semanticdb.Scala._ | |
+import org.eclipse.lsp4j.Position | |
+ | |
+object EnclosingClasses { | |
+ def closestClass( | |
+ input: Input.VirtualFile, | |
+ pos: Position | |
+ ): Option[SymbolOccurrence] = { | |
+ val occurrences = | |
+ Mtags.allToplevels(input).occurrences.filterNot(_.symbol.isPackage) | |
+ if (occurrences.isEmpty) None | |
+ else { | |
+ val closestSymbol = occurrences.minBy { occ => | |
+ val startLine = occ.range.fold(Int.MaxValue)(_.startLine) | |
+ val distance = math.abs(pos.getLine - startLine) | |
+ val isLeading = pos.getLine() > startLine | |
+ (!isLeading, distance) | |
+ } | |
+ Some(closestSymbol) | |
+ } | |
+ } | |
+} | |
diff --git a/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala b/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala | |
index 4d04482..fccdb7d 100644 | |
--- a/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala | |
+++ b/metals/src/main/scala/scala/meta/internal/tvp/MetalsTreeViewProvider.scala | |
@@ -254,14 +254,7 @@ class MetalsTreeViewProvider( | |
val input = path.toInput | |
val occurrences = | |
Mtags.allToplevels(input).occurrences.filterNot(_.symbol.isPackage) | |
- if (occurrences.isEmpty) None | |
- else { | |
- val closestSymbol = occurrences.minBy { occ => | |
- val startLine = occ.range.fold(Int.MaxValue)(_.startLine) | |
- val distance = math.abs(pos.getLine - startLine) | |
- val isLeading = pos.getLine() > startLine | |
- (!isLeading, distance) | |
- } | |
+ EnclosingClasses.closestClass(input, pos).flatMap { closestSymbol => | |
val result = | |
if (path.isDependencySource(workspace())) { | |
buildTargets | |
@@ -294,12 +287,11 @@ class MetalsTreeViewProvider( | |
for { | |
compilation <- compilations().get(id) | |
info <- buildTargets.info(id) | |
- } yield | |
- TreeViewNode( | |
- Compile, | |
- id.getUri, | |
- s"${info.getDisplayName()} - ${compilation.timer.toStringSeconds} (${compilation.progressPercentage}%)" | |
- ) | |
+ } yield TreeViewNode( | |
+ Compile, | |
+ id.getUri, | |
+ s"${info.getDisplayName()} - ${compilation.timer.toStringSeconds} (${compilation.progressPercentage}%)" | |
+ ) | |
} | |
private def ongoingCompilationNode: TreeViewNode = { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment