@@ -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 ._
@@ -346,9 +346,9 @@ class DottyLanguageServer extends LanguageServer
346346 else {
347347 import dotty .tools .dotc .core .Comments ._
348348 val symbol = Interactive .enclosingSourceSymbol(trees, pos)
349- val doc = ctx.docCtx.flatMap(_.docstring(symbol)).map(_.raw + " / " ).getOrElse( " " )
350- val str = tpw.show.toString
351- new Hover (List (JEither .forLeft(doc + str )).asJava, null )
349+ val docComment = ctx.docCtx.flatMap(_.docstring(symbol))
350+ val markedString = docMarkedString(docComment, tpw.show.toString)
351+ new Hover (List (JEither .forRight(markedString )).asJava, null )
352352 }
353353 }
354354
@@ -465,6 +465,21 @@ object DottyLanguageServer {
465465 item
466466 }
467467
468+ private def docMarkedString (comment : Option [Comment ], info : String ): lsp4j.MarkedString = {
469+
470+ val formattedComment = comment.map { comment =>
471+ s """ ```scala
472+ | ${comment.raw}
473+ |```
474+ | """ .stripMargin
475+ }.getOrElse(" " )
476+
477+ val markedString = new lsp4j.MarkedString ()
478+ markedString.setValue(formattedComment + info)
479+ markedString
480+ }
481+
482+
468483 /** Create an lsp4j.SymbolInfo from a Symbol and a SourcePosition */
469484 def symbolInfo (sym : Symbol , pos : SourcePosition )(implicit ctx : Context ): lsp4j.SymbolInformation = {
470485 def symbolKind (sym : Symbol )(implicit ctx : Context ): lsp4j.SymbolKind = {
0 commit comments