haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Type Signature on Hover is Truncated

Open emekoi opened this issue 4 months ago • 2 comments

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?)

emekoi avatar Sep 08 '25 00:09 emekoi

Related: https://github.com/emacs-lsp/lsp-haskell/issues/151

emekoi avatar Sep 08 '25 03:09 emekoi

I think I found the "solution" to this "problem". Changing printOutputable to printOutputableOneLine in AtPoint.hs https://github.com/haskell/haskell-language-server/blob/9b952c849cfc9540b4a574c81c0236a9db4d650b/ghcide/src/Development/IDE/Spans/AtPoint.hs#L352 should print the type on a single line. Alternatively, we could just special case line 304 https://github.com/haskell/haskell-language-server/blob/9b952c849cfc9540b4a574c81c0236a9db4d650b/ghcide/src/Development/IDE/Spans/AtPoint.hs#L304 to use printOutputableOneLine so other types aren't affected if the splitting behavior is still desirable there.

EDIT:

Image

emekoi avatar Sep 09 '25 00:09 emekoi