haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.71k stars 368 forks source link

`Prelude.head: empty list` makes hls unusable until restart #1618

Closed codygman closed 7 months ago

codygman commented 3 years ago

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

~/work-repo $ haskell-language-server --probe-tools
haskell-language-server version: 1.0.0.0 (GHC: 8.10.4) (PATH: /nix/store/1ngys7bwknlk8mixh5x3cxzxpnzn83ya-haskell-language-server-1.0.0.0/bin/haskell-language-server)
Tool versions found on the $PATH
cabal:      3.0.0.0
stack:      2.5.1.1
ghc:        8.10.4

Which lsp-client do you use: lsp-mode in emacs

Describe your project (alternative: link to the project): n/a

Steps to reproduce

I'm not quite sure.

Expected behaviour

HLS should not die with a Prelude.head empty list error or at least report an error with call stack information

Actual behaviour

HLS seems "stuck" until restart

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

I don't have time to take out information that I might be unable to share right now.

Debug output: ``` ```

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs: ``` Found "/home/cody/work-proj/hie.yaml" for "/home/cody/work-proj/a" Module "/home/cody/work-proj/a" is loaded by Cradle: Cradle {cradleRootDir = "/home/cody/work-proj", cradleOptsProg = CradleAction: Stack} Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.0.0.0 x86_64 ghc-8.10.4 Current directory: /home/cody/work-proj Operating system: linux Arguments: ["--lsp","-d","-l","/tmp/hls.log"] Cradle directory: /home/cody/work-proj Cradle type: Stack Tool versions found on the $PATH cabal: 3.0.0.0 stack: 2.5.1.1 ghc: 8.10.4 Consulting the cradle to get project GHC version... Project GHC version: 8.10.4 haskell-language-server exe candidates: ["haskell-language-server-8.10.4","haskell-language-server-8.10","haskell-language-server"] Launching haskell-language-server exe at:/run/current-system/sw/bin/haskell-language-server-8.10.4 haskell-language-server version: 1.0.0.0 (GHC: 8.10.4) (PATH: /nix/store/1ngys7bwknlk8mixh5x3cxzxpnzn83ya-haskell-language-server-1.0.0.0/bin/haskell-language-server) Starting (haskell-language-server)LSP server... with arguments: LspArguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = True, argsLogFile = Just "/tmp/hls.log", argsThreads = 0, argsProjectGhcVersion = False} with plugins: [PluginId "brittany",PluginId "class",PluginId "eval",PluginId "floskell",PluginId "fourmolu",PluginId "ghcide-code-actions",PluginId "ghcide-completions",PluginId "ghcide-hover-and-symbols",PluginId "ghcide-type-lenses",PluginId "haddockComments",PluginId "hlint",PluginId "importLens",PluginId "moduleName",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "splice",PluginId "stylish-haskell",PluginId "tactic"] in directory: /home/cody/work-proj If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option! Starting LSP server... If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option! Started LSP server in 0.00s setInitialDynFlags cradle: Cradle {cradleRootDir = "/home/cody/work-proj", cradleOptsProg = CradleAction: Stack} Output from setting up the cradle Cradle {cradleRootDir = "/home/cody/work-proj", cradleOptsProg = CradleAction: Stack} > work-proj> configure (lib) > Configuring work-proj-9003... > work-proj> initial-build-steps (lib) > Configuring GHCi with the following packages: work-proj > /home/cody/work-proj/.stack-work/install/x86_64-linux-nix/bf73507d5ab7d23ffbc635ca9a779c93abe2b07d289a0605721872c193f83a77/8.10.4/pkgdb:/home/cody/.stack/snapshots/x86_64-linux-nix/bf73507d5ab7d23ffbc635ca9a779c93abe2b07d289a0605721872c193f83a77/8.10.4/pkgdb:/nix/store/26zbw2cg6w0ih8gr5ab8vh670mccrd3v-ghc-8.10.4/lib/ghc-8.10.4/package.conf.d haskell-language-server-8.10.4: Prelude.head: empty list ```

What is /home/cody/work-proj/a? ls shows me file not found. Is that something synthetic hls adds?

jneira commented 3 years ago

Thanks for the bug report. Is it reproduced after building the project with stack build and restarting hls?

What is /home/cody/work-proj/a? ls shows me file not found. Is that something synthetic hls adds?

It is a fake path hls is using to load the cradle iirc

//cc @fendor

fendor commented 3 years ago

@jneira, yep, that path should be fine.

pepeiborra commented 3 years ago

is this still a problem?

lehins commented 3 years ago

I just ran into the exact same issue:

haskell-language-server-8.10.4: Prelude.head: empty list

Relevant version info:

Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.3.0.0, Git revision e7c5e90b6df5dff2760d76169eddaea3bdd6a831 (dirty) x86_64 ghc-8.10.4
Cradle type: Cabal

Tool versions found on the $PATH
cabal:      3.4.0.0
stack:      2.7.3
ghc:        8.10.4

Why would anyone use head??? It should really be removed from base or even better switched to head :: [a] -> Maybe a

fendor commented 7 months ago

I think this should be fixed by now, reopen if still an issue!