haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Spurious error when opening project, even though HLS works properly

Open lylek opened this issue 2 years ago • 7 comments

Your environment

Which OS do you use? macOS 13.3 on aarch64

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

How is your project built (alternative: link to the project)? A makefile that calls stack

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

Which version of HLS do you use and how did you install it? 1.10.0.0 - was installed automatically by VSCode extension

Have you configured HLS in any way (especially: a hie.yaml file)? Yes, I generated a hie.yaml using gen-hie --stack.

What's wrong?

Everything is working in HLS. It's just that I get a spurious error message popping up when the HLS server starts. It seems that it's trying to run cabal exec -v0 --ghc --print-libdir. But I don't know why it's running that command - I'm using stack. I've made that clear in the hie.yaml.

Debug information

2023-05-12T18:51:23.477355Z | Info | Starting server
2023-05-12T18:51:23.500923Z | Info | Started LSP server in 0.02s
2023-05-12T18:51:23.531179Z | Debug | executing command: cabal exec -v0 -- ghc --print-libdir
2023-05-12T18:51:27.565448Z | Error | Couldn't load cradle for ghc libdir.
  Cradle error: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling cabal exec -v0 -- ghc --print-libdir","","cabal: Could not resolve dependencies:\n[__0] trying: ExaTMS-0.1.0.0 (user goal)\n[__1] rejecting: ExaTMS:!test (constraint from config file, command line flag,\nor user target requires opposite flag selection)\n[__1] trying: ExaTMS:*test\n[__2] trying: openapi3-3.2.3 (dependency of ExaTMS *test)\n[__3] trying: template-haskell-2.18.0.0/installed-2.18.0.0 (dependency of\nExaTMS)\n[__4] trying: lens-datetime-0.3 (dependency of ExaTMS)\n[__5] next goal: lens (dependency of ExaTMS)\n[__5] rejecting: lens-5.2.2 (conflict: lens-datetime => lens>=3 && <5)\n[__5] skipping: lens-5.2.1, lens-5.2, lens-5.1.1, lens-5.1, lens-5.0.1, lens-5\n(has the same characteristics that caused the previous version to fail:\nexcluded by constraint '>=3 && <5' from 'lens-datetime')\n[__5] rejecting: lens-4.19.2 (conflict:\ntemplate-haskell==2.18.0.0/installed-2.18.0.0, lens => template-haskell>=2.4\n&& <2.17)\n[__5] skipping: lens-4.19.1, lens-4.19, lens-4.18.1, lens-4.18, lens-4.17.1,\nlens-4.17, lens-4.16.1, lens-4.16, lens-4.15.4, lens-4.15.3, lens-4.15.2,\nlens-4.15.1, lens-4.15, lens-4.14, lens-4.13.2.1, lens-4.13.2, lens-4.13.1,\nlens-4.13, lens-4.12.3, lens-4.12.2, lens-4.12.1, lens-4.12, lens-4.11.1,\nlens-4.11, lens-4.10, lens-4.9.1, lens-4.9, lens-4.8, lens-4.7.0.1, lens-4.7,\nlens-4.6.0.1, lens-4.6, lens-4.5, lens-4.4.0.2, lens-4.4.0.1, lens-4.4,\nlens-4.3.3, lens-4.3.2, lens-4.3.1, lens-4.3, lens-4.2, lens-4.1.2.1,\nlens-4.1.2, lens-4.1.1, lens-4.1, lens-4.0.7, lens-4.0.6, lens-4.0.5,\nlens-4.0.4, lens-4.0.3, lens-4.0.2, lens-4.0.1, lens-4.0, lens-3.10.3,\nlens-3.10.2, lens-3.10.1, lens-3.10.0.1, lens-3.10, lens-3.9.2, lens-3.9.1,\nlens-3.9.0.3, lens-3.9.0.2, lens-3.9.0.1, lens-3.9, lens-3.8.7.3,\nlens-3.8.7.2, lens-3.8.7.1, lens-3.8.7, lens-3.8.6, lens-3.8.5, lens-3.8.4,\nlens-3.8.3, lens-3.8.2, lens-3.8.1, lens-3.8.0.2, lens-3.8.0.1, lens-3.8 (has\nthe same characteristics that caused the previous version to fail: excludes\n'template-haskell' version 2.18.0.0)\n[__5] rejecting: lens-3.7.6 (conflict: openapi3 => lens>=4.16.1 && <5.3)\n[__5] skipping: lens-3.7.5, lens-3.7.4, lens-3.7.3, lens-3.7.2, lens-3.7.1.2,\nlens-3.7.1.1, lens-3.7.1, lens-3.7.0.2, lens-3.7.0.1, lens-3.7, lens-3.6.0.4,\nlens-3.6.0.3, lens-3.6.0.2, lens-3.6.0.1, lens-3.6, lens-3.5.1, lens-3.5,\nlens-3.4, lens-3.3, lens-3.2, lens-3.1, lens-3.0.6, lens-3.0.5, lens-3.0.4,\nlens-3.0.3, lens-3.0.2, lens-3.0.1, lens-3.0, lens-2.9, lens-2.8,\nlens-2.7.0.1, lens-2.7, lens-2.6.1, lens-2.6, lens-2.5, lens-2.4.0.2,\nlens-2.4, lens-2.3, lens-2.2, lens-2.1, lens-2.0, lens-1.9.1, lens-1.9,\nlens-1.8, lens-1.7.1, lens-1.7, lens-1.6, lens-1.5, lens-1.4.1, lens-1.4,\nlens-1.3.1, lens-1.3, lens-1.2, lens-1.1.1, lens-1.1, lens-1.0.3, lens-1.0.2,\nlens-1.0.1, lens-1.0, lens-0.9, lens-0.8, lens-0.7, lens-0.6, lens-0.5,\nlens-0.4, lens-0.3, lens-0.2, lens-0.1 (has the same characteristics that\ncaused the previous version to fail: excluded by constraint '>=4.16.1 && <5.3'\nfrom 'openapi3')\n[__5] fail (backjumping, conflict set: ExaTMS, lens, lens-datetime, openapi3,\ntemplate-haskell)\nAfter searching the rest of the dependency tree exhaustively, these were the\ngoals I've had most trouble fulfilling: lens, ExaTMS, openapi3,\ntemplate-haskell, lens-datetime, ExaTMS:test\nTry running with --minimize-conflict-set to improve the error message.\n\n"]}
  Root dir path: /Users/lkopnicky/ExaTMS
  hie.yaml path:
  Cradle: Cradle {cradleRootDir = "/Users/lkopnicky/ExaTMS", cradleOptsProg = CradleAction: Cabal}

lylek avatar May 12 '23 19:05 lylek

Heyo, thank you for your bug report!

Two things:

  • Is /Users/lkopnicky/ExaTMS the root of your project, e.g. where your .cabal or cabal.project file can be found?
  • Try running that command cabal exec -- ghc --print-libdir, maybe the output is more helpful.

fendor avatar May 13 '23 09:05 fendor

Heyo, thank you for your bug report!

Two things:

  • Is /Users/lkopnicky/ExaTMS the root of your project, e.g. where your .cabal or cabal.project file can be found?

Yes. The .cabal file is auto-generated from package.yaml by hpack 0.35.1.

  • Try running that command cabal exec -- ghc --print-libdir, maybe the output is more helpful.

I tried that, but I don't find the output helpful. It gives me errors about not being able to resolve dependencies. However, I'm able to build my project just fine (with stack) and HLS operates correctly, so I don't think I have any dependency issues.

% cabal exec -- ghc --print-libdir
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: ExaTMS-0.1.0.0 (user goal)
[__1] rejecting: ExaTMS:!test (constraint from config file, command line flag,
or user target requires opposite flag selection)
[__1] trying: ExaTMS:*test
[__2] trying: openapi3-3.2.3 (dependency of ExaTMS *test)
[__3] trying: template-haskell-2.18.0.0/installed-2.18.0.0 (dependency of
ExaTMS)
[__4] trying: lens-datetime-0.3 (dependency of ExaTMS)
[__5] next goal: lens (dependency of ExaTMS)
[__5] rejecting: lens-5.2.2 (conflict: lens-datetime => lens>=3 && <5)
[__5] skipping: lens-5.2.1, lens-5.2, lens-5.1.1, lens-5.1, lens-5.0.1, lens-5
(has the same characteristics that caused the previous version to fail:
excluded by constraint '>=3 && <5' from 'lens-datetime')
[__5] rejecting: lens-4.19.2 (conflict:
template-haskell==2.18.0.0/installed-2.18.0.0, lens => template-haskell>=2.4
&& <2.17)
[__5] skipping: lens-4.19.1, lens-4.19, lens-4.18.1, lens-4.18, lens-4.17.1,
lens-4.17, lens-4.16.1, lens-4.16, lens-4.15.4, lens-4.15.3, lens-4.15.2,
lens-4.15.1, lens-4.15, lens-4.14, lens-4.13.2.1, lens-4.13.2, lens-4.13.1,
lens-4.13, lens-4.12.3, lens-4.12.2, lens-4.12.1, lens-4.12, lens-4.11.1,
lens-4.11, lens-4.10, lens-4.9.1, lens-4.9, lens-4.8, lens-4.7.0.1, lens-4.7,
lens-4.6.0.1, lens-4.6, lens-4.5, lens-4.4.0.2, lens-4.4.0.1, lens-4.4,
lens-4.3.3, lens-4.3.2, lens-4.3.1, lens-4.3, lens-4.2, lens-4.1.2.1,
lens-4.1.2, lens-4.1.1, lens-4.1, lens-4.0.7, lens-4.0.6, lens-4.0.5,
lens-4.0.4, lens-4.0.3, lens-4.0.2, lens-4.0.1, lens-4.0, lens-3.10.3,
lens-3.10.2, lens-3.10.1, lens-3.10.0.1, lens-3.10, lens-3.9.2, lens-3.9.1,
lens-3.9.0.3, lens-3.9.0.2, lens-3.9.0.1, lens-3.9, lens-3.8.7.3,
lens-3.8.7.2, lens-3.8.7.1, lens-3.8.7, lens-3.8.6, lens-3.8.5, lens-3.8.4,
lens-3.8.3, lens-3.8.2, lens-3.8.1, lens-3.8.0.2, lens-3.8.0.1, lens-3.8 (has
the same characteristics that caused the previous version to fail: excludes
'template-haskell' version 2.18.0.0)
[__5] rejecting: lens-3.7.6 (conflict: openapi3 => lens>=4.16.1 && <5.3)
[__5] skipping: lens-3.7.5, lens-3.7.4, lens-3.7.3, lens-3.7.2, lens-3.7.1.2,
lens-3.7.1.1, lens-3.7.1, lens-3.7.0.2, lens-3.7.0.1, lens-3.7, lens-3.6.0.4,
lens-3.6.0.3, lens-3.6.0.2, lens-3.6.0.1, lens-3.6, lens-3.5.1, lens-3.5,
lens-3.4, lens-3.3, lens-3.2, lens-3.1, lens-3.0.6, lens-3.0.5, lens-3.0.4,
lens-3.0.3, lens-3.0.2, lens-3.0.1, lens-3.0, lens-2.9, lens-2.8,
lens-2.7.0.1, lens-2.7, lens-2.6.1, lens-2.6, lens-2.5, lens-2.4.0.2,
lens-2.4, lens-2.3, lens-2.2, lens-2.1, lens-2.0, lens-1.9.1, lens-1.9,
lens-1.8, lens-1.7.1, lens-1.7, lens-1.6, lens-1.5, lens-1.4.1, lens-1.4,
lens-1.3.1, lens-1.3, lens-1.2, lens-1.1.1, lens-1.1, lens-1.0.3, lens-1.0.2,
lens-1.0.1, lens-1.0, lens-0.9, lens-0.8, lens-0.7, lens-0.6, lens-0.5,
lens-0.4, lens-0.3, lens-0.2, lens-0.1 (has the same characteristics that
caused the previous version to fail: excluded by constraint '>=4.16.1 && <5.3'
from 'openapi3')
[__5] fail (backjumping, conflict set: ExaTMS, lens, lens-datetime, openapi3,
template-haskell)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: lens, ExaTMS, openapi3,
template-haskell, lens-datetime, ExaTMS:test
Try running with --minimize-conflict-set to improve the error message.

lylek avatar May 13 '23 20:05 lylek

Aha, that's the issue, HLS thinks it is a cabal project while it actually is a stack project! Try deleting dist-newstyle in your project directory, make sure you have run stack build (e.g., .stack-work or whatever it is called), and then launch HLS again.

Also, what's in your hie.yaml? And where did you create it? Right next to your stack.yaml/package.yaml? If all that doesn't help, please share your project structure, e.g. a call from tree

fendor avatar May 13 '23 20:05 fendor

Aha, that's the issue, HLS thinks it is a cabal project while it actually is a stack project! Try deleting dist-newstyle in your project directory, make sure you have run stack build (e.g., .stack-work or whatever it is called), and then launch HLS again.

That got rid of the problem, thank you!

Also, what's in your hie.yaml? And where did you create it? Right next to your stack.yaml/package.yaml? If all that doesn't help, please share your project structure, e.g. a call from tree

My hie.yaml is in the top level of my project, next to the stack.yaml/package.yaml.

I won't list my entire hie.yaml here, but here's the first piece of it:

cradle:
  stack:
    - path: "./src"
      component: "ExaTMS:lib"

    - path: "./app/Main.hs"
      component: "ExaTMS:exe:ExaTMS"

    - path: "././"
      component: "ExaTMS:test:doctest"

    - path: "./integration-test"
      component: "ExaTMS:test:integration-test"

    - path: "./test"
      component: "ExaTMS:test:test"

All the other entries are like that... underneath the stack key. That's why I was surprised that HLS thought I was using cabal. I have no cabal key in my hie.yaml.

So apparently there's something looking for dist-newstyle and assuming that means it's a cabal project. But it's just one piece of the process... because as I said, everything else was working correctly.

lylek avatar May 13 '23 22:05 lylek

BTW, there's also a cabal.project file. Some developers use nix with cabal, others use stack, on the same repo. The hie.yaml is not part of the repo though - I generated that with gen-hie --stack.

lylek avatar May 13 '23 22:05 lylek

hie.yaml should be the absolute authority, nothing else matters. So, I am also perplexed why it didn't think it is a stack project. Your log says that there is no hie.yaml location:

2023-05-12T18:51:27.565448Z | Error | Couldn't load cradle for ghc libdir.
  Cradle error: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = [...]}
  Root dir path: /Users/lkopnicky/ExaTMS
  hie.yaml path:
  Cradle: Cradle {cradleRootDir = "/Users/lkopnicky/ExaTMS", cradleOptsProg = CradleAction: Cabal}

This is wrong, since there is one.

It would be great, if you can share your project, or a public example where this behaviour is reproducible,

fendor avatar May 14 '23 07:05 fendor

Did we ever get a reproduction for this?

michaelpj avatar Jan 17 '24 10:01 michaelpj