Skip to content
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

When main module is a symlink, HLS fails to load it #4462

Open
chreekat opened this issue Dec 8, 2024 · 5 comments
Open

When main module is a symlink, HLS fails to load it #4462

chreekat opened this issue Dec 8, 2024 · 5 comments
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@chreekat
Copy link

chreekat commented Dec 8, 2024

Your environment

Which OS do you use?
NixOS 24.05.6966.190c31a89e5e (Uakari)

Which version of GHC do you use and how did you install it?
The Glorious Glasgow Haskell Compilation System, version 9.6.5 from OS package

How is your project built (alternative: link to the project)?
cabal build

Which LSP client (editor/plugin) do you use?
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan 01 1980 00:00:00)
+ coc.nvim

Which version of HLS do you use and how did you install it?
haskell-language-server-9.6.5 from OS package

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

Steps to reproduce

  1. Use cabal init to create an executable package
  2. mv Main.hs Real.hs
  3. ln -s Real.hs Main.hs
  4. Start vim

Expected behaviour

HLS should load the module and provide hints.

Actual behaviour

I get a popup on line 1 with text:

>>module Main where
   Loading the module '/home/b/tmp/symlinkmain/Main.hs' failed.

   It may not be listed in your .cabal file!
   Perhaps you need to add `Main` to other-modules or exposed-modules.

   For more information, visit: https://cabal.readthedocs.io/en/3.4/developing-
   packages.html#modules-included-in-the-package
    (cradle)

The error message is incorrect, at the very least.

Debug information

@chreekat chreekat added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Dec 8, 2024
@fendor
Copy link
Collaborator

fendor commented Dec 9, 2024

While the error message is bad and incorrect, cabal is the reason this fails:

> cabal repl Main.hs
Error: [Cabal-7121]
Failed extracting script block: `{- cabal:` start marker not found

Can you confirm this?

@chreekat
Copy link
Author

chreekat commented Dec 9, 2024

@fendor yes, although a bare cabal repl works just fine!

@chreekat
Copy link
Author

chreekat commented Dec 9, 2024

[b@kuusi:~/tmp/symlinkmain]$ cabal repl app/Main.hs
Error: cabal: Failed extracting script block: `{- cabal:` start marker not
found


[b@kuusi:~/tmp/symlinkmain]$ cabal repl
Build profile: -w ghc-9.6.5 -O1
In order, the following will be built (use -v for more details):
 - symlinkmain-0.1.0.0 (exe:symlinkmain) (first run)
Preprocessing executable 'symlinkmain' for symlinkmain-0.1.0.0..
GHCi, version 9.6.5: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/b/Projects/dotfiles/ghci
[1 of 2] Compiling Main             ( app/Main.hs, interpreted )
Ok, one module loaded.
|*Main|
λ

@fendor
Copy link
Collaborator

fendor commented Dec 9, 2024

Yeah, but HLS uses cabal repl app/Main.hs by default, so that's a blocker for this issue.

There is a workaround, but it is not universally applicable. hie.yaml like this

cradle:
  cabal:
    component: all

and telling HLS to use multi component loading ala "haskell.sessionLoading": "multipleComponents". Requires cabal 3.12 and that all dependencies can be built using Cabal >= 3.12.

This setup implements an eager loading strategy where HLS loads all components in your project at once, which is likely the best user experience, as long as your RAM can take it. Don't forget to cabal configure --enable-tests --enable-benchmarks, though, see haskell/cabal#8605 (comment)

@chreekat
Copy link
Author

chreekat commented Dec 9, 2024

Cool beans, I opened haskell/cabal#10627.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage 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

2 participants