Subject: Re: bug#73500: eglot: diagnostic location not always shown

From: João Távora <[email-masked]>
Date: Sat, 28 Sep 2024 22:18:00 +0100

On Sat, Sep 28, 2024 at 4:23 PM Federico Beffa <[email-masked]> wrote:
>
> The attached archive includes everything mentioned at the indicated
> link.  See the included `README.md` file for instructions on how to
> reproduce the bug (minimally).

Thanks.

>  assume you have running test benches with everything.

You assume wrong.  Eglot supports hundreds of servers.  I only have the
servers I work or worked with in the past.  "Supports foo server " means
solely that someone knowledgeable with foo tried it and reported good
results at some point, so they requested to add a server invocation to
eglot-server-programs.

Anyway, I couldn't reproduce your problem simply because the Main.hs
program you provided does not seem to produce any diagnostics, according
the haskell-language-server I installed in my system, which identifies
itself as

haskell-language-server version: 1.9.1.0 (GHC: 9.2.8) (PATH: /usr/bin/haskell-language-server)

I'm not a Haskell programmer, so I don't know if this makes sense to
you.

In the events log, the publishDiagonstics message is the following:

[jsonrpc] e[22:01:33.466] <-- textDocument/publishDiagnostics {
  "jsonrpc": "2.0",
  "method": "textDocument/publishDiagnostics",
  "params": {
    "diagnostics": [],
    "uri": "file:///home/capitaomorte/Downloads/bug73500/src/Main.hs",
    "version": 2
  }
}

Notice the empty JSON array.  However, when I change your Main.hs to
what is likely a nonsensical Haskell program:

    module Main where
     
    isAscending :: [Int] -> Bool
    isAscending [] = True
    isAscending [x] = x
    --                ^ this second 'x' _is_ underlined
    isAscending (x : y : ys) = x < y && isAscending (y : ys)
     
    main :: IO ()
    main = putStrLn "Hello, bug 73500!"

Then I see the second x being underlined with a 1-char-long diagnostic,
the corresponding LSP event being:

[jsonrpc] e[22:05:21.403] <-- textDocument/publishDiagnostics {
  "jsonrpc": "2.0",
  "method": "textDocument/publishDiagnostics",
  "params": {
    "diagnostics": [
      {
        "code": "-Wdeferred-type-errors",
        "message": "• Couldn't match expected type ‘Bool’ with actual type ‘Int’\n• In the expression: x\n  In an equation for ‘isAscending’: isAscending [x] = x",
        "range": {
          "end": {
            "character": 19,
            "line": 4
          },
          "start": {
            "character": 18,
            "line": 4
          }
        },
        "severity": 1,
        "source": "typecheck"
      }
    ],
    "uri": "file:///home/capitaomorte/Downloads/bug73500/src/Main.hs",
    "version": 25
  }
}

I have now removed haskell-language-server from my machine.
João