ionide / FsAutoComplete

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

Add Support for Breaking Down Type Signatures in Tooltips #1203

Open 1eyewonder opened 7 months ago

1eyewonder commented 7 months ago

Details

Assuming we have the following code:

type GetNumberFromDb = IDbConnection -> int

let getNumberFromDb : GetNumberFromDb =
  fun conn -> 1

let addNumberFunc' (dbFunc : GetNumberFromDb) otherNumber conn =
  let number = dbFunc conn
  printfn "I got a number: %i" number
  number + otherNumber

type AddNumberFunc = int -> IDbConnection -> int

let addNumberFunc : AddNumberFunc =
  addNumberFunc' getNumberFromDb

let someHigherOrderFunction' (addNum : AddNumberFunc) num conn =
  addNum num conn
  // other logic here

type SomeHigherOrderFunction = int -> IDbConnection -> int

let someHigherOrderFunction : SomeHigherOrderFunction =
  someHigherOrderFunction' addNumberFunc

When hovering over function parameters with a type signature such as below image

You can see the tooltip shows us the alias of the type signature (AddNumberFunc). I would like to propose we add the ability for navigating the type signatures further so you don't have to leave your current spot in the code to read and understand the signature.

Ideas/Suggestions:

  1. Create a 'mathetical proof' style signature. We'd have to account for type aliases for primitive types and other sorts of F# magic. Depending on the size of the 'proof' placing this under the 'Open the documentation' section may prove better. Maybe adding configuration of some sorts as well?
    addNumberFunc : AddNumberFunc
    addNumberFunc : int -> IDbConnection -> int

If this is found to be a reasonable idea/suggestion, I'd be willing to help contribute. I would just need guidance on areas of the codebase to search and refactor

Checklist

TheAngryByrd commented 7 months ago

I agree this would be very nice to have but I think something like this should live in FSharp.Compiler.Service. If it's possible to prototype in FsAutocomplete, I'm for it but I get the feeling you'll hit some pain points and will have to push into FCS.

I also recall reading issues about this becoming extremely complicated as you can compound aliases:


type Fooer = string
type MyFoo = int -> int

type FooItAgain = MyFoo -> Task<Fooer>
type SlightlyDifferentFooIt = FooItAgain

I can't recall any direct issues about this from a quick search though.

1eyewonder commented 7 months ago

Sounds good. I'll bring it up over there and see how plausible it is. I agree the compounding will be fun to say the least

nojaf commented 7 months ago

Aren't tooltips in FSAC their own thing? I always thought you gents rolled your own thing for tooltips.

TheAngryByrd commented 7 months ago

I think it's all the backing needed for it, like getting aliases of aliases and such. Like there's a bug about them: https://github.com/ionide/ionide-vscode-fsharp/issues/1947