Skip to content

Add Support for Breaking Down Type Signatures in Tooltips #1203

Description

@1eyewonder

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

  • I have looked through existing issues to make sure that this feature has not been requested before
  • I have provided a descriptive title for this issue
  • I am aware that even valid feature requests may be rejected if they do not align with the project's goals
  • I or my company would be willing to contribute this feature

Activity

  1. TheAngryByrd commented on Nov 15, 2023

    @TheAngryByrd
    Member

    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.

  2. 1eyewonder commented on Nov 15, 2023

    @1eyewonder
    ContributorAuthor

    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

  3. nojaf commented on Nov 16, 2023

    @nojaf
    Contributor

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

  4. TheAngryByrd commented on Nov 16, 2023

    @TheAngryByrd
    Member

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

  5. github-actions commented on Apr 4, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    Great feature request! Here's an updated look at what's needed, based on the current codebase.

    Current behaviour

    When you hover over addNumberFunc : AddNumberFunc, FSAC displays:

    val addNumberFunc: AddNumberFunc

    The format function in DocumentationFormatter.fs formats AddNumberFunc using typ.TypeDefinition.DisplayName (because the alias HasTypeDefinition = true), so it shows the alias name — not the expanded form.

    Why FCS changes aren't needed

    @TheAngryByrd is right that resolving deep alias chains is complex, but the underlying FCS API already has what's needed:

    • FSharpType.IsAbbreviation — true when the type is an abbreviation
    • FSharpType.AbbreviatedType — the next level of the abbreviation chain (may itself be an abbreviation)

    Recursive unwrapping is straightforward:

    let rec expandAlias (t: FSharpType) =
        if t.IsAbbreviation then expandAlias t.AbbreviatedType else t

    Implementation sketch

    The best place to add this is in DocumentationFormatter.getValSignature and DocumentationFormatter.getFuncSignatureWithIdent:

    1. After computing retType (e.g., "AddNumberFunc"), check if the underlying type is an abbreviation.
    2. Recursively unwrap to get the expanded form.
    3. If the expanded display differs from the alias display, append it as a comment line in the code block:
    val addNumberFunc: AddNumberFunc
        // = int -> IDbConnection -> int

    For SymbolUse.Val, check v.FullType.IsAbbreviation.
    For SymbolUse.Function and SymbolUse.ClosureOrNestedFunction, check func.ReturnParameter.Type.IsAbbreviation and/or func.FullType.IsAbbreviation for the non-curried case.

    Caveats

    • The expansion appears inside a fsharp code block in the hover tooltip, so // = ... renders as a code comment — looks natural.
    • Deeply nested aliases (e.g., type Bar = Foo where type Foo = int -> string) are handled by the recursive unwrap loop.
    • The feature should be gated on a config option (e.g., fsharp.tooltips.expandTypeAliases: bool, defaulting to false) to avoid surprising users who prefer concise tooltips.

    Repo Assist is looking into implementing this as a PR.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@4ea8c81959909f40373e2a5c2b7fdb54ea19e0a5
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions