Presence of a .git directory breaks Haskell Language Server

I’m running into an odd bug, and I’m not sure how to go about further diagnosing it and fixing it.

In short, the presence of a .git directory “breaks” the haskell language server.

I have a cabal project in a directory .../parent/project with a cabal file project.cabal. When a .git directory is present in parent (or an even further removed parent directory) , the haskell language server cannot find three specific packages that have been listed in the project.cabal file. It can find all others. Additionally, if I remove all dependencies from the project.cabal file, the haskell language server still recognizes all those other packages, all of which it no longer should. So it seems that the haskell language server is somehow not reading the cabal file. There is no other cabal file contained in any of the parent directories.

I should note that cabal run and haskell-langauge-server-wrapper both still work fine, its only the haskell language server as its initiated by eglot (in emacs) that breaks.

When I rename the .git file to even just git, suddenly haskell language server works properly again.

If I remove all the content of .git so that it is an empty directory, the haskell language server still breaks.

If I create a new cabal project inside the directory parent, same result.

I have tested this across two different machines, in different parent directories, etc. I have tested this with HLS 2.9.0.1 and 2.10.0.0. I have tested this with GHC 9.10.1 and GHC 9.12.2. The result is the same.

However, I have many other cabal projects residing in git repositories, all of them have the haskell language server working just fine. I cannot for the life of me see a difference between this git repository and any of the others.

Has anybody run into a similar issue or have an idea of how to go about debugging this?

If I understand you correctly and that error only occures in Emacs, it is caused by Emacs’ / eglot’s project handling, which uses a .git directory as one of the possibilities to mark a project’s root directory. I don’t use eglot for many other reasons, so I can only say that at least lsp-mode interactively asks for the project’s root if there is no “project” registered yet for the opened file.

3 Likes

I see, that would make sense. Eglot seems to think the project directory is parent, not project. And when I remove the .git file, eglot seems to think the project directory is project/app, not project. Thank you, I think that identifies the problem. I thought it had to do with HLS, not eglot, mostly because HLS could still find some packages.

It seems like this question runs into the same issue.

Looks like there are two suggestions there that will work, adding a cabal.project file at the same level as the .git file, or setting the project-vc-extra-root-markers variable. The second one worked for me.