Skip to content

Commit

Permalink
Show inferred generic parameters in tooltips (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasily-kirichenko authored and auduchinok committed Apr 11, 2019
1 parent 3bc26b9 commit 4b500ab
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module JetBrains.ReSharper.Plugins.FSharp.Daemon.Stages.Tooltips

open System
open FSharp.Compiler.Layout
open FSharp.Compiler.SourceCodeServices
open JetBrains.DocumentModel
open JetBrains.ProjectModel
Expand Down Expand Up @@ -57,27 +58,30 @@ type FSharpIdentifierTooltipProvider(lifetime, solution, presenter, xmlDocServic
let lineText = sourceFile.Document.GetLineText(coords.Line)

// todo: provide tooltip for #r strings in fsx, should pass String tag
let getTooltip = checkResults.GetToolTipText(int coords.Line + 1, int coords.Column, lineText, names, FSharpTokenTag.Identifier)
let getTooltip = checkResults.GetStructuredToolTipText(int coords.Line + 1, int coords.Column, lineText, names, FSharpTokenTag.Identifier)
let result = ResizeArray()
match getTooltip.RunAsTask() with
| FSharpToolTipText(tooltips) ->
tooltips |> List.iter (function
| FSharpToolTipElement.None
| FSharpToolTipElement.CompositionError _ -> ()

| FSharpToolTipElement.Group(overloads) ->
overloads |> List.iter (fun overload ->
let text = overload.MainDescription.TrimStart()
match xmlDocService.GetXmlDoc(overload.XmlDoc) with
| null when not (text.IsNullOrWhitespace()) -> result.Add(text)
| xmlDocText ->

let xmlDocText = xmlDocText.Text
match text.IsNullOrWhitespace(), xmlDocText.IsNullOrWhitespace() with
| false, false -> result.Add(text + "\n\n" + xmlDocText)
| false, _ -> result.Add(text)
| _, false -> result.Add(xmlDocText)
| _ -> ()))
let (FSharpToolTipText layouts) = getTooltip.RunAsTask()

layouts |> List.iter (function
| FSharpStructuredToolTipElement.None
| FSharpStructuredToolTipElement.CompositionError _ -> ()

| FSharpStructuredToolTipElement.Group(overloads) ->
overloads |> List.iter (fun overload ->
[
if not (isEmptyL overload.MainDescription) then
yield showL overload.MainDescription

if not overload.TypeMapping.IsEmpty then
yield "Generic parameters:\n" + (overload.TypeMapping |> List.map showL |> String.concat "\n")

match xmlDocService.GetXmlDoc(overload.XmlDoc) with
| null -> ()
| xmlDocText when xmlDocText.Text.IsNullOrWhitespace() -> ()
| xmlDocText -> yield xmlDocText.Text
]
|> String.concat "\n\n"
|> result.Add))

result.Join(RiderTooltipSeparator)

Expand Down

0 comments on commit 4b500ab

Please sign in to comment.