I'm creating an external language server in csharp using the language server protocol for a client in vscode.
In the language, there exist references to image files (pngs), and I would like to have an on-hover markdown tooltip that includes a preview of the image. When I embed a "spoof" image in the tooltip that points to some image on the web via an url, the image is loaded correctly. However when I try to use a reference to a local file it doesn't render the image.
I found this related question with the main difference being that my language server is not implemented in vscode/javascript.
Under the assumption that I must be pointing to the image incorrectly, I've tried absolute paths, paths from the workspace root, relative paths to the current file and some other things, but none seem to work.
The actual image currently exists both in /CardArt/SlowAndSteady.png
where /
is the vscode workspace root as well as SlowAndSteady.png
in the same folder as the file that the language server is providing the hover tooltip for.
When I make an explicit markdown file, and reference the image with those same paths, the image resolves fine. It is just the hover tooltips that don't display the image.
Is there anything I'm misunderstanding in how images in the tooltips are resolved, or is this a bug?
It seems like any local or unsafe urls are blocked in the markdown vscode tooltips.
I've found a workaround for the issue. Instead of providing the link to the image, you can encode the image into a base64 string, and directly embed it into the markdown. This way there is no reference to a local image that needs to be unsafely resolved.
This looks something like:
![image](data:image/png;base64,iVBORw0KGgoAAAAN... etc)
The catch is that the tooltips have a certain max length (I don't know the actual value) so the image must scaled down before converting to base64 if the image is too large for the tooltip.
I'm currently converting the images to 150x150px pngs, and it seems to fit consistently in the tooltip character limit.