@@ -18,7 +18,7 @@ const (
1818 typeFormatFlags = checker .TypeFormatFlagsUseAliasDefinedOutsideCurrentScope
1919)
2020
21- func (l * LanguageService ) ProvideHover (ctx context.Context , documentURI lsproto.DocumentUri , position lsproto.Position ) (lsproto.HoverResponse , error ) {
21+ func (l * LanguageService ) ProvideHover (ctx context.Context , documentURI lsproto.DocumentUri , position lsproto.Position , contentFormat lsproto. MarkupKind ) (lsproto.HoverResponse , error ) {
2222 program , file := l .getProgramAndFile (documentURI )
2323 node := astnav .GetTouchingPropertyName (file , int (l .converters .LineAndCharacterToPosition (file , position )))
2424 if node .Kind == ast .KindSourceFile {
@@ -28,43 +28,57 @@ func (l *LanguageService) ProvideHover(ctx context.Context, documentURI lsproto.
2828 c , done := program .GetTypeCheckerForFile (ctx , file )
2929 defer done ()
3030 rangeNode := getNodeForQuickInfo (node )
31- quickInfo , documentation := l .getQuickInfoAndDocumentationForSymbol (c , c .GetSymbolAtLocation (node ), rangeNode )
31+ quickInfo , documentation := l .getQuickInfoAndDocumentationForSymbol (c , c .GetSymbolAtLocation (node ), rangeNode , contentFormat )
3232 if quickInfo == "" {
3333 return lsproto.HoverOrNull {}, nil
3434 }
3535 hoverRange := l .getLspRangeOfNode (rangeNode , nil , nil )
3636
37+ var content string
38+ if contentFormat == lsproto .MarkupKindMarkdown {
39+ content = formatQuickInfo (quickInfo ) + documentation
40+ } else {
41+ content = quickInfo + documentation
42+ }
43+
3744 return lsproto.HoverOrNull {
3845 Hover : & lsproto.Hover {
3946 Contents : lsproto.MarkupContentOrStringOrMarkedStringWithLanguageOrMarkedStrings {
4047 MarkupContent : & lsproto.MarkupContent {
41- Kind : lsproto . MarkupKindMarkdown ,
42- Value : formatQuickInfo ( quickInfo ) + documentation ,
48+ Kind : contentFormat ,
49+ Value : content ,
4350 },
4451 },
4552 Range : hoverRange ,
4653 },
4754 }, nil
4855}
4956
50- func (l * LanguageService ) getQuickInfoAndDocumentationForSymbol (c * checker.Checker , symbol * ast.Symbol , node * ast.Node ) (string , string ) {
57+ func (l * LanguageService ) getQuickInfoAndDocumentationForSymbol (c * checker.Checker , symbol * ast.Symbol , node * ast.Node , contentFormat lsproto. MarkupKind ) (string , string ) {
5158 quickInfo , declaration := getQuickInfoAndDeclarationAtLocation (c , symbol , node )
5259 if quickInfo == "" {
5360 return "" , ""
5461 }
62+ isMarkdown := contentFormat == lsproto .MarkupKindMarkdown
5563 var b strings.Builder
5664 if declaration != nil {
5765 if jsdoc := getJSDocOrTag (declaration ); jsdoc != nil && ! containsTypedefTag (jsdoc ) {
58- l .writeComments (& b , c , jsdoc .Comments ())
66+ l .writeComments (& b , c , jsdoc .Comments (), isMarkdown )
5967 if jsdoc .Kind == ast .KindJSDoc {
6068 if tags := jsdoc .AsJSDoc ().Tags ; tags != nil {
6169 for _ , tag := range tags .Nodes {
6270 if tag .Kind == ast .KindJSDocTypeTag {
6371 continue
6472 }
65- b .WriteString ("\n \n *@" )
66- b .WriteString (tag .TagName ().Text ())
67- b .WriteString ("*" )
73+ b .WriteString ("\n \n " )
74+ if isMarkdown {
75+ b .WriteString ("*@" )
76+ b .WriteString (tag .TagName ().Text ())
77+ b .WriteString ("*" )
78+ } else {
79+ b .WriteString ("@" )
80+ b .WriteString (tag .TagName ().Text ())
81+ }
6882 switch tag .Kind {
6983 case ast .KindJSDocParameterTag , ast .KindJSDocPropertyTag :
7084 writeOptionalEntityName (& b , tag .Name ())
@@ -90,7 +104,7 @@ func (l *LanguageService) getQuickInfoAndDocumentationForSymbol(c *checker.Check
90104 b .WriteString ("— " )
91105 }
92106 }
93- l .writeComments (& b , c , comments )
107+ l .writeComments (& b , c , comments , isMarkdown )
94108 }
95109 }
96110 }
@@ -425,24 +439,24 @@ func writeCode(b *strings.Builder, lang string, code string) {
425439 b .WriteByte ('\n' )
426440}
427441
428- func (l * LanguageService ) writeComments (b * strings.Builder , c * checker.Checker , comments []* ast.Node ) {
442+ func (l * LanguageService ) writeComments (b * strings.Builder , c * checker.Checker , comments []* ast.Node , isMarkdown bool ) {
429443 for _ , comment := range comments {
430444 switch comment .Kind {
431445 case ast .KindJSDocText :
432446 b .WriteString (comment .Text ())
433447 case ast .KindJSDocLink , ast .KindJSDocLinkPlain :
434- l .writeJSDocLink (b , c , comment , false /*quote*/ )
448+ l .writeJSDocLink (b , c , comment , false /*quote*/ , isMarkdown )
435449 case ast .KindJSDocLinkCode :
436- l .writeJSDocLink (b , c , comment , true /*quote*/ )
450+ l .writeJSDocLink (b , c , comment , true /*quote*/ , isMarkdown )
437451 }
438452 }
439453}
440454
441- func (l * LanguageService ) writeJSDocLink (b * strings.Builder , c * checker.Checker , link * ast.Node , quote bool ) {
455+ func (l * LanguageService ) writeJSDocLink (b * strings.Builder , c * checker.Checker , link * ast.Node , quote bool , isMarkdown bool ) {
442456 name := link .Name ()
443457 text := strings .Trim (link .Text (), " " )
444458 if name == nil {
445- writeQuotedString (b , text , quote )
459+ writeQuotedString (b , text , quote && isMarkdown )
446460 return
447461 }
448462 if ast .IsIdentifier (name ) && (name .Text () == "http" || name .Text () == "https" ) && strings .HasPrefix (text , "://" ) {
@@ -455,7 +469,16 @@ func (l *LanguageService) writeJSDocLink(b *strings.Builder, c *checker.Checker,
455469 linkText = linkUri
456470 }
457471 }
458- writeMarkdownLink (b , linkText , linkUri , quote )
472+ if isMarkdown {
473+ writeMarkdownLink (b , linkText , linkUri , quote )
474+ } else {
475+ writeQuotedString (b , linkText , false )
476+ if linkText != linkUri {
477+ b .WriteString (" (" )
478+ b .WriteString (linkUri )
479+ b .WriteString (")" )
480+ }
481+ }
459482 return
460483 }
461484 declarations := getDeclarationsFromLocation (c , name )
@@ -469,11 +492,15 @@ func (l *LanguageService) writeJSDocLink(b *strings.Builder, c *checker.Checker,
469492 if linkText == "" {
470493 linkText = getEntityNameString (name ) + text [:prefixLen ]
471494 }
472- linkUri := fmt .Sprintf ("%s#%d,%d-%d,%d" , loc .Uri , loc .Range .Start .Line + 1 , loc .Range .Start .Character + 1 , loc .Range .End .Line + 1 , loc .Range .End .Character + 1 )
473- writeMarkdownLink (b , linkText , linkUri , quote )
495+ if isMarkdown {
496+ linkUri := fmt .Sprintf ("%s#%d,%d-%d,%d" , loc .Uri , loc .Range .Start .Line + 1 , loc .Range .Start .Character + 1 , loc .Range .End .Line + 1 , loc .Range .End .Character + 1 )
497+ writeMarkdownLink (b , linkText , linkUri , quote )
498+ } else {
499+ writeQuotedString (b , linkText , false )
500+ }
474501 return
475502 }
476- writeQuotedString (b , getEntityNameString (name )+ " " + text , quote )
503+ writeQuotedString (b , getEntityNameString (name )+ " " + text , quote && isMarkdown )
477504}
478505
479506func trimCommentPrefix (text string ) string {
0 commit comments