Skip to content

Commit

Permalink
improvement: Use inlay hints for worksheets
Browse files Browse the repository at this point in the history
Advantages:
- this would allow us to stop using a custom extension and support more editors such as Zed
- can reuse any new feature inlay hints add
- reevaluate on change? (or should we remove it?)

Disadvantages:
- no way to set color
- could mix with normal decorations

TODO:

- [ ] gather feedback
- [ ] fix tests
- [ ] check if we can remove other ways of publishing altogether
  • Loading branch information
tgodzik committed Nov 17, 2024
1 parent cfc7715 commit 8084e55
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ final class InlayHintResolveProvider(
token: CancelToken,
): Future[InlayHint] = {
scala.util.Try {
val data = inlayHint.getData().asInstanceOf[JsonArray]
getLabelParts(inlayHint).zip(parseData(data))
Option(inlayHint.getData()) match {
case Some(data: JsonArray) =>
resolve(
inlayHint,
getLabelParts(inlayHint).zip(parseData(data)),
path,
token,
)

case _ => Future.successful(inlayHint)
}
}.toEither match {
case Right(labelParts) =>
resolve(inlayHint, labelParts, path, token)
case Right(labelParts) => labelParts
case Left(error) =>
scribe.warn(s"Failed to resolve inlay hint: $error")
rc.unsanitized.create(report(inlayHint, path, error), ifVerbose = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ abstract class MetalsLspService(
new WorksheetProvider(
folder,
buffers,
trees,
buildTargets,
languageClient,
() => userConfig,
Expand All @@ -430,7 +431,7 @@ abstract class MetalsLspService(
worksheetPublisher,
compilations,
scalaVersionSelector,
clientConfig.initialConfig,
clientConfig,
)
)
}
Expand Down Expand Up @@ -1015,7 +1016,11 @@ abstract class MetalsLspService(
if (userConfig.areSyntheticsEnabled())
compilers.inlayHints(params, token)
else Future.successful(List.empty[l.InlayHint].asJava)
} yield hints
worksheet <- worksheetProvider.inlayHints(
params.getTextDocument().getUri().toAbsolutePath,
token,
)
} yield (hints.asScala ++ worksheet).asJava
}
}

Expand Down Expand Up @@ -1378,13 +1383,17 @@ abstract class MetalsLspService(
def copyWorksheetOutput(
worksheetPath: AbsolutePath
): CompletableFuture[Object] = {
val output = worksheetProvider.copyWorksheetOutput(worksheetPath)
if (output.nonEmpty) {
Future(output).asJavaObject
} else {
languageClient.showMessage(Messages.Worksheets.unableToExport)
Future.successful(()).asJavaObject
}
worksheetProvider
.copyWorksheetOutput(worksheetPath)
.map { output =>
if (output.nonEmpty) {
output
} else {
languageClient.showMessage(Messages.Worksheets.unableToExport)
()
}
}
.asJavaObject
}

def analyzeStackTrace(content: String): Option[ExecuteCommandParams] =
Expand Down
Loading

0 comments on commit 8084e55

Please sign in to comment.