haskell / haskell-language-server

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

Unable to load modules in haskell-language-server/plugins/default #1394

Open berberman opened 3 years ago

berberman commented 3 years ago

HLS version:

haskell-language-server version: 0.9.0.0 (GHC: 8.10.3) (PATH: /home/berberman/.cabal/store/ghc-8.10.3/haskell-language-server-0.9.0.0-fc61519dda1a1498575dccc3fb04c9f3a1600a61493f968ee632374480d5dcd6/bin/haskell-language-server)
Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      Not found
ghc:        8.10.3

I found HLS could not load modules in this directory: for example, I opened Example.hs, and I got

Multi Cradle: No prefixes matched
pwd: /home/berberman/Desktop/haskell/haskell-language-server
filepath: /home/berberman/Desktop/haskell/haskell-language-server/plugins/default/src/Ide/Plugin/Example.hs
prefixes:
("./ghcide/src",Cabal {component = Just "lib:ghcide"})
("./ghcide/session-loader",Cabal {component = Just "lib:ghcide"})
("./ghcide/test/preprocessor/Main.hs",Cabal {component = Just "ghcide:exe:ghcide-test-preprocessor"})
("./ghcide/bench/hist/Main.hs",Cabal {component = Just "ghcide:bench:benchHist"})
("./ghcide/bench/lib/Main.hs",Cabal {component = Just "ghcide:bench:benchHist"})
("./ghcide/bench/hist/Experiments/Types.hs",Cabal {component = Just "ghcide:bench:benchHist"})
("./ghcide/bench/lib/Experiments/Types.hs",Cabal {component = Just "ghcide:bench:benchHist"})
("./ghcide/exe/Main.hs",Cabal {component = Just "ghcide:exe:ghcide"})
("./ghcide/exe/Arguments.hs",Cabal {component = Just "ghcide:exe:ghcide"})
("./ghcide/exe/Paths_ghcide.hs",Cabal {component = Just "ghcide:exe:ghcide"})
("./ghcide/test/cabal",Cabal {component = Just "ghcide:test:ghcide-tests"})
("./ghcide/test/exe",Cabal {component = Just "ghcide:test:ghcide-tests"})
("./ghcide/test/src",Cabal {component = Just "ghcide:test:ghcide-tests"})
("./ghcide/bench/lib",Cabal {component = Just "ghcide:test:ghcide-tests"})
("./ghcide/bench/lib/Main.hs",Cabal {component = Just "ghcide:exe:ghcide-bench"})
("./ghcide/bench/exe/Main.hs",Cabal {component = Just "ghcide:exe:ghcide-bench"})
("./ghcide/bench/lib/Experiments.hs",Cabal {component = Just "ghcide:exe:ghcide-bench"})
("./ghcide/bench/lib/Experiments/Types.hs",Cabal {component = Just "ghcide:exe:ghcide-bench"})
("./ghcide/bench/exe/Experiments.hs",Cabal {component = Just "ghcide:exe:ghcide-bench"})
("./ghcide/bench/exe/Experiments/Types.hs",Cabal {component = Just "ghcide:exe:ghcide-bench"})
("./src",Cabal {component = Just "lib:haskell-language-server"})
("./exe/Main.hs",Cabal {component = Just "haskell-language-server:exe:haskell-language-server"})
("./exe/Plugins.hs",Cabal {component = Just "haskell-language-server:exe:haskell-language-server"})
("./exe/Wrapper.hs",Cabal {component = Just "haskell-language-server:exe:haskell-language-server-wrapper"})
("./test/functional",Cabal {component = Just "haskell-language-server:test:func-test"})
("./plugins/hls-tactics-plugin/src",Cabal {component = Just "haskell-language-server:test:func-test"})
("./plugins/hls-eval-plugin/test",Cabal {component = Just "haskell-language-server:test:func-test"})
("./plugins/hls-splice-plugin/src",Cabal {component = Just "haskell-language-server:test:func-test"})
("./plugins/hls-eval-plugin/src",Cabal {component = Just "haskell-language-server:test:func-test"})
("./test/wrapper",Cabal {component = Just "haskell-language-server:test:wrapper-test"})
("./hie-compat/src-ghc86",Cabal {component = Just "lib:hie-compat"})
("./hie-compat/src-ghc88",Cabal {component = Just "lib:hie-compat"})
("./hie-compat/src-reexport",Cabal {component = Just "lib:hie-compat"})
("./hie-compat/src-ghc810",Cabal {component = Just "lib:hie-compat"})
("./hie-compat/src-reexport",Cabal {component = Just "lib:hie-compat"})
("./hls-plugin-api/src",Cabal {component = Just "lib:hls-plugin-api"})
("./plugins/hls-class-plugin/src",Cabal {component = Just "lib:hls-class-plugin"})
("./plugins/hls-eval-plugin/src",Cabal {component = Just "lib:hls-eval-plugin"})
("./plugins/hls-explicit-imports-plugin/src",Cabal {component = Just "lib:hls-explicit-imports-plugin"})
("./plugins/hls-haddock-comments-plugin/src",Cabal {component = Just "lib:hls-haddock-comments-plugin"})
("./plugins/hls-hlint-plugin/src",Cabal {component = Just "lib:hls-hlint-plugin"})
("./plugins/hls-retrie-plugin/src",Cabal {component = Just "lib:hls-retrie-plugin"})
("./plugins/hls-splice-plugin/src",Cabal {component = Just "lib:hls-splice-plugin"})
("./plugins/hls-tactics-plugin/src",Cabal {component = Just "lib:hls-tactics-plugin"})
("./plugins/hls-tactics-plugin/test",Cabal {component = Just "hls-tactics-plugin:test:tests"})
("./shake-bench/src",Cabal {component = Just "lib:shake-bench"})

The cradles generated by implicit-hie didn't include this file. However,

$ hie-bios debug plugins/default/src/Ide/Plugin/Example.hs

worked without error, and further, after I changed loadImplicitHieCradle to HieBios.loadImplicitCradle at

https://github.com/haskell/haskell-language-server/blob/c95b0766fe363a4de90e4532204e05bcc092ab59/ghcide/session-loader/Development/IDE/Session.hs#L117

and

https://github.com/haskell/haskell-language-server/blob/c95b0766fe363a4de90e4532204e05bcc092ab59/ghcide/session-loader/Development/IDE/Session.hs#L389

i.e. using hie-bios to load the cradle rather than implicit-hie-cradle, I could load these modules successfully. So I think this should be a bug in implicit-hie. It seems that implicit-hie doesn't support common stanzas, but after normalizing these parts (by running cabal format), the result is still inaccurate:

$ cabal format
$ gen-hie
cradle:
  cabal:
    - path: "./ghcide/src"
      component: "lib:ghcide"

    - path: "./ghcide/session-loader"
      component: "lib:ghcide"

    - path: "./ghcide/test/preprocessor/Main.hs"
      component: "ghcide:exe:ghcide-test-preprocessor"

    - path: "./ghcide/bench/hist/Main.hs"
      component: "ghcide:bench:benchHist"

    - path: "./ghcide/bench/lib/Main.hs"
      component: "ghcide:bench:benchHist"

    - path: "./ghcide/bench/hist/Experiments/Types.hs"
      component: "ghcide:bench:benchHist"

    - path: "./ghcide/bench/lib/Experiments/Types.hs"
      component: "ghcide:bench:benchHist"

    - path: "./ghcide/exe/Main.hs"
      component: "ghcide:exe:ghcide"

    - path: "./ghcide/exe/Arguments.hs"
      component: "ghcide:exe:ghcide"

    - path: "./ghcide/exe/Paths_ghcide.hs"
      component: "ghcide:exe:ghcide"

    - path: "./ghcide/test/cabal"
      component: "ghcide:test:ghcide-tests"

    - path: "./ghcide/test/exe"
      component: "ghcide:test:ghcide-tests"

    - path: "./ghcide/test/src"
      component: "ghcide:test:ghcide-tests"

    - path: "./ghcide/bench/lib"
      component: "ghcide:test:ghcide-tests"

    - path: "./ghcide/bench/lib/Main.hs"
      component: "ghcide:exe:ghcide-bench"

    - path: "./ghcide/bench/exe/Main.hs"
      component: "ghcide:exe:ghcide-bench"

    - path: "./ghcide/bench/lib/Experiments.hs"
      component: "ghcide:exe:ghcide-bench"

    - path: "./ghcide/bench/lib/Experiments/Types.hs"
      component: "ghcide:exe:ghcide-bench"

    - path: "./ghcide/bench/exe/Experiments.hs"
      component: "ghcide:exe:ghcide-bench"

    - path: "./ghcide/bench/exe/Experiments/Types.hs"
      component: "ghcide:exe:ghcide-bench"

    - path: "./src"
      component: "lib:haskell-language-server"

    - path: "./plugins/default/src/Main.hs"
      component: "haskell-language-server:exe:haskell-language-server"

    - path: "./plugins/default/src/Ide/Plugin/Brittany.hs"
      component: "haskell-language-server:exe:haskell-language-server"

    - path: "./exe/Wrapper.hs"
      component: "haskell-language-server:exe:haskell-language-server-wrapper"

    - path: "./test/utils"
      component: "haskell-language-server:test:func-test"

    - path: "./test/functional"
      component: "haskell-language-server:test:func-test"

    - path: "./plugins/hls-tactics-plugin/src"
      component: "haskell-language-server:test:func-test"

    - path: "./plugins/hls-eval-plugin/test"
      component: "haskell-language-server:test:func-test"

    - path: "./plugins/hls-splice-plugin/src"
      component: "haskell-language-server:test:func-test"

    - path: "./plugins/hls-eval-plugin/src"
      component: "haskell-language-server:test:func-test"

    - path: "./test/utils"
      component: "haskell-language-server:test:wrapper-test"

    - path: "./test/wrapper"
      component: "haskell-language-server:test:wrapper-test"

    - path: "./hie-compat/src-ghc86"
      component: "lib:hie-compat"

    - path: "./hie-compat/src-ghc88"
      component: "lib:hie-compat"

    - path: "./hie-compat/src-reexport"
      component: "lib:hie-compat"

    - path: "./hie-compat/src-ghc810"
      component: "lib:hie-compat"

    - path: "./hie-compat/src-reexport"
      component: "lib:hie-compat"

    - path: "./hls-plugin-api/src"
      component: "lib:hls-plugin-api"

    - path: "./plugins/hls-class-plugin/src"
      component: "lib:hls-class-plugin"

    - path: "./plugins/hls-eval-plugin/src"
      component: "lib:hls-eval-plugin"

    - path: "./plugins/hls-explicit-imports-plugin/src"
      component: "lib:hls-explicit-imports-plugin"

    - path: "./plugins/hls-haddock-comments-plugin/src"
      component: "lib:hls-haddock-comments-plugin"

    - path: "./plugins/hls-hlint-plugin/src"
      component: "lib:hls-hlint-plugin"

    - path: "./plugins/hls-retrie-plugin/src"
      component: "lib:hls-retrie-plugin"

    - path: "./plugins/hls-splice-plugin/src"
      component: "lib:hls-splice-plugin"

    - path: "./plugins/hls-tactics-plugin/src"
      component: "lib:hls-tactics-plugin"

    - path: "./plugins/hls-tactics-plugin/test"
      component: "hls-tactics-plugin:test:tests"

    - path: "./shake-bench/src"
      component: "lib:shake-bench"
berberman commented 3 years ago

@Ailrun was right, I overlooked default plugins at that time... https://github.com/haskell/haskell-language-server/issues/741#issuecomment-764745971

jneira commented 3 years ago

@berberman iguess it still is reproduced for the two modules which still life in default. If that is the case it would be great fill anisue in implicit hie, to investigate the cause tham may affect other projects.

Ailrun commented 3 years ago

@jneira Do we even need to leave them in default plugin directory? I mean, yes, this issue is still better to be fixed for other projects, but for HLS itself, I think we can either move those two example plugins into the src directory or into an example plugin package.

jneira commented 3 years ago

Sure, the correct place even without this bug would be in ./plugins/hls-example-plugin imo. But i would close this one when we have an issue tracking this upstream.

Ailrun commented 3 years ago

Yes, probably that will be better for this issue itself. I just wanted to be clear about HLS devs' problem.