Markdown string for Hover (textDocument/hover) in Visual Studio

Sajith 66 Reputation points
2025-11-12T17:18:42.74+00:00

Iam working on an extension in Visual Studio that implements a Language Server (LSP) and support Hover (textDocument/hover) on some keywords in editor.

Markdown string returned for Hover request does not work in my case.

Does Visual Studio support markdown string as hover text?

Developer technologies | Visual Studio | Extensions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Gade Harika (INFOSYS LIMITED) 2,020 Reputation points Microsoft External Staff
    2025-11-13T11:09:23.1+00:00

    Thanks for reaching out,
    Visual Studio’s LSP client currently renders hover content as plain text only and does not support Markdown in textDocument/hover. During initialize, the client advertises hover.contentFormat: ["plaintext"]. This is by design today and is tracked as a feature request in Developer Community.

    What to do now:

    Return a single MarkupContent with Kind = PlainText and pre‑format your message for readability (bullets, ASCII tables). For richer content, provide a Code Action or command to open external documentation.

    using Microsoft.VisualStudio.LanguageServer.Protocol;
    
    [JsonRpcMethod(Methods.TextDocumentHoverName)]
    public Hover OnHover(JToken arg)
    {
        var contents = new MarkupContent
        {
            Kind = MarkupKind.PlainText,
            Value =
                "MyKeyword\n" +
                "Summary: Does something useful.\n\n" +
                "Details:\n" +
                "- Input: string name\n" +
                           "- Output: int id\n\n" +
                "Notes:\n" +
                "Use with care in performance-critical paths."
        };
    
        return new Hover { Contents = contents };
    
    

    References:


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.