haskell-language-server
haskell-language-server copied to clipboard
HLS can't find Main.hs for Haskell default project in VS Code, despite being listed in .cabal, and goes into crash loop
Your environment
- Which OS do you use?
Mac OS 14.2.1 (23C71)
- Which version of GHC do you use and how did you install it?
v9.4.8, pasting command from https://www.haskell.org/ghcup/
- How is your project built (alternative: link to the project)?
Unedited template Haskell project created via cabal init --interactive
, the resulting .cabal
file is below, minus metadata.
- Which LSP client (editor/plugin) do you use?
VS Code, pretty much a clean install
- Which version of HLS do you use and how did you install it?
2.5.0.0, via VS Code
- Have you configured HLS in any way (especially: a
hie.yaml
file)?
No
What's wrong?
I'm aware of #1297, but I'm not doing anything fancy at all.
Working with Cabal and a clean install of HLS and taking the template Haskell project, which does build, I'm getting the dreaded error
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
Despite Main.hs
being listed in my .cabal
file, opening VS Code after successful compilation in the correct folder etc.
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 attached log, but the HLS specifically breaks when it tries to find info on a type (or similar) to display as a tooltip in VSCode.
Debug information
Here's what I think is relevant from the log: HLS_log.txt
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
Cabal version is 3.10.2.1, Stack (though I'm not using it) is v2.13.1, and GHCup is v0.1.20.0, and I have run cabal update
.
My PATH variable contains /Users/david/.cabal/bin:/Users/david/.ghcup/bin
Try adding the following hie.yaml
:
cradle:
cabal:
Did that, and the result is no different. Here's the end of the log:
2024-02-02T23:15:36.360178Z | Info | Starting server
2024-02-02T23:15:36.385373Z | Info | Started LSP server in 0.03s
2024-02-02T23:15:36.866594Z | Info | Registering IDE configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 7466103998142758901 "file:///Users/david/[SNIPPED]"], clientSettings = hashed Nothing}
2024-02-02T23:15:36.881661Z | Info | Cradle path: src/SVA/SValuation.hs
2024-02-02T23:15:36.882082Z | Info | invoking build tool to determine build flags (this may take some time depending on the cache)
2024-02-02T23:15:37.327524Z | Warning | No plugin handles this "textDocument/semanticTokens/full" request.
[Error - 09:45:37] 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-02T23:15:37.745070Z | Info | cabal --builddir=/Users/david/.cache/hie-bios/dist-[SNIPPED]-bd3c78c81bf13db646dfcdd1d2c74c8a 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]/src/SVA/SValuation.hs
Environment Variables
HIE_BIOS_OUTPUT: /private/var/folders/99/4c53g77s3qv2h_53rv940bym0000gn/T/HIE_BIOS_OUTPUT2595-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 - 09:45:37] Request textDocument/codeLens failed.
Message: eval: Rule Failed: GetEvalComments
Code: -32803
[Error - 09:45:37] Request textDocument/foldingRange failed.
Message: codeRange: Rule Failed: GetCodeRange
Code: -32803
Let me know if you need more from before this.
Someone advised me that "template Haskell" is a separate thing, and certainly not what I'm working with! Reworded the title to be less misleading, I hope
For what it's worth, in a fresh account on this laptop, a fresh install of VSCode, CHCup and HLS works ok. Still don't know why it's not working in my current account. Could there be some kind of system environment variable that's messing things up?
In cases like this when things stop working mysteriously, I usually just delete hls's cache folder (where hls stores build artifacts). It's usually stored under home directory ~/.cache/ghcide - just rm -rf the whole directory and restart hls (ctrl+shift+p - restart haskell language server) Refer to https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#clearing-hls-s-build-cache
Sadly, this didn't help.
Sorry, I'm out of my depth :-/
It seems to me that to make these kinds of issues easier to troubleshoot we should include more info in the error message than just Message: codeRange: Rule Failed: GetCodeRange
And now, mysteriously, the problem seems to have fixed itself. I really don't know what happened there!
I suggest closing this issue since the problem can't be reproduced any longer. It can be reopened, in case it reappears.
@LucianU will do.
I suggest closing this issue since the problem can't be reproduced any longer. It can be reopened, in case it reappears.
No, it's not an issue that can't be reproduced. I ran into this issue with HLS2.9.0.1 + GHC9.10.1 + cabal3.10.3.0. For me, the problem was solved simply by copying the entire package folder into another directory. And after that, I found that the original path of my package contains a space in the parent folder just like: ~/foo bar/MyLib/
. If I rename it to ~/foo_bar/MyLib/
, problem solved.
So the true cause of the error message @DavidMichaelRoberts may be that [SNIPPED]
contains some characters that HLS doesn't recognize, even a space. If this is the case, it's definitely a bug of HLS which can be fixed easily.
Hope this helps.
The issue you describe is a cabal bug iirc https://github.com/haskell/cabal/issues/8875
So that should be solved with 3.12
.