haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.66k stars 355 forks source link

Couldn't load cradle for libdir #2599

Closed jerbaroo closed 2 years ago

jerbaroo commented 2 years ago

Your environment

Which OS do you use: NixOS Which LSP client (editor/plugin) do you use: Doom emacs+lsp-mode+envrc-mode In my config.el I set: setq lsp-haskell-server-path "haskell-language-server-8.10.7" Describe your project (alternative: link to the project): haskell.nix (haskell-language-server is provided via haskell.nix's shellFor.tools) + cabal.project

Expected behaviour

Typechecks my cabal project.

Actual behaviour

haskell-language-server and cabal are both available in the environment via direnv/envrc-mode. The lsp logs show that haskell-language-server can be found.. but something goes badly wrong..

Include debug information

Emacs buffer *lsp-haskell::stderr*:

haskell-language-server version: 1.4.0.0 (GHC: 8.10.7) (PATH: /nix/store/l4b2gn9h5w1c4rffbr69dkf0k37s5hxq-haskell-language-server-1.4.0.0/bin/haskell-language-server)
Starting (haskell-language-server)LSP server...
  with arguments: GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = True, argsLogFile = Just "/tmp/hls.log", argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "pragmas",PluginId "floskell",PluginId "fourmolu",PluginId "tactics",PluginId "ormolu",PluginId "stylish-haskell",PluginId "retrie",PluginId "brittany",PluginId "callHierarchy",PluginId "class",PluginId "haddockComments",PluginId "eval",PluginId "importLens",PluginId "refineImports",PluginId "moduleName",PluginId "hlint",PluginId "splice",PluginId "ghcide-hover-and-symbols",PluginId "ghcide-code-actions-imports-exports",PluginId "ghcide-code-actions-type-signatures",PluginId "ghcide-code-actions-bindings",PluginId "ghcide-code-actions-fill-holes",PluginId "ghcide-completions",PluginId "ghcide-type-lenses",PluginId "ghcide-core"]
  in directory: /home/jer/robo-actuary
 Starting LSP server...
If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
Started LSP server in 0.03s
setInitialDynFlags cradle: Cradle {cradleRootDir = "", cradleOptsProg = CradleAction: Cabal}
Couldn't load cradle for libdir: (CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitSuccess, cradleErrorStderr = ["Couldn't execute cabal --builddir=/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656 v2-exec --with-compiler /home/jer/.cache/hie-bios/wrapper-13a09b18ea883dd377d59db5e821a86b ghc -v0 -- --print-libdir"]},"/home/jer/robo-actuary",Nothing,Cradle {cradleRootDir = "", cradleOptsProg = CradleAction: Cabal})
Output from setting up the cradle Cradle {cradleRootDir = "", cradleOptsProg = CradleAction: Cabal}
jneira commented 2 years ago

hi, thanks for the bug report, the error should have included the error from the cabal ... v2-exec ghc -v0 -- --print-libdir, what happens if you run the exact command shown in the error in a shell?

jerbaroo commented 2 years ago

thanks for your time. The output of the command:

cabal --builddir=/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656 v2-exec --with-compiler /home/jer/.cache/hie-bios/wrapper-13a09b18ea883dd377d59db5e821a86b ghc -v0 -- --print-libdir

was:

/nix/store/3w3vvwl4fyirncd9xhhbqfzffjmnl13b-ghc-shell-for-packages-ghc-8.10.4-env/lib/ghc-8.10.4
jerbaroo commented 2 years ago

Some files show this error at the top (screenshot of Doom emacs):

image

fendor commented 2 years ago

Hi!

The cradleRootDir = "" looks slightly weird. Maybe a culprit?

Also, what is your cabal version? Do you have a hie.yaml? (in your project root, if you can't find one, totally fine.) Does your project compile in general?

Did you run cabal --builddir=/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656 v2-exec --with-compiler /home/jer/.cache/hie-bios/wrapper-13a09b18ea883dd377d59db5e821a86b ghc -v0 -- --print-libdir in the root of your project? What is curious is that your logs above claim haskell-lanuage-server-8.10.7 but now the reported ghc version is 8.10.4. Did you run the command in the same shell?

Please, also provide the logs of haskell-language-server --debug <some-file-name-in-your-project>.

jerbaroo commented 2 years ago

What is curious is that your logs above claim haskell-lanuage-server-8.10.7 but now the reported ghc version is 8.10.4. Did you run the command in the same shell?

I believe I have managed to get both HLS and GHC to the same version: 8.10.7

N cabal --builddir=/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656 v2-exec --with-compiler /home/jer/.cache/hie-bios/wrapper-13a09b18ea883dd377d59db5e821a86b ghc -v0 -- --print-libdir

/nix/store/44hsjv04vwcp9zmg065v2l2kc9qzvvg8-ghc-shell-for-packages-ghc-8.10.7-env/lib/ghc-8.10.7

jerbaroo commented 2 years ago

The current *lsp-haskell:stderr* output is:

Consulting the cradle to get project GHC version...
Project GHC version: 8.10.7
haskell-language-server exe candidates: ["haskell-language-server-8.10.7","haskell-language-server"]
Launching haskell-language-server exe at:/home/jer/.nix-profile/bin/haskell-language-server-8.10.7
haskell-language-server version: 1.4.0.0 (GHC: 8.10.7) (PATH: /nix/store/l4b2gn9h5w1c4rffbr69dkf0k37s5hxq-haskell-language-server-1.4.0.0/bin/haskell-language-server)
Starting (haskell-language-server)LSP server...
  with arguments: GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = True, argsLogFile = Just "/tmp/hls.log", argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "pragmas",PluginId "floskell",PluginId "fourmolu",PluginId "tactics",PluginId "ormolu",PluginId "stylish-haskell",PluginId "retrie",PluginId "brittany",PluginId "callHierarchy",PluginId "class",PluginId "haddockComments",PluginId "eval",PluginId "importLens",PluginId "refineImports",PluginId "moduleName",PluginId "hlint",PluginId "splice",PluginId "ghcide-hover-and-symbols",PluginId "ghcide-code-actions-imports-exports",PluginId "ghcide-code-actions-type-signatures",PluginId "ghcide-code-actions-bindings",PluginId "ghcide-code-actions-fill-holes",PluginId "ghcide-completions",PluginId "ghcide-type-lenses",PluginId "ghcide-core"]
  in directory: /home/jer/robo-actuary
 Starting LSP server...
If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option!
Started LSP server in 0.01s
setInitialDynFlags cradle: Cradle {cradleRootDir = "", cradleOptsProg = CradleAction: Cabal}
Couldn't load cradle for libdir: (CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitSuccess, cradleErrorStderr = ["Couldn't execute cabal --builddir=/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656 v2-exec --with-compiler /home/jer/.cache/hie-bios/wrapper-13a09b18ea883dd377d59db5e821a86b ghc -v0 -- --print-libdir"]},"/home/jer/robo-actuary",Nothing,Cradle {cradleRootDir = "", cradleOptsProg = CradleAction: Cabal})
Output from setting up the cradle Cradle {cradleRootDir = "/home/jer/robo-actuary", cradleOptsProg = CradleAction: Cabal}
haskell-language-server-wrapper: callProcess: /home/jer/.nix-profile/bin/haskell-language-server-8.10.7 "--lsp" "-d" "-l" "/tmp/hls.log" (exit -11): failed

Process lsp-haskell stderr finished
jerbaroo commented 2 years ago

Also, what is your cabal version? Do you have a hie.yaml? (in your project root, if you can't find one, totally fine.) Does your project compile in general?

> cabal --version
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library

I have a hie.yaml generated with gen-hie --cabal > hie.yaml.

The project compiles and passes tests.

jerbaroo commented 2 years ago
> haskell-language-server --debug tt-common/src/TT/Time.hs
haskell-language-server version: 1.6.1.0 (GHC: 8.10.7) (PATH: /nix/store/12igs7v761295dwpanhgr9svv3x0irkx-haskell-language-server-exe-haskell-language-server-1.6.1.0/bin/haskell-language-server)
2022-02-07 12:00:13.794794068 [ThreadId 4] INFO hls:    Logging heap statistics every 60.00s
 ghcide setup tester in /home/jer/robo-actuary.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/jer/robo-actuary
Found 1 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  (/home/jer/robo-actuary/hie.yaml)Step 3/4: Initializing the IDE2022-02-07 12:00:13.804951594 [ThreadId 8] DEBUG hls:   Initializing exports map from hiedb2022-02-07 12:00:13.811894525 [ThreadId 4] DEBUG hls:   Shake session initializedStep 4/4: Type checking the files2022-02-07 12:00:13.818573078 [ThreadId 32] INFO hls:   Consulting the cradle for "tt-common/src/TT/Time.hs"2022-02-07 12:00:13.819968946 [ThreadId 32] DEBUG hls:  Output from setting up the cradle Cradle {cradleRootDir = "/home/jer/robo-actuary", cradleOptsProg = CradleAction: Cabal}2022-02-07 12:00:13.911301745 [ThreadId 8] DEBUG hls:   Done initializing exports map from hiedb (4520)2022-02-07 12:00:14.087926411 [ThreadId 38] INFO hie-bios:      Build profile: -w ghc-8.10.7 -O12022-02-07 12:00:14.088099257 [ThreadId 38] INFO hie-bios:      In order, the following will be built (use -v for more details):2022-02-07 12:00:14.088330217 [ThreadId 38] INFO hie-bios:       - tt-common-0.1.0.0 (lib) (file /home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/db-lib-0.1.0.0/cache/build changed)
2022-02-07 12:00:14.234810718 [ThreadId 38] INFO hie-bios:      Preprocessing library for tt-common-0.1.0.0..
2022-02-07 12:00:14.690715052 [ThreadId 32] DEBUG hls:  Session loading result: Right (ComponentOptions {componentOptions = ["-fbuilding-cabal-package","-O0","-outputdir","/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build","-odir","/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build","-hidir","/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build","-stubdir","/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build","-i","-i/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build","-isrc","-i/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build/autogen","-i/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build/global-autogen","-I/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build/autogen","-I/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build/global-autogen","-I/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build","-optP-include","-optP/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/build/autogen/cabal_macros.h","-this-unit-id","tt-common-0.1.0.0-inplace","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/jer/.cabal/store/ghc-8.10.7/package.db","-package-db","/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/packagedb/ghc-8.10.7","-package-db","/home/jer/.cache/hie-bios/dist-robo-actuary-22f3244f040f6fd209eaeca909468656/build/x86_64-linux/ghc-8.10.7/tt-common-0.1.0.0/package.conf.inplace","-package-id","aeson-1.5.6.0-DkwLMaMFAoKEbTeMR8x6ex","-package-id","attoparsec-0.13.2.5-8izDPW0DwnMA1uBRNCYnOn","-package-id","base-4.14.3.0","-package-id","beam-core-0.9.1.0-LIkYqxPEkiG64wewjmJvLn","-package-id","bytestring-0.10.12.0","-package-id","casing-0.1.4.1-1AxxkpcOOOtCySgqIdcwn9","-package-id","cassava-0.5.2.0-8Di14682zcU6LXbcrzApA0","-package-id","containers-0.6.5.1","-package-id","db-lib-0.1.0.0-inplace","-package-id","directory-1.3.6.0","-package-id","exceptions-0.10.4-GZzIP1JaPeSLBhL2GS4vh1","-package-id","extra-1.7.9-H13SV8oiNFv6jqPPHm2cAt","-package-id","lens-4.19.2-3vJ4Zk2fLvKScRkYOJ0Nj","-package-id","moving-averages-0.2.0.0-G7MnCtB3u0o11U9MJfQWLf","-package-id","mtl-2.2.2","-package-id","optics-core-0.4-15IQKU0DHpBBmSPCGR7eXg","-package-id","path-0.8.0-Go5nPS2OEloEgdJyEvqMQz","-package-id","pretty-simple-4.0.0.0-KQSse8zOzjN7BoDiYtj29L","-package-id","pretty-terminal-0.1.0.0-1FPUTuYCfk9HIha5CUVkkq","-package-id","random-1.2.0-GAV679NMk7iDELNoxF99p4","-package-id","safe-exceptions-0.1.7.2-1dt8YmdvO5WFTqpe62pIFN","-package-id","scientific-0.3.7.0-EUZZqwADHqZGCpstxNmUR7","-package-id","servant-0.18.3-J0zDumMaqE46C9BI0iMb7r","-package-id","servant-client-0.18.3-ChABTdwePbM2dfJoZWvJos","-package-id","servant-server-0.18.3-IrG6ewZN4lE5yMywtkZM2m","-package-id","strict-0.4.0.1-1aHAlXNc3zpJLTL7d8gALJ","-package-id","swagger2-2.6-8XNX7MMEuLrAcjus0u5qCL","-package-id","text-1.2.4.1","-package-id","time-1.9.3","-package-id","uuid-1.3.15-51F3dqkCJgW4s2qbXObXVT","-package-id","validity-0.11.0.1-ICS6AfMMBO7KaoWEjBj3T1","-package-id","validity-text-0.3.1.2-CJLxWbJv9hN3Orr3ppBUDE","-package-id","validity-time-0.4.0.0-4w18bAIQBvc3gxEqe22coP","-package-id","validity-uuid-0.1.0.3-KFu69ACzMTT6vy4cNRBM9n","-package-id","witch-0.3.4.0-4n9LBuofOil2G5I0bsXdXI","-XHaskell2010","-XLambdaCase","-XOverloadedLabels","-XOverloadedStrings","-XBangPatterns","-XBinaryLiterals","-XConstrainedClassMethods","-XConstraintKinds","-XDeriveDataTypeable","-XDeriveFoldable","-XDeriveFunctor","-XDeriveGeneric","-XDeriveLift","-XDeriveTraversable","-XEmptyCase","-XEmptyDataDeriving","-XExistentialQuantification","-XExplicitForAll","-XFlexibleContexts","-XFlexibleInstances","-XGADTSyntax","-XGeneralisedNewtypeDeriving","-XHexFloatLiterals","-XImportQualifiedPost","-XInstanceSigs","-XKindSignatures","-XMultiParamTypeClasses","-XNamedFieldPuns","-XNamedWildCards","-XNumericUnderscores","-XPolyKinds","-XPostfixOperators","-XRankNTypes","-XScopedTypeVariables","-XStandaloneDeriving","-XStandaloneKindSignatures","-XTupleSections","-XTypeApplications","-XTypeOperators","-XTypeSynonymInstances","TT.File","TT.Log","TT.Log.Class","TT.Log.Db","TT.Log.Log","TT.Log.Monad","TT.Log.Schema","TT.Log.Schema.Log","TT.Log.Schema.Tag","TT.Log.Span","TT.Time","TT.Log.Types","TT.Member","TT.Common.ApiSchema","TT.Common.Error","TT.Common.FinanceUtils","TT.Common.MapUtils","TT.Common.Type.AuthToken","TT.Common.Type.BaseUrl","TT.Common.Type.Port","TT.Common.Token","TT.Common.Uuid","TT.Common.Witch","Paths_tt_common","-hide-all-packages","-Wall"], componentRoot = "/home/jer/robo-actuary/tt-common", componentDependencies = ["tt-common/tt-common.cabal","cabal.project","cabal.project.local"]},"/nix/store/1clrin7r4zb2kszx6b1yq4aq3p2zks32-ghc-shell-for-packages-ghc-8.10.7-env/lib/ghc-8.10.7")
2022-02-07 12:00:14.832877848 [ThreadId 32] INFO hls:   Using interface files cache dir: /home/jer/.cache/ghcide/tt-common-0.1.0.0-inplace-4a7506e943ad8e4f370a8e039aff6d07ba46d265
2022-02-07 12:00:14.833216139 [ThreadId 32] INFO hls:   Making new HscEnv[tt-common-0.1.0.0-inplace]
2022-02-07 12:00:14.859957032 [ThreadId 32] DEBUG hls:  New Component Cache HscEnvEq: (([],Just HscEnvEq 5),fromList [("/home/jer/robo-actuary/hie.yaml",Just 2022-02-07 14:20:22.561262733 UTC),("cabal.project",Just 2022-02-04 14:44:59.245825173 UTC),("cabal.project.local",Nothing),("tt-common/tt-common.cabal",Just 2022-02-01 14:43:38.660359898 UTC)])
2022-02-07 12:00:14.896087691 [ThreadId 32] DEBUG hls:  Known files updated: fromList [(TargetModule TT.Common.Token,fromList ["/home/jer/robo-actuary/tt-common/src/TT/Common/Token.hs"]),<<REMOVED_FOR_PRIVACY>>]
2022-02-07 12:00:14.896607633 [ThreadId 11] DEBUG hls:  Finishing build session(exception: AsyncCancelled)
2022-02-07 12:00:14.896717794 [ThreadId 32] DEBUG hls:  Restarting build session due to new component with queue ["User TypeCheck"] for keys [GetKnownTargets; ,GhcSessionIO; ] (aborting the previous one took 0.00s)
2022-02-07 12:00:14.896955093 [ThreadId 53] DEBUG hls:  hlint:getIdeas:file:NormalizedFilePath "/home/jer/robo-actuary/tt-common/src/TT/Time.hs"
2022-02-07 12:00:16.30002739 [ThreadId 60] INFO hls:    finish: User TypeCheck (took 1.40s)
2022-02-07 12:00:16.610005173 [ThreadId 779] INFO hls:  finish: GetHie (took 0.29s)
2022-02-07 12:00:16.610355138 [ThreadId 788] INFO hls:  finish: GenerateCore (took 0.00s)

Completed (1 file worked, 0 files failed)
jerbaroo commented 2 years ago

After upgrading a bunch of things (HLS, emacs, NixOS, GHC) this is no longer an issue.