autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

invalid value: integer `-2`, expected u64, breaks syntax error report #1147

Closed sim590 closed 3 years ago

sim590 commented 3 years ago

Describe the bug

Error on certain instances of valid code with Haskell files which breaks the syntax error report in Vim:

Error: invalid value: integer `-2`, expected u64

This happens when editing the following file:

module Tata (
) where

import System.Random

toto :: [a] -> IO [a]
toto as = do
  let (before, (a:after)) = splitAt 0 as
  return before

Environment

Steps to Reproduce and current behaviour

Steps to reproduce the behavior:

  1. Create a directory with the Cabal file (attached to this post) and the Haskell code snippet given above.
  2. Configure Vim to use the min-vimrc.vim configuration file (with the addition of Haskell configuration as mentioned before).
  3. Edit the Tata.hs file with Vim.
  4. Notice no errors in the file is reported (compile the code by yourself if you want to make sure).
  5. Have a look at the LanguageClient log file for the client and notice the following:

    Message: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"Redundant bracket","message":"Redundant bracket\nFound:\n  (before, (a : after))\nWhy not:\n  (before, a : after)\n","range":{"end":{"character":-2,"line":-2},"start":{"character":-2,"line":-2}},"severity":4,"source":"hlint"}],"uri":"file:///tmp/toto/Tata.hs"}}
    
    Error: invalid value: integer `-2`, expected u64

    The full log file is attached here.

While the error by itself doesn't indicate a bad behaviour, notice that when triggering an error by changing the following line:

toto :: [a] -> IO [a]

to for instance:

oto :: [a] -> IO [a]

will show the syntax error on the right. However, if when undoing the change with the u key (and saving the file), one can clearly see that the syntax error message doesn't go away on the right no matter how many times we write the file on the disk. Actually, the whole syntax error report is not listed in the location list (or quickfix list, depending on configuration), i.e. the syntax error report is not updated in Vim since the plugin seems to have abandoned to do so even though a syntax warning message was available according to the client log.

Message: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"Redundant bracket","message":"Redundant bracket\nFound:\n  (before, (a : after))\nWhy not:\n  (before, a : after)\n","range":{"end":{"character":-2,"line":-2},"start":{"character":-2,"line":-2}},"severity":4,"source":"hlint"}],"uri":"file:///tmp/toto/Tata.hs"}}

Expected behavior

The error message about the invalid integer should not happen and syntax errors should disappear when resolved in the file.

Additional context

The strange thing is that changing the source file to the following does go around the issue ...

toto :: [a] -> IO [a]
toto as = do
  let (before, (a)) = splitAt 0 as
  return before

It seems like the :list part of the expression is not liked by some linter. May be the issue is with the server, but I can't tell.

EDIT: Actually, it seems like simply removing the parentheses does the trick... i.e.:

toto :: [a] -> IO [a]
toto as = do
  let (before, a:after) = splitAt 0 as
  return before
martskins commented 3 years ago

I think this may be an issue with the server. The publishDiagnostics notification is sent from the server and the character and line values you get there should be greater or equal to zero, as it doesn't make sense for them to be anything else.

The spec even says that there are no special values like -1 to denote EOL or anything like that.

Position in a text document expressed as zero-based line and zero-based character offset. A position is between two characters like an ‘insert’ cursor in a editor. Special values like for example -1 to denote the end of a line are not supported.

martskins commented 3 years ago

Closing this as it seems to be stale and a server issue. Feel free to re-open if that's not the case.