HLS can't find Main.hs for Haskell default project in VS Code, despite being listed in .cabal

52 Views Asked by At

I had a working Haskell Language Server/VS Code integration, and it just stopped working, and now even a fresh install of VS Code, Haskell (via GHCup), the HLS and a fresh project, I get the error that the HLS can't find Main.hs and suggests it needs listing in the .cabal file. I created a fresh user on this machine, and did a fresh install of everything there, and then it worked.


System/install details:

  • Mac OS 14.2.1 (23C71)
  • GHC 9.4.8, installed by pasting command from https://www.haskell.org/ghcup/ into Terminal (running zsh)
  • HLS 2.5.0.0
  • cabal 3.10.2.1
  • stack 2.13.1

Opening VS Code in the root folder of the project (which does build successfully, so Haskell itself is fine), I get the error message

Loading the module '/Users/david/[SNIPPED]/app/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

HLS was working earlier in the week, and even after it broke on a larger project, it still worked on the template project, and then the next day HLS was broken on the template project too. I did not do any major upgrades that I am aware of. The larger project was pulled clean from GitHub, and my colleague also pulled a clean copy and had it work fine, before I tried to debug, and found that not even the template project resulting in HLS working properly.

See the log below, but the HLS specifically breaks when it tries to find info on a type (or similar) to display as a tooltip in VSCode.

My settings.json from VS Code is (this is the complete file)

{
    "haskell.manageHLS": "GHCup",
    "git.autofetch": true,
    "editor.formatOnSave": true,
    "files.hotExit": "off",
    "editor.fontFamily": "JetBrains Mono, Menlo, Monaco, 'Courier New', monospace",
    "editor.fontLigatures": true
}

The .cabal file of the project contains the following settings, after the project metadata (maintainer, license etc):

cabal-version:      3.0

-- SNIPPED METADATA

build-type:         Simple

extra-doc-files:    CHANGELOG.md

common warnings
    ghc-options: -Wall

executable situated-reasoner2
    import:           warnings
    main-is:          Main.hs

    -- Modules included in this executable, other than Main.
    -- other-modules:

    -- LANGUAGE extensions used by modules in this package.
    -- other-extensions:

    build-depends:    base ^>=4.17.2.1
    hs-source-dirs:   app
    default-language: Haskell2010

Here's the end of the log

2024-02-01T07:15:21.890830Z | Info | Cradle path: app/Main.hs
2024-02-01T07:15:21.890905Z | 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.
2024-02-01T07:15:21.891827Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2024-02-01T07:15:22.341363Z | Warning | No plugin handles this "textDocument/semanticTokens/full" request.
[Error - 17:45:22] Request textDocument/semanticTokens/full failed.
  Message: No plugins are available to handle this SMethod_TextDocumentSemanticTokensFull request.
 Plugins installed for this method, but not available to handle this request are:
semanticTokens is disabled globally in your config.
  Code: -32601 
2024-02-01T07:15:22.578600Z | Info | cabal --builddir=/Users/david/.cache/hie-bios/dist-[SNIPPED]-7455b94875967927029f419348469cff v2-repl --with-compiler /Users/david/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /Users/david/.cache/hie-bios/ghc-pkg-9d846c81c4c61505d0e53ee3963ccf4a /Users/david/[SNIPPED]/app/Main.hs
  Environment Variables
    HIE_BIOS_OUTPUT: /private/var/folders/99/4c53g77s3qv2h_53rv940bym0000gn/T/HIE_BIOS_OUTPUT63581-0
    HIE_BIOS_GHC: /Users/david/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/bin/ghc-9.4.8
    HIE_BIOS_GHC_ARGS: -B/Users/david/.ghcup/ghc/9.4.8/lib/ghc-9.4.8/lib
[Error - 17:45:22] Request textDocument/foldingRange failed.
  Message: codeRange: Rule Failed: GetCodeRange
  Code: -32803 
[Error - 17:45:22] Request textDocument/codeLens failed.
  Message: eval: Rule Failed: GetEvalComments
  Code: -32803 

Someone on GitHub suggested having a hie.yaml file containing

cradle:
  cabal:

But that didn't change anything.

0

There are 0 best solutions below