Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval Plugin cannot handle internal library imports #509

Open
konn opened this issue Oct 17, 2020 · 7 comments
Open

Eval Plugin cannot handle internal library imports #509

konn opened this issue Oct 17, 2020 · 7 comments
Labels
component: hls-eval-plugin multi-component Issues relating to multi-component support type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@konn
Copy link
Collaborator

konn commented Oct 17, 2020

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 
@pepeiborra
Copy link
Collaborator

I think this an instance of https://github.com/haskell/ghcide#limitations-to-multi-component-support but we need to confirm this:

(EDIT: it seems internal library doesn't have to depend on a core library)

If there is no dependency then it is not an instance of the limitation linked above and might be an actual bug.

NB: #485 was not a bug with GhcSessionDeps

@jneira jneira added component: hls-eval-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Oct 18, 2020
@Profpatsch
Copy link

I’m running into the same issue. Is there a workaround?

@jneira
Copy link
Member

jneira commented Nov 8, 2021

There is no one afaik (but the obvius one, make modules available in other way and no use internal libs).
Maybe it worths to check if @fendor's wip improving multi component support fixes this as well.

@fendor
Copy link
Collaborator

fendor commented Nov 8, 2021

Just fyi, the WIP does unfortunately not work at the moment.

@jneira
Copy link
Member

jneira commented Nov 8, 2021

Just fyi, the WIP does unfortunately not work at the moment.

Oh, that is unfortunate, there is no usable previous commit?

@fendor
Copy link
Collaborator

fendor commented Nov 8, 2021

Well maybe, but you have to use the right cabal commit as well for it to work

@kczulko
Copy link

kczulko commented Nov 5, 2022

+1
I am facing the same issue now.

$  haskell-language-server --version
haskell-language-server version: 1.7.0.0 (GHC: 9.0.2) (PATH: /nix/store/0mlwa968v3bw6g9qgb3ldih6d9bqxcli-haskell-language-server-1.7.0.0/bin/haskel

Every time I try to evaluate a function from a comment I get the following "error" (taken from lsp-haskell::stderr; IPTypes module defined within internal library):

<no location info>: warning: [-Wmissing-home-modules]
    These modules are needed for compilation but not listed in your .cabal file's other-modules: 
        IPTypes

/home/kczulko/Projects/ip-range-haskell/ip/gen/IPGen.hs:4:1: error:
    Could not load module ‘IPTypes’
    It is a member of the hidden package ‘ip-range-haskell-0.1.0.0’.
    Perhaps you need to add ‘ip-range-haskell’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘ip-range-haskell-0.1.0.0’.
    Perhaps you need to add ‘ip-range-haskell’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.

@michaelpj michaelpj added the multi-component Issues relating to multi-component support label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-eval-plugin multi-component Issues relating to multi-component support type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

7 participants