Language-server-protocol: MarkupContent in Hover lacks support for "regions"

Created on 11 Jul 2018  路  10Comments  路  Source: microsoft/language-server-protocol

(as discussed in https://github.com/Microsoft/vscode-languageserver-node/issues/328 and https://github.com/Microsoft/vscode-languageserver-node/issues/374)

When using MarkedString[] as a Hover's contents, a client can interpret this as different "regions" and format it accordingly, e.g. with a horizontal separator like VSCode does. However, MarkedString is deprecated, and this can't be communicated with MarkupContent. So effectively, one is forced to use deprecated API to achieve this formatting right now.

Perhaps MarkupContent[] could be allowed as a possible type for Hover.contents as well to remedy this.

feature-request help wanted

All 10 comments

As a workaround for this, I've been using MarkupContent with markdown and using \n\n---\n\n to put horizontal separators.

The problem is that that looks different (and not nearly as good in my opinion). See also the screenshots in https://github.com/Microsoft/vscode-languageserver-node/issues/374.

Yes, I see what you mean. And it definitely would make sense to be able to use MarkupContent[] just like MarkedString[] can be used.

I'm looking at adding LSP support to Dart and just hit this. In the built-in provider (which uses Dart's proprietary protocol) we return a section at the top that has the type info/deprecated note/etc. above the doc comment.

I'm curious what the other languages that use LSP do here (for ex. in TypeScript it seems to render like the Dart one does... does it use the deprecated types?)

This is a strange regression. Was this intentional? The native VS Code API still allows for this.

As far as I know, TypeScript uses the VSCode API directly, rather than the LSP:

Ah, that explains that. From what I can see, the Omnisharp implementation uses the older MarkedStrings which I think allow for arrays. I'll go back to them for now - probably it's more likely a client will support that than the newer types anyway.

I solved this by concatenating items into markdown, separated by horizontal rules (--- or <hr>): https://github.com/sourcegraph/lang-typescript/blob/8456bed0730557aea672ec727cb023979e489496/extension/src/lsp-conversion.ts#L55-L75

I modified the styles on Sourcegraph so that sections separated by horizontal rules look the same as multiple array items: https://github.com/sourcegraph/codeintellify/commit/2ab2bf62289fc0266b3772fe07aee9d82c1786e7

I fixed this by rendering a --- (e.g <hr> tag) as a semantic break in the VS Code UI. I am not a fan of supporting MarkedContent[]. Reason being is that we then needs to specify what it means when a array is received and how that should be rendered on the client side. Having only one element makes this a lot easier.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angelozerr picture angelozerr  路  6Comments

stamblerre picture stamblerre  路  5Comments

kittaakos picture kittaakos  路  4Comments

pajatopmr picture pajatopmr  路  3Comments

gorkem picture gorkem  路  6Comments