@@ -19,7 +19,7 @@ import scala.io.Codec
1919import dotc ._
2020import ast .{Trees , tpd }
2121import core ._ , core .Decorators .{sourcePos => _ , _ }
22- import Contexts ._ , Flags ._ , Names ._ , NameOps ._ , Symbols ._ , SymDenotations ._ , Trees ._ , Types ._
22+ import Comments . Comment , Contexts ._ , Flags ._ , Names ._ , NameOps ._ , Symbols ._ , SymDenotations ._ , Trees ._ , Types ._
2323import classpath .ClassPathEntries
2424import reporting ._ , reporting .diagnostic .MessageContainer
2525import util ._
@@ -348,9 +348,9 @@ class DottyLanguageServer extends LanguageServer
348348 else {
349349 import dotty .tools .dotc .core .Comments ._
350350 val symbol = Interactive .enclosingSourceSymbol(trees, pos)
351- val doc = ctx.docCtx.flatMap(_.docstring(symbol)).map(_.raw + " / " ).getOrElse( " " )
352- val str = tpw.show.toString
353- new Hover (List (JEither .forLeft(doc + str )).asJava, null )
351+ val docComment = ctx.docCtx.flatMap(_.docstring(symbol))
352+ val markedString = docMarkedString(docComment, tpw.show.toString)
353+ new Hover (List (JEither .forRight(markedString )).asJava, null )
354354 }
355355 }
356356
@@ -467,6 +467,21 @@ object DottyLanguageServer {
467467 item
468468 }
469469
470+ private def docMarkedString (comment : Option [Comment ], info : String ): lsp4j.MarkedString = {
471+
472+ val formattedComment = comment.map { comment =>
473+ s """ ```scala
474+ | ${comment.raw}
475+ |```
476+ | """ .stripMargin
477+ }.getOrElse(" " )
478+
479+ val markedString = new lsp4j.MarkedString ()
480+ markedString.setValue(formattedComment + info)
481+ markedString
482+ }
483+
484+
470485 /** Create an lsp4j.SymbolInfo from a Symbol and a SourcePosition */
471486 def symbolInfo (sym : Symbol , pos : SourcePosition )(implicit ctx : Context ): lsp4j.SymbolInformation = {
472487 def symbolKind (sym : Symbol )(implicit ctx : Context ): lsp4j.SymbolKind = {
0 commit comments