syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.68k stars 4.89k forks source link

haskell-mode not running the binary haskell-language-server #15616

Closed dewijones92 closed 2 years ago

dewijones92 commented 2 years ago

Description Thanks for this amazing project 😊 I am banging my head against a brick wall here πŸ˜” When I run "haskell-mode" I expcet it to run the associated language server. But it is not.

System info Spacemacs version: develop branch - 4eaff25268634fcb8137b91fb7d0b7598588cbca - Date: Mon Jun 20 23:12:45 2022 -0400

My ~/.spacemacs.d very vanilla https://github.com/dewijones92/spacemacs.d/blob/5fc5a78fafcf6bcdc086217d8aa469f6137a49cd/init.el#L114

dewi@pop-os:~/.emacs.d$ compgen -c | \grep "hask.*server"
haskell-language-server
haskell-language-server-wrapper

Reproduction guide πŸͺ²

  1. Open a haskell project
  2. Run in emacs haskell-mode

Observed behaviour: πŸ‘€ πŸ’” Error message

LSP :: Connected to [lsp-haskell:48309/starting].
LSP :: lsp-haskell has exited (finished)
Server lsp-haskell:48309/starting exited with status exit(check corresponding stderr buffer for details\
). Do you want to restart it? (y or n) y
LSP :: Connected to [lsp-haskell:48319/starting].
LSP :: lsp-haskell has exited (finished)
error in process sentinel: Quit [2 times]

Expected behaviour: ❀️ Spacemacs should run haskell-language-server

BenedictHW commented 2 years ago

Since it seems like no Haskell or LSP experts are chiming in here, I have to recommend eglot over LSP.

https://github.com/joaotavora/eglot

Though my experience with either is limited, I do know the author of eglot is very active upstream of Emacs and also happens to have wrote SLY (which I enjoy using very much).

https://github.com/joaotavora/sly

Eglot is meant to be plug and play, and I agree personally that cl-defmethod is nicer than a hash table for this design case.

https://github.com/joaotavora/eglot/issues/180

Competition is good! Eglot also has the explicit goal of being upstreamed into Emacs proper in the future. Try adding eglot' todotspacemacs-additional-packages'

dewijones92 commented 2 years ago

@BenedictHW many thanks for that. I gotta try it out :)

dalanicolai commented 2 years ago

@dewijones92 The error message says 'check corresponding stderr buffer for details', have you tried that? What did it say?

dewijones92 commented 2 years ago

@dalanicolai the logs look fine. Which is weird. I don't understand why emacs says it's immediately exiting 😞

/tmp/hls.log
`2022-07-02T06:56:45.617379Z | Info | haskell-language-server version: 1.7.0.0 (GHC: 9.2.3) (PATH: /home/dewi/.local/bin/haskell-language-server) (GIT hash: 59016bb9ae55b6c59b6866eb3f47c70f255b3c7a)
2022-07-02T06:56:45.617703Z | Info | Directory: /home/dewi/tmp/haskellTut/hell3/helloworld
2022-07-02T06:56:45.617761Z | Info | Starting (haskell-language-server) LSP server...
  GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = True, argsLogFile = Just "/tmp/hls.log", argsThreads = 0, argsProjectGhcVersion = False}
  PluginIds: [ pragmas
             , floskell
             , fourmolu
             , ormolu
             , stylish-haskell
             , rename
             , callHierarchy
             , class
             , eval
             , importLens
             , qualifyImportedNames
             , refineImports
             , moduleName
             , hlint
             , alternateNumberFormat
             , selectionRange
             , changeTypeSignature
             , gadt
             , ghcide-hover-and-symbols
             , ghcide-code-actions-imports-exports
             , ghcide-code-actions-type-signatures
             , ghcide-code-actions-bindings
             , ghcide-code-actions-fill-holes
             , ghcide-completions
             , ghcide-type-lenses
             , ghcide-core
             , LSPRecorderCallback ]
2022-07-02T06:56:45.617946Z | Info | Logging heap statistics every 60.00s
2022-07-02T06:56:45.623928Z | Info | Staring LSP server...
If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
lsp-haskell:stderr
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.7.0.0, Gi\
t revision 59016bb9ae55b6c59b6866eb3f47c70f255b3c7a (dirty) (2824 commits) x86_64 ghc-9.2.3
Current directory: /home/dewi/tmp/haskellTut/hell3/helloworld
Operating system: linux
Arguments: ["--lsp","-d","-l","/tmp/hls.log"]
Cradle directory: /home/dewi/tmp/haskellTut/hell3/helloworld
Cradle type: Stack

Tool versions found on the $PATH
cabal:    3.6.2.0
stack:    2.7.5
ghc:    9.2.3

Consulting the cradle to get project GHC version...
Project GHC version: 9.0.2
haskell-language-server exe candidates: ["haskell-language-server-9.0.2","haskell-language-server"]
Launching haskell-language-server exe at:/home/dewi/.local/bin/haskell-language-server

Process lsp-haskell stderr finished
dalanicolai commented 2 years ago

Okay, well I am no LSP/Emacs expert, so I guess the best thing for you to try then is to ask assistance on the lsp-mode gitter channel (maybe point them to this issue).

dewijones92 commented 2 years ago

@dalanicolai thanks, will do

blablablerg commented 2 years ago

Do you perchance have multiple haskell language servers installed? E.g. a local one in a project dir and a global one? I had this problem too, emacs was starting the wrong one. You can check this by running the shell command which haskell-language-server in emacs.

In my spacemacs config I have (spacemacs/load-spacemacs-env) commented out, because the way spacemacs loads environment variables was causing problems like this (in combination with nix and direnv). Didn't seem to break anything else for me 🀷. Good luck solving it.

lebensterben commented 2 years ago

@dewijones92

Please see @blablablerg 's comment above. It's likely to be caused by version conflict.

And yes the way Spacemacs deals with environment variables is error prone.

dewijones92 commented 2 years ago

@blablablerg @lebensterben thanks for your comments. Unfortunately commenting out (spacemacs/load-spacemacs-env) did not work.

I only have 1 instance on HLS installed:

$ type -a haskell-language-server
haskell-language-server is /home/dewi/.local/bin/haskell-language-server

$ type -a haskell-language-server-wrapper
haskell-language-server-wrapper is /home/dewi/.local/bin/haskell-language-server-wrapper

does anyone here have HLS working with emacs? if so can you kindly share me your config? thanks

lebensterben commented 2 years ago

@dewijones92

What's the setup of the project you're working on? It's common that it uses a different ghc version from your system's default and it might cause problem.

dewijones92 commented 2 years ago

wow i just started from a clean spacemacs config and now it works :) yay :)

dewijones92 commented 2 years ago

thanks all for your comments

dewijones92 commented 2 years ago

This is the culprit config. https://github.com/dewijones92/spacemacs.d/tree/07b6ac203027429a33d158ed462292147abfeca2 No idea what the cause is tho

I should have tried a clean config weeks ago ahahah πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜’πŸ˜’πŸ˜’πŸ˜’πŸ˜’