haskell / haskell-language-server

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

HLS fails to start due to hidden packages #4415

Closed tomseli closed 1 week ago

tomseli commented 1 week ago

Your environment

Which OS do you use?

Windows 11

Which version of GHC do you use and how did you install it?

The GHCup Haskell installer, version 0.1.30.0 cabal-install version 3.12.1.0 compiled using version 3.12.1.0 of the Cabal library

How is your project built (alternative: link to the project)? Using Cabal, with the following .cabal file

cabal-version:      3.0
name:               Hac-Man
version:            0.1.0.0

homepage:           
license:            MIT
license-file:       LICENSE

-- The package author(s).
author:             Tom Selier
maintainer:

category:           Game
build-type:         Simple

extra-doc-files:    CHANGELOG.md

common warnings
    ghc-options: -Wall -O2 -threaded

executable Hac-Man
    import:           warnings
    main-is:          Main.hs

    other-modules:    Controller.Controller,
                      View.View,
                      Model.Model

    build-depends:    base ^>=4.17.2.1,
                                gloss ^>=1.13.0.4

    hs-source-dirs:   src
    default-language: Haskell2010

Which LSP client (editor/plugin) do you use?

VSCode + Haskell extensions

Which version of HLS do you use and how did you install it? Got prompted by the extension ghcup install hls reports hls-2.9.0.1

Have you configured HLS in any way (especially: a hie.yaml file)?

cradle:
  cabal:

What's wrong?

HLS fails to start in my cabal project. It does work in other (non-project) Haskell files.

It reports a hidden package (directory and process). I've messed around with the paths (currently it's back to default), and tried to install those packages, even though they clearly are installed. I've browsed the issues and the docs, and found no mention of this error. I'm at my wits end to get it to work, so some help would be very appreciated!

NB the project builds and runs without issues.

Debug information

The output from VSCode:

2024-10-10 08:28:13.0330000 [client] INFO Finding haskell-language-server
2024-10-10 08:28:13.0340000 [client] INFO Searching for server executables haskell-language-server-wrapper,haskell-language-server in $PATH
2024-10-10 08:28:13.0340000 [client] INFO $PATH environment variable: C:\Program Files (x86)\Common Files\Oracle\Java\java8path;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\komorebi\bin\;C:\Program Files\whkd\bin\;C:\Program Files\Docker\Docker\resources\bin;C:\Users\tomse\AppData\Local\Microsoft\WindowsApps;C:\Users\tomse\AppData\Local\Programs\Microsoft VS Code\bin;C:\ghcup\bin;C:\Users\tomse\AppData\Local\Programs\oh-my-posh\bin;C:\Users\tomse\AppData\Local\Microsoft\WinGet\Packages\Schniz.fnm_Microsoft.Winget.Source_8wekyb3d8bbwe;C:\texlive\2024\bin\windows;C:\Users\tomse\AppData\Local\Microsoft\WinGet\Packages\BrettMayson.HEMTT_Microsoft.Winget.Source_8wekyb3d8bbwe;C:\cabal\bin;
2024-10-10 08:28:13.0750000 [client] INFO Found server executable in $PATH: haskell-language-server-wrapper
2024-10-10 08:28:13.0750000 [client] INFO Activating the language server in working dir: c:\Repositories\Hac-Man (the workspace folder)
2024-10-10 08:28:13.0750000 [client] INFO run command: haskell-language-server-wrapper --lsp
2024-10-10 08:28:13.0750000 [client] INFO debug command: haskell-language-server-wrapper --lsp
2024-10-10 08:28:13.0750000 [client] INFO server cwd: c:\Repositories\Hac-Man
2024-10-10 08:28:13.0750000 [client] INFO server environment variables:
2024-10-10 08:28:13.0780000 [client] INFO Starting language server
Found "c:\Repositories\Hac-Man\hie.yaml" for "c:\Repositories\Hac-Man\a"
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper-2.9.0.1.exe) Version 2.9.0.1 x86_64 ghc-9.8.2
Current directory: c:\Repositories\Hac-Man
Operating system: mingw32
Arguments: ["--lsp"]
Cradle directory: c:\Repositories\Hac-Man
Cradle type: Cabal

Tool versions found on the $PATH
cabal:          3.12.1.0
stack:          Not found
ghc:            9.4.8

Consulting the cradle to get project GHC version...
2024-10-10T08:28:13.633569Z | Debug | cabal exec -v0 -- ghc --print-libdir
2024-10-10T08:28:15.349744Z | Debug | cabal exec -v0 -- ghc -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)
2024-10-10T08:28:15.350851Z | Debug | ghc -rtsopts=ignore -outputdir C:\Users\tomse\AppData\Local\Temp\hie-bios-d70021ae70e1c91c -o C:\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.exe C:\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs

C:\\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs:4:1: error:
    Could not load module `System.Directory'
    It is a member of the hidden package `directory-1.3.7.1'.
    You can run `:set -package directory' to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import System.Directory (getCurrentDirectory)

  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

C:\\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs:7:1: error:
    Could not load module `System.Process'
    It is a member of the hidden package `process-1.6.18.0'.
    You can run `:set -package process' to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
7 | import System.Process (spawnProcess, waitForProcess)

  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
haskell-language-server-wrapper-2.9.0.1.exe: readCreateProcess: ghc "-rtsopts=ignore" "-outputdir" "C:\\Users\\tomse\\AppData\\Local\\Temp\\hie-bios-d70021ae70e1c91c" "-o" "C:\\Users\\tomse\\AppData\\Local\\hie-bios\\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.exe" "C:\\Users\\tomse\\AppData\\Local\\hie-bios\\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs" (exit 1): failed
fendor commented 1 week ago

Hi, thank you for your bug report! process and directory are packages that you need to actively depend on in a cabal project. They are included by default if you just use ghc, but with .cabal files you need to be explicit :)

executable Hac-Man
    import:           warnings
    main-is:          Main.hs

    other-modules:    Controller.Controller,
                      View.View,
                      Model.Model

    build-depends:    base ^>=4.17.2.1,
                                gloss ^>=1.13.0.4,
                                directory,
                                process

    hs-source-dirs:   src
    default-language: Haskell2010

BTW, cabal build should show you the same error message.

PS, here is the documentation for directory and process. Often, when you are using directory, you also want filepath. So maybe you also want to depend on filepath in the future.

tomseli commented 1 week ago

Thanks for the quick response!

I've edited the build-depends as you sugested, then rebuilt the project. Cabal build does not give me any warnings whatsoever.

Unfortunately, I get the same error from HLS.

Do you have any further ideas? Do you need more information?

fendor commented 1 week ago

Have you restarted the editor? Unfortunately, HLS does not pick up changes to the .cabal file automatically due to some bugs.

Otherwise, please show the new logs of vscode.

fendor commented 1 week ago

Oh wait, I may have misidentified the problem

fendor commented 1 week ago

This seems to be an issue in hie-bios, we fail to compile the wrapper.hs which is necessary to launch HLS correctly...

fendor commented 1 week ago

This looks more complicated than anticipated. Have you ever run cabal install --lib by accident or purpose?

Can you reproduce the error message via running ghc "-rtsopts=ignore" "-outputdir" "C:\\Users\\tomse\\AppData\\Local\\Temp\\hie-bios-d70021ae70e1c91c" "-o" "C:\\Users\\tomse\\AppData\\Local\\hie-bios\\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.exe" "C:\\Users\\tomse\\AppData\\Local\\hie-bios\\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs"?

tomseli commented 1 week ago

I can indeed replicate the error running that code. And I likely have ran cabal install --lib at some point.

For completeness sake, here's the full error:

PS C:\Repositories\Hac-Man> ghc "-rtsopts=ignore" "-outputdir" "C:\\Users\\tomse\\AppData\\Local\\Temp\\hie-bios-d70021ae70e1c91c" "-o" "C:\\Users\\tomse\\AppData\\Local\\hie-bios\\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.exe" "C:\\Users\\tomse\\AppData\\Local\\hie-bios\\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs"
Loaded package environment from C:\Users\tomse\AppData\Roaming\ghc\x86_64-mingw32-9.4.8\environments\default
[1 of 2] Compiling Main             ( C:\\\\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs, C:\\\\Users\tomse\AppData\Local\Temp\hie-bios-d70021ae70e1c91c\Main.o )

C:\\\\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs:4:1: error:
    Could not load module `System.Directory'
    It is a member of the hidden package `directory-1.3.7.1'.
    You can run `:set -package directory' to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import System.Directory (getCurrentDirectory)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

C:\\\\Users\tomse\AppData\Local\hie-bios\wrapper-340ffcbd9b6dc8c3bed91eb5c533e4e3.hs:7:1: error:
    Could not load module `System.Process'
    It is a member of the hidden package `process-1.6.24.0'.
    You can run `:set -package process' to expose it.
    (Note: this unloads all the modules in the current scope.)
    It is a member of the hidden package `process-1.6.18.0'.
    You can run `:set -package process' to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
7 | import System.Process (spawnProcess, waitForProcess)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fendor commented 1 week ago

Perfect, that solves the issue! So, unless you know what you are doing, it is safe to say you should never run cabal install --lib. It was a bad idea by cabal to suggest it, it is almost never what you really want.

If you want to play around with packages in ghci, prefer cabal repl -z -b <name-of-package>.

Please delete the file C:\Users\tomse\AppData\Roaming\ghc\x86_64-mingw32-9.4.8\environments\default, then everything should be fine.

tomseli commented 1 week ago

Perfect! That did it. Thanks for the help!

fendor commented 1 week ago

Happy hacking! Feel free to open more issues if you encounter any more problems!