How to make LS tooltip windows "pretty" w/ colors

Currently my extension LS tooltip windows are lacking colors (see below). How are we supposed to pull in colors from the current editor theme?

If the language server returns the right type of hover contents, Nova can syntax highlight code in the tooltip:

https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#hover

There are a few ways to do it, either by making sure the content string is markdown with fenced code blocks annotated with the syntax, or like this…

LSP request:

{
  "jsonrpc": "2.0",
  "id": 442,
  "method": "textDocument\\/hover",
  "params": {
    "textDocument": {
      "uri": "file:\\/\\/[redacted]\\/foo.ts"
    },
    "position": {
      "line": 1,
      "character": 9
    }
  }
}

LSP response:

{
  "jsonrpc": "2.0",
  "id": 442,
  "result": {
    "contents": [
      {
        "language": "typescript",
        "value": "function foo(): void"
      },
      "Description."
    ],
    "range": {
      "start": {
        "line": 1,
        "character": 9
      },
      "end": {
        "line": 1,
        "character": 12
      }
    }
  }
}

Note that the Description. text isn’t displaying in the hover tooltip due to a Nova bug, see:

Welp, I wasn’t expecting this to be an LSP feature… Thanks a ton @jaydenseric !

1 Like