Skip to content

Eval Plugin cannot handle internal library imports #509

Open
@konn

Description

@konn

Subject of the issue

Similar to already fixed #485, Eval plugin cannot handle imports from local internal libraries.
In particular, the issue will occur when we have a package with three components:

  • a core unnamed library
  • another internal library (EDIT: it seems internal library doesn't have to depend on a core library)
  • An executable depending on both libraries.

As with #485, this issue should be a bug in ghcide's GhcSessionDeps, but I have no idea to test GhcSessionDeps with this situation, since the HLS and ghcide works if we don't do any Eval invocation, so I decided to report this error here at first; sorry for the inconvenience.

Your environment

  • Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools

    $ ~/Library/Application\ Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-0.5.1-darwin --probe-tools
    haskell-language-server version: 0.5.1.0 (GHC: 8.10.1) (PATH: /Users/hiromi/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-wrapper-0.5.1-darwin) (GIT hash: e3fe0e7546aa91e44cc56cfe8ec078a026cf533a)
    Tool versions found on the $PATH
    cabal:          3.2.0.0
    stack:          2.5.1
    ghc:            8.6.5
  • Which lsp-client do you use: VSCode

  • Describe your project: repro repo here

  • Contents of hie.yaml: as contained above:

    cradle:
      cabal:
        - path: "src"
          component: "lib:hls-eval-internal-libs"
        - path: "internals"
          component: "lib:internals"
        - path: "app/Main.hs"
          component: "exe:hls-eval-internal-libs-exe"

    N.B. You need to use cabal cradle, since the current stack doesn't support internal libraries.

Steps to reproduce

  1. Open internals/InternalLib.hs

  2. Open app/Main.hs

    module Main where
    
    import Lib ( someFunc )
    import InternalLib ( internal )
    
    -- >>> internal
    
    main :: IO ()
    main = do
      print internal
      someFunc
  3. Click Evaluate... code lens.

Expected behaviour

The line -- "This is internal" gets added right below the doctest comment.

Actual behaviour

HLS silently fails with the following error dumped to OUTPUT region:

[Error - 22:58:11] Request workspace/executeCommand failed.
  Message: These modules are needed for compilation but not listed in your .cabal file's other-modules: 
    InternalLibCould not load module ‘InternalLib’

On the other hand, if we just open app/Main.hs ONLY and NOT internals/InternalLib.hs, then the Eval Plugin successfully prints the comment -- "This is internal".

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output:
ebug .
haskell-language-server version: 0.5.1.0 (GHC: 8.6.5) (PATH: /Users/hiromi/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.1-darwin-8.6.5) (GIT hash: e3fe0e7546aa91e44cc56cfe8ec078a026cf533a)
(haskell-language-server)Ghcide setup tester in /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Tool versions found on the $PATH
cabal:          3.2.0.0
stack:          2.5.1
ghc:            8.6.5


Step 1/4: Finding files to test in /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs
Found 4 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
[INFO] Consulting the cradle for "app/Main.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
> Resolving dependencies...
> Build profile: -w ghc-8.6.5 -O1
> In order, the following will be built (use -v for more details):
>  - hls-eval-internal-libs-0.1.0.0 (lib) (first run)
>  - hls-eval-internal-libs-0.1.0.0 (lib:internals) (first run)
>  - hls-eval-internal-libs-0.1.0.0 (exe:hls-eval-internal-libs-exe) (first run)
> Configuring library for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library for hls-eval-internal-libs-0.1.0.0..
> Building library for hls-eval-internal-libs-0.1.0.0..
> [2 of 2] Compiling Paths_hls_eval_internal_libs ( /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/dist-newstyle/build/x86_64-osx/ghc-8.6.5/hls-eval-internal-libs-0.1.0.0/build/autogen/Paths_hls_eval_internal_libs.hs, /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/dist-newstyle/build/x86_64-osx/ghc-8.6.5/hls-eval-internal-libs-0.1.0.0/build/Paths_hls_eval_internal_libs.o )
> Configuring library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Building library 'internals' for hls-eval-internal-libs-0.1.0.0..
> [1 of 1] Compiling InternalLib      ( internals/InternalLib.hs, /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/dist-newstyle/build/x86_64-osx/ghc-8.6.5/hls-eval-internal-libs-0.1.0.0/l/internals/build/internals/InternalLib.o )
> Configuring executable 'hls-eval-internal-libs-exe' for hls-eval-internal-libs-0.1.0.0..
> Warning: The package has an extraneous version range for a dependency on an
> internal library: hls-eval-internal-libs -any && ==0.1.0.0 && ==0.1.0.0. This
> version range includes the current package but isn't needed as the current
> package's library will always be used.
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing executable 'hls-eval-internal-libs-exe' for hls-eval-internal-libs-0.1.0.0..
[INFO] Using interface files cache dir: /Users/hiromi/.cache/ghcide/main-051784bafe383be2c17068b2f78e2c930f7975cf
[INFO] Making new HscEnv[main]
[INFO] Consulting the cradle for "Setup.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
File:     /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/Setup.hs
Hidden:   no
Range:    1:0-2:0
Source:   cradle
Severity: DsError
Message: 
  Multi Cradle: No prefixes matched
  pwd: /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs
  filepath: /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/Setup.hs
  prefixes:
  ("src",Cabal {component = Just "lib:hls-eval-internal-libs"})
  ("internals",Cabal {component = Just "lib:internals"})
  ("app/Main.hs",Cabal {component = Just "exe:hls-eval-internal-libs-exe"})
[INFO] Consulting the cradle for "src/Lib.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
> Resolving dependencies...
> Build profile: -w ghc-8.6.5 -O1
> In order, the following will be built (use -v for more details):
>  - hls-eval-internal-libs-0.1.0.0 (lib) (configuration changed)
> Configuring library for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library for hls-eval-internal-libs-0.1.0.0..
[INFO] Using interface files cache dir: /Users/hiromi/.cache/ghcide/hls-eval-internal-libs-0.1.0.0-inplace-198a34380b305419edb786973492d59eb812ec44
[INFO] Using interface files cache dir: /Users/hiromi/.cache/ghcide/main-84a044c6cfece52a6d54376562efbb59ff1b1fda
[INFO] Making new HscEnv[hls-eval-internal-libs-0.1.0.0-inplace,main]
[INFO] Consulting the cradle for "Setup.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
[INFO] Consulting the cradle for "internals/InternalLib.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
> Resolving dependencies...
> Build profile: -w ghc-8.6.5 -O1
> In order, the following will be built (use -v for more details):
>  - hls-eval-internal-libs-0.1.0.0 (lib:internals) (configuration changed)
> Configuring library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library 'internals' for hls-eval-internal-libs-0.1.0.0..
[INFO] Using interface files cache dir: /Users/hiromi/.cache/ghcide/hls-eval-internal-libs-0.1.0.0-inplace-internals-1c7c94e78b66d6d4dfd2342d222008d473884ed3
[INFO] Using interface files cache dir: /Users/hiromi/.cache/ghcide/hls-eval-internal-libs-0.1.0.0-inplace-1c7c94e78b66d6d4dfd2342d222008d473884ed3
[INFO] Using interface files cache dir: /Users/hiromi/.cache/ghcide/main-32803953539d23a7024faadb8855b9fe307e9259
[INFO] Making new HscEnv[hls-eval-internal-libs-0.1.0.0-inplace-internals,hls-eval-internal-libs-0.1.0.0-inplace,main]
[INFO] Consulting the cradle for "Setup.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
Files that failed:
[INFO] finish: User TypeCheck (took 0.04s) * /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/Setup.hs


Completed (3 files worked, 1 file failed)

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs:
[client] run command: "/Users/hiromi/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.1-darwin-8.6.5 --lsp"
[client] debug command: "/Users/hiromi/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.1-darwin-8.6.5 --lsp"
[client] server cwd: undefined
haskell-language-server version: 0.5.1.0 (GHC: 8.6.5) (PATH: /Users/hiromi/Library/Application Support/Code/User/globalStorage/haskell.haskell/haskell-language-server-0.5.1-darwin-8.6.5) (GIT hash: e3fe0e7546aa91e44cc56cfe8ec078a026cf533a)
Starting (haskell-language-server)LSP server...
  with arguments: LspArguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False}
  with plugins: [PluginId "brittany",PluginId "eval",PluginId "floskell",PluginId "fourmolu",PluginId "ghcide",PluginId "importLens",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "stylish-haskell",PluginId "tactic"]
  in directory: /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs
If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!
 Started LSP server in 0.00s
2020-10-17 23:07:16.648838 [ThreadId 29] - Registering ide configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 1885191613013803323 "file:///Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs"], clientSettings = hashed Nothing}
2020-10-17 23:07:16.650142 [ThreadId 29] - Configuration changed: Object (fromList [("haskell",Object (fromList [("hlint",Object (fromList [("logLevel",String "info"),("executablePath",String "/Users/hiromi/.local/bin/hlint")])),("logFile",String ""),("updateBehavior",String "keep-up-to-date"),("hlintOn",Bool True),("formatOnImportOn",Bool True),("indentationRules",Object (fromList [("enabled",Bool True)])),("liquidOn",Bool False),("languageServerVariant",String "haskell-language-server"),("serverExecutablePath",String ""),("diagnosticsOnChange",Bool True),("completionSnippetsOn",Bool True),("maxNumberOfProblems",Number 100.0),("formattingProvider",String "none"),("trace",Object (fromList [("server",String "off")]))]))])
2020-10-17 23:07:16.651316 [ThreadId 29] - Opened text document: file:///Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/internals/InternalLib.hs
2020-10-17 23:07:16.65308 [ThreadId 97] - Consulting the cradle for "internals/InternalLib.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
2020-10-17 23:07:16.911003 [ThreadId 112] - Plugin.makeCodeLens (ideLogger)
> Resolving dependencies...
> Build profile: -w ghc-8.6.5 -O1
> In order, the following will be built (use -v for more details):
>  - hls-eval-internal-libs-0.1.0.0 (lib:internals) (configuration changed)
> Configuring library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library 'internals' for hls-eval-internal-libs-0.1.0.0..
2020-10-17 23:07:23.278934 [ThreadId 97] - Using interface files cache dir: /Users/hiromi/.cache/ghcide/hls-eval-internal-libs-0.1.0.0-inplace-internals-1c7c94e78b66d6d4dfd2342d222008d473884ed3
2020-10-17 23:07:23.279216 [ThreadId 97] - Making new HscEnv[hls-eval-internal-libs-0.1.0.0-inplace-internals]
2020-10-17 23:07:23.396025 [ThreadId 216] - finish: codeLens (took 0.03s)
2020-10-17 23:07:23.396834 [ThreadId 225] - finish:  (took 0.00s)
2020-10-17 23:07:25.27093 [ThreadId 29] - Opened text document: file:///Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/app/Main.hs
2020-10-17 23:07:25.272736 [ThreadId 264] - Consulting the cradle for "app/Main.hs"
Output from setting up the cradle Cradle {cradleRootDir = "/Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs", cradleOptsProg = CradleAction: Cabal}
2020-10-17 23:07:25.276909 [ThreadId 307] - DocumentHighlight request at position 8:10 in file: /Users/hiromi/Documents/Programming/Haskell/git/hls-eval-internal-libs/app/Main.hs
2020-10-17 23:07:25.502939 [ThreadId 313] - Plugin.makeCodeLens (ideLogger)
> Resolving dependencies...
> Build profile: -w ghc-8.6.5 -O1
> In order, the following will be built (use -v for more details):
>  - hls-eval-internal-libs-0.1.0.0 (lib) (configuration changed)
>  - hls-eval-internal-libs-0.1.0.0 (lib:internals) (configuration changed)
>  - hls-eval-internal-libs-0.1.0.0 (exe:hls-eval-internal-libs-exe) (configuration changed)
> Configuring library for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library for hls-eval-internal-libs-0.1.0.0..
> Building library for hls-eval-internal-libs-0.1.0.0..
> Configuring library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Building library 'internals' for hls-eval-internal-libs-0.1.0.0..
> Configuring executable 'hls-eval-internal-libs-exe' for hls-eval-internal-libs-0.1.0.0..
> Warning: The package has an extraneous version range for a dependency on an
> internal library: hls-eval-internal-libs -any && ==0.1.0.0 && ==0.1.0.0. This
> version range includes the current package but isn't needed as the current
> package's library will always be used.
> Warning: Packages using 'cabal-version: >= 1.10' must specify the
> 'default-language' field for each component (e.g. Haskell98 or Haskell2010).
> If a component uses different languages in different modules then list the
> other ones in the 'other-languages' field.
> Preprocessing executable 'hls-eval-internal-libs-exe' for hls-eval-internal-libs-0.1.0.0..
2020-10-17 23:07:38.715133 [ThreadId 264] - Using interface files cache dir: /Users/hiromi/.cache/ghcide/main-ae34532819c30d0be9622a694c09dd8fbc7b1a4e
2020-10-17 23:07:38.715394 [ThreadId 264] - Using interface files cache dir: /Users/hiromi/.cache/ghcide/hls-eval-internal-libs-0.1.0.0-inplace-internals-051784bafe383be2c17068b2f78e2c930f7975cf
2020-10-17 23:07:38.715498 [ThreadId 264] - Making new HscEnv[main,hls-eval-internal-libs-0.1.0.0-inplace-internals]
2020-10-17 23:07:38.819148 [ThreadId 427] - finish: CodeAction (took 0.01s)
2020-10-17 23:07:38.851192 [ThreadId 521] - finish: codeLens (took 0.04s)
2020-10-17 23:07:38.852059 [ThreadId 533] - finish:  (took 0.00s)
2020-10-17 23:07:39.027137 [ThreadId 566] - finish: CodeAction:PackageExports (took 0.21s)
2020-10-17 23:07:39.027581 [ThreadId 567] - finish: importLens (took 0.00s)
2020-10-17 23:07:39.02801 [ThreadId 569] - finish: retrie (took 0.00s)
2020-10-17 23:07:39.028468 [ThreadId 571] - finish: tactic (took 0.00s)
2020-10-17 23:07:39.028804 [ThreadId 577] - finish: tactic (took 0.00s)
2020-10-17 23:07:39.028915 [ThreadId 578] - finish: tactic (took 0.00s)
2020-10-17 23:07:40.912259 [ThreadId 585] - finish: runEvalCmd.ghcSession (took 0.00s)
2020-10-17 23:07:40.912479 [ThreadId 587] - finish: runEvalCmd.getModSummary (took 0.00s)
[Error - 23:07:40] Request workspace/executeCommand failed.
  Message: These modules are needed for compilation but not listed in your .cabal file's other-modules: 
    InternalLibCould not load module ‘InternalLib’
It is a member of the hidden package ‘hls-eval-internal-libs-0.1.0.0’.
Perhaps you need to add ‘hls-eval-internal-libs’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
  Code: -32603 

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: hls-eval-pluginmulti-componentIssues relating to multi-component supporttype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions