Skip to content

Neovim Autocomplete with HLS >= 2.1.0.0 throws error #3842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CiaraMar opened this issue Oct 14, 2023 · 10 comments
Closed

Neovim Autocomplete with HLS >= 2.1.0.0 throws error #3842

CiaraMar opened this issue Oct 14, 2023 · 10 comments
Assignees
Labels
type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@CiaraMar
Copy link

Your environment

Which OS do you use?
Arch Linux
Which version of GHC do you use and how did you install it?
9.0.2 ghcup
How is your project built (alternative: link to the project)?
cabal

Which LSP client (editor/plugin) do you use?
Neovim + haskell-tools + nvim_coq
(All latest)
Which version of HLS do you use and how did you install it?
Version 2.1.0.0 (Though I've tried all the way up to 2.4.0.0)
Version 2.0.0.1 does work for me
Installed via ghcup
Have you configured HLS in any way (especially: a hie.yaml file)?
no

Steps to reproduce

cabal init
cabal build
nvim app/Main.hs

wait for server to load

type in fm and wait for fmap to show up
tab to the "fmap" that has "LSP" on the side
(see pics below) for more

Expected behaviour

It should complete or show various info on it
2023-10-13-185958_1054x1055_escrotum

Actual behaviour

When hovering over on autocomplete of a name, and the name has "LSP" on the side it pops up a window with an error.
This does not occur if on the right side it is a "BUF" based suggestion.
2023-10-13-190118_1057x1058_escrotum

Debug information

HLS log
2023-10-13T23:42:21.023882Z | Error | LSP: incoming message parse error:
Error in $.params.insertTextMode: parsing Integer failed, expected Number, but encountered Null
when processing
{"method":"completionItem/resolve","params":{"label":"spark#","detail":"from GHC.Base","sortText":"05","data":null,"insertTextMode":null,"insertTextFormat":1,"documentation":{"kind":"markdown","value":"Defined in 'GHC.Base'\n"},"command":{"arguments":[{"doc":"file:///home/maeve/projects/haskell/algorithm-design/app/Main.hs","importName":"GHC.Base","newThing":"spark#"}],"command":"404320:ghcide-extend-import-action:extendImport","title":"extend import"},"kind":3},"id":6,"jsonrpc":"2.0"}

I believe it might have something to do with the insertTextMode in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Completer/Simple.hs

insertTestMode Specification (Might be wrong version for nvim):
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#insertTextMode

Error seems to refer to the text mode not being an integer or number as expected in the specification above.

@CiaraMar CiaraMar added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Oct 14, 2023
@fendor
Copy link
Collaborator

fendor commented Oct 14, 2023

Hi, thank you for your bug report!

Maybe @joyfulmantis knows what this is about.

@joyfulmantis joyfulmantis self-assigned this Oct 18, 2023
@expipiplus1
Copy link
Contributor

expipiplus1 commented Oct 27, 2023

Edit: Ah, this might not be what I'm describing (which looks identical to this: #3535 (comment))


This might be the same as what I'm seeing also in nvim (with coc.nvim). The provenance and docs for symbols are only shown (and updated) for already imported symbols. So if I start typeing getCon then I just see all of text/bytestring/prelude's getContents but indistinguishable because no docs or whatever.

Here's a snipped from the log, many such messages repeated.

2023-10-27T20:19:50.501 ERROR (pid:2643853) [completion-floating] - Error on resolve complete item from languageserver.haskell: {
  command: {
    arguments: [ �[36m[Object]�[39m ],
    command: �[32m'2643883:ghcide-extend-import-action:extendImport'�[39m,
    title: �[32m'extend import'�[39m
  },
  detail: �[32m'from Data.Traversable'�[39m,
  documentation: { kind: �[32m'markdown'�[39m, value: �[32m"*Defined in 'Data.Traversable'*\n"�[39m },
  insertText: �[32m'fmapDefault'�[39m,
  insertTextFormat: �[33m2�[39m,
  kind: �[33m3�[39m,
  label: �[32m'fmapDefault'�[39m,
  sortText: �[32m'01'�[39m
} Dg [Error]: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
    at it (/nix/store/hihqsxbr7sjgmphbfdk3c9bkxjqhx9vx-vimplugin-coc.nvim-2023-09-30/build/index.js:27:234)
    at zn (/nix/store/hihqsxbr7sjgmphbfdk3c9bkxjqhx9vx-vimplugin-coc.nvim-2023-09-30/build/index.js:26:7395)
    at uo (/nix/store/hihqsxbr7sjgmphbfdk3c9bkxjqhx9vx-vimplugin-coc.nvim-2023-09-30/build/index.js:26:7518)
    at Immediate.<anonymous> (/nix/store/hihqsxbr7sjgmphbfdk3c9bkxjqhx9vx-vimplugin-coc.nvim-2023-09-30/build/index.js:26:7282)
�[90m    at process.processImmediate (node:internal/timers:476:21)�[39m {
  code: �[33m-32601�[39m,
  data: �[90mundefined�[39m
}

and from the server log (same thing more or less)

[Error - 20:19:50.501] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 

And the full session log:

Details
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 2.3.0.0 x86_64 ghc-9.4.7
Current directory: /home/e/work/spirv2gml
Operating system: linux
Arguments: ["--lsp"]
Cradle directory: /home/e/work/spirv2gml
Cradle type: Cabal

Tool versions found on the $PATH
cabal:          3.10.1.0
stack:          Not found
ghc:            9.4.7


Consulting the cradle to get project GHC version...
2023-10-27T12:22:48.012630Z | Debug | executing command: cabal exec -v0 -- ghc --print-libdir
2023-10-27T12:22:48.090578Z | Debug | executing command: cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2023-10-27T12:22:48.218891Z | Debug | executing command: cabal --builddir=/home/e/.cache/hie-bios/dist-spirv2gml-b1f42fe85ce43519cc33e59d54172f32 v2-exec --with-compiler /home/e/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/e/.cache/hie-bios/ghc-pkg-e283fb0c87704ad639a18c882466fb77 ghc -v0 -- --numeric-version
Project GHC version: 9.4.7
haskell-language-server exe candidates: ["haskell-language-server-9.4.7","haskell-language-server"]
Launching haskell-language-server exe at:/nix/store/wwyzhgdrz6sk13kcx4sywj149s08cg6k-haskell-language-server-2.3.0.0/bin/haskell-language-server-9.4.7
2023-10-27T12:22:48.298038Z | Debug | executing command: cabal exec -v0 -- ghc --print-libdir
2023-10-27T12:22:48.365223Z | Debug | executing command: cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2023-10-27T12:22:48.493072Z | Debug | executing command: cabal --builddir=/home/e/.cache/hie-bios/dist-spirv2gml-b1f42fe85ce43519cc33e59d54172f32 v2-exec --with-compiler /home/e/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/e/.cache/hie-bios/ghc-pkg-e283fb0c87704ad639a18c882466fb77 ghc -v0 -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2023-10-27T12:22:48.611376Z | Debug | executing command: cabal exec -v0 -- ghc --print-libdir
2023-10-27T12:22:48.688612Z | Debug | executing command: cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2023-10-27T12:22:48.816501Z | Debug | executing command: cabal --builddir=/home/e/.cache/hie-bios/dist-spirv2gml-b1f42fe85ce43519cc33e59d54172f32 v2-exec --with-compiler /home/e/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/e/.cache/hie-bios/ghc-pkg-e283fb0c87704ad639a18c882466fb77 ghc -v0 -- --print-libdir
2023-10-27T12:22:50.247693Z | Info | haskell-language-server version: 2.3.0.0 (GHC: 9.4.7) (PATH: /nix/store/wwyzhgdrz6sk13kcx4sywj149s08cg6k-haskell-language-server-2.3.0.0/bin/.haskell-language-server-9.4.7-unwrapped)
2023-10-27T12:22:50.248570Z | Info | Directory: /home/e/work/spirv2gml
2023-10-27T12:22:50.248721Z | Info | Starting (haskell-language-server) LSP server...
  GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsLogLevel = Info, argsLogFile = Nothing, argsLogStderr = True, argsLogClient = False, argsThreads = 0, argsProjectGhcVersion = False}
  PluginIds: [ pragmas-suggest
             , pragmas-completion
             , retrie
             , ghcide-completions
             , alternateNumberFormat
             , ghcide-code-actions-bindings
             , explicit-fields
             , ghcide-hover-and-symbols
             , ghcide-code-actions-type-signatures
             , floskell
             , fourmolu
             , ghcide-extend-import-action
             , ghcide-code-actions-fill-holes
             , importLens
             , LSPRecorderCallback
             , cabal
             , qualifyImportedNames
             , moduleName
             , splice
             , stylish-haskell
             , changeTypeSignature
             , hlint
             , class
             , ormolu
             , callHierarchy
             , ghcide-type-lenses
             , codeRange
             , cabal-fmt
             , eval
             , rename
             , ghcide-code-actions-imports-exports
             , gadt
             , overloaded-record-dot
             , ghcide-core
             , explicit-fixity
             , pragmas-disable ]
2023-10-27T12:22:50.251444Z | Info | Logging heap statistics every 60.00s
 2023-10-27T12:22:50.271373Z | Info | Starting LSP server...
  If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
  PluginIds: [ pragmas-suggest
             , pragmas-completion
             , retrie
             , ghcide-completions
             , alternateNumberFormat
             , ghcide-code-actions-bindings
             , explicit-fields
             , ghcide-hover-and-symbols
             , ghcide-code-actions-type-signatures
             , floskell
             , fourmolu
             , ghcide-extend-import-action
             , ghcide-code-actions-fill-holes
             , importLens
             , LSPRecorderCallback
             , cabal
             , qualifyImportedNames
             , moduleName
             , splice
             , stylish-haskell
             , changeTypeSignature
             , hlint
             , class
             , ormolu
             , callHierarchy
             , ghcide-type-lenses
             , codeRange
             , cabal-fmt
             , eval
             , rename
             , ghcide-code-actions-imports-exports
             , gadt
             , overloaded-record-dot
             , ghcide-core
             , explicit-fixity
             , pragmas-disable ]
2023-10-27T12:22:50.271593Z | Info | Starting server
2023-10-27T12:22:50.272811Z | Info | Started LSP server in 0.00s
2023-10-27T12:22:50.564326Z | Info | Registering IDE configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 7470944715222572669 "file:///home/e/work/spirv2gml"], clientSettings = hashed (Just (Object (fromList [])))}
2023-10-27T12:22:50.671481Z | Info | Cradle path: app/Main.hs
2023-10-27T12:22:50.671672Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for app/Main.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2023-10-27T12:22:50.674412Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2023-10-27T12:22:51.329529Z | Info | Interface files cache directory: /home/e/.cache/ghcide/main-843feac3f15730b258788fc3ed9bfc9c66608baf-843feac3f15730b258788fc3ed9bfc9c66608baf
2023-10-27T12:22:51.329803Z | Info | Making new HscEnv. In-place unit ids: [ main-843feac3f15730b258788fc3ed9bfc9c66608baf ]
2023-10-27T12:22:55.369384Z | Warning | No plugin enabled for "completionItem/resolve"
[Error - 20:22:55.369] Sending request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
[Error - 20:22:55.369] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
2023-10-27T12:22:56.761270Z | Warning | No plugin enabled for "completionItem/resolve"
[Error - 20:22:56.761] Sending request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
[Error - 20:22:56.761] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
2023-10-27T12:22:57.441582Z | Warning | No plugin enabled for "completionItem/resolve"
[Error - 20:22:57.441] Sending request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
[Error - 20:22:57.441] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
2023-10-27T12:22:58.129167Z | Warning | No plugin enabled for "completionItem/resolve"
[Error - 20:22:58.129] Sending request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
[Error - 20:22:58.129] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
2023-10-27T12:23:00.049158Z | Warning | No plugin enabled for "completionItem/resolve"
[Error - 20:23:00.049] Sending request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 
[Error - 20:23:00.049] Request completionItem/resolve failed.
  Message: No plugin enabled for SMethod_CompletionItemResolve, potentially available: ghcide-completions
  Code: -32601 

@joyfulmantis
Copy link
Collaborator

It should be easy enough to get HLS to bounce resolve requests we don't want to answer instead of failing them. It feels a bit incorrect, but probably worth it if our current behavior is causing problems with editors. I'll try to get a PR out this week for it.

@michaelpj
Copy link
Collaborator

Hmm, the error we get back also seems misleading, about no plugins being enabled? I also think there's a lsp parsing bug lurking here perhaps.

@joyfulmantis
Copy link
Collaborator

Hmm, the error we get back also seems misleading, about no plugins being enabled? I also think there's a lsp parsing bug lurking here perhaps.

These are completion request with an empty data field, and so we reject them outright. Certainly nicer rejection messages would be nice, but I think it what we currently show for these sort of request rejections.

@michaelpj
Copy link
Collaborator

Also, this looks like a client bug to me. It's not legal to pass null for insertTextMode. It can be absent, but not null.

2023-10-13T23:42:21.023882Z | Error | LSP: incoming message parse error:
Error in $.params.insertTextMode: parsing Integer failed, expected Number, but encountered Null
when processing
{"method":"completionItem/resolve","params":{"label":"spark#","detail":"from GHC.Base","sortText":"05","data":null,"insertTextMode":null,"insertTextFormat":1,"documentation":{"kind":"markdown","value":"Defined in 'GHC.Base'\n"},"command":{"arguments":[{"doc":"file:///home/maeve/projects/haskell/algorithm-design/app/Main.hs","importName":"GHC.Base","newThing":"spark#"}],"command":"404320:ghcide-extend-import-action:extendImport","title":"extend import"},"kind":3},"id":6,"jsonrpc":"2.0"}

@michaelpj
Copy link
Collaborator

These are completion request with an empty data field, and so we reject them outright. Certainly nicer rejection messages would be nice, but I think it what we currently show for these sort of request rejections.

That's a shame. It's really not comprehensible to the user, I think...

@cdimitroulas
Copy link

I get this same error when trying to apply code actions in neovim

@joyfulmantis
Copy link
Collaborator

I get this same error when trying to apply code actions in neovim

Code actions and completions work quite differently. @cdimitroulas could you create a new bug report with logs and specific details?

@michaelpj
Copy link
Collaborator

@joyfulmantis improved the error messages, and the next lsp release will be more tolerant of clients sending null instead of omitting a field, so I think we've made decent progress here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

6 participants