ionide / FsAutoComplete

F# language server using Language Server Protocol
Other
389 stars 151 forks source link

Format tooltips using client input #1254

Open ettomatic opened 3 months ago

ettomatic commented 3 months ago

Details

Format tFsAutoComplete should allow customising the rendering for different clients based on client capabilities or client names.

For exaple on Emacs the Eldoc functionlity does not allow to display the exammples section and show a link and a message: Open the documentation to see the truncated examples.

I've initially reported the effect of this issue on emacs-fsharp-mode https://github.com/fsharp/emacs-fsharp-mode/issues/339

Checklist

baronfel commented 3 months ago

From the linked issue:

What you're seeing is the result of a design decision to render minimal tooltips inline in favor of rendering something more full in the Info Panel display.

Unfortunately this display is only available on VSCode - what we should do is instead use the information that the client sends us during the Initialize LSP call to determine how we should format tooltips. This would allow us to customize the rendering for different clients based on client capabilities or client names.

@TheAngryByrd / @MangelMaxime any disagreement with this approach? I think ideally we could use some kind of ClientCapabilities structure instead of hardcoding to client names to make these kinds of decisions, but I'm not 100% sure what that would look like.

MangelMaxime commented 3 months ago

No disagreement with this approach.

I believe this is why we also have different CommentStyle:

https://github.com/fsharp/FsAutoComplete/blob/4bc676cc1e8659d9338d31d82d6244bcfcc55cc4/src/FsAutoComplete.Core/TipFormatter.fs#L715-L720

I suppose in the case of Emacs we should the client to say that it wants to use the Documentation style which doesn't have the truncated examples?

Or do we need to introduce a new style?

baronfel commented 3 months ago

I think if we are able to define our own ClientCapabilities you could imagine a setting specifically for which tooltip style to use


"tooltips": {
  "format": "Documentation" 
}

Or any of our other known styles, and we could default to a style that is more inclusive, then have Ionide specifically opt into the command-based style.

That way the behavior isn't tied to the client specifically, and maps to concepts already in our codebase on a forward-compatible way.

MangelMaxime commented 3 months ago

Yes, this is what I think too.

I am just unsure if we already have the style corresponding to:

and we could default to a style that is more inclusive

I also don't remember why I am adding the Open documentation link in 2 steps (format the tooltip and then generate text/link):

Could it be because of the match tooltipResult.SymbolInfo with?

https://github.com/fsharp/FsAutoComplete/blob/4bc676cc1e8659d9338d31d82d6244bcfcc55cc4/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs#L898-L924

Depending on the reason we could revisit:

 [<RequireQualifiedAccess>] 
 type FormatCommentStyle = 
   | Legacy 
   | FullEnhanced 
   | FullEnhancedWithOpenDocumentationLink // New case
   | SummaryOnly 
   | Documentation 

or in the client capabilities set SupportsInfoPanel which then would allow to generate the Open documentation thing and the info panel capabilities.