Skip to content

Type Signature on Hover is Truncated #4724

@emekoi

Description

@emekoi

Your environment

Which OS do you use?
Linux

Which version of GHC do you use and how did you install it?
GHC 9.10.1 via ghcup

How is your project built (alternative: link to the project)?
standalone file

Which LSP client (editor/plugin) do you use?
emacs+eglot

Which version of HLS do you use and how did you install it?
2.10.0.0 via ghcup

Have you configured HLS in any way (especially: a hie.yaml file)?
no

What's wrong?

The markup returned by the server for hover requests include line breaks for longer type signatures:

// request
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "textDocument/hover",
  "params": {
    "textDocument": {
      "uri": "file:///<path>/example.hs"
    },
    "position": {
      "line": 15,
      "character": 11
    }
  }
}

// response
{
  "id": 3,
  "jsonrpc": "2.0",
  "result": {
    "contents": {
      "kind": "markdown",
      "value": "\n```haskell\nfoldl' :: forall (t :: Type -> Type) b a.\nFoldable t =>\n(b -> a -> b) -> b -> t a -> b\n```\n\n*Defined in ‘GHC.Internal.Data.Foldable’* *(ghc-internal-9.1001.0)*\n\n* * *\nEvidence of constraint `Foldable []`\n  using an external instance\n  *Defined in ‘GHC.Internal.Data.Foldable’*\n* * *\n\n```haskell\n_ :: (Int -> Int -> Int) -> Int -> [Int] -> Int\n```\n* * *\n\n```haskell\n_ :: forall b a. (b -> a -> b) -> b -> [a] -> b\n```\n* * *\n\n```haskell\n_ :: forall (t :: Type -> Type) b a.\nFoldable t =>\n(b -> a -> b) -> b -> t a -> b\n```\n"
    },
    "range": {
      "end": {
        "character": 16,
        "line": 15
      },
      "start": {
        "character": 10,
        "line": 15
      }
    }
  }
}

This causes the type signatures to be truncated when shown in the echo area:

Image

and split across multiple lines in the doc buffer:

Image

Is there some way to tweak the formatting of information HLS is returning? Like changing the line wrapping behavior and suppressing the explicit foralls? Alternatively is there some LSP method to only report the type of the identifier at a point I could wrap to do what I want manually? (As an aside, why does HLS report the type 3 times?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions