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

LiquidHaskell is causing HLS to fails

Open ashkann opened this issue 3 years ago • 12 comments

vscode 1.71.0 with Haskell plugin configured to use ghcup + almost zero code stack project MacOS ghc 8.10.7 stack 2.7.5 HLS 1.7.0.0

Trying to make LiquidHaskell work with the HLS. The stack build works so LH setup is well but now LHS outputs an error

No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /Users/ashkan/Hobby/Haskell/learn-lh
Operating system: darwin
Arguments: ["--lsp","-d"]
Cradle directory: /Users/ashkan/Hobby/Haskell/learn-lh
Cradle type: Stack

Tool versions found on the $PATH
cabal:		3.6.2.0
stack:		2.7.5
ghc:		8.10.7


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:/Users/ashkan/.ghcup/tmp/ghcup-ghc-8.10.7_cabal-3.6.2.0_hls-1.7.0.0_stack-2.7.5/haskell-language-server-8.10.7
Failed to get project GHC executable path: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)","","\n<interactive>:0:1: error:\n    Not in scope: \8216Control.Monad.join\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:21: error:\n    Not in scope: \8216Control.Monad.fmap\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:40: error:\n    Not in scope: \8216System.IO.putStr\8217\n    No module named \8216System.IO\8217 is imported.\n\n<interactive>:0:57: error:\n    Not in scope: \8216System.Environment.getExecutablePath\8217\n    No module named \8216System.Environment\8217 is imported.\n"]}
[Error - 11:13:30 PM] Connection to server got closed. Server will not be restarted.
[Error - 11:13:30 PM] Notify file events failed.

I tried the command on terminal, same error :

learn-lh  $> stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e "Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)"

<interactive>:0:1: error:
    Not in scope: ‘Control.Monad.join’
    No module named ‘Control.Monad’ is imported.

<interactive>:0:21: error:
    Not in scope: ‘Control.Monad.fmap’
    No module named ‘Control.Monad’ is imported.

<interactive>:0:40: error:
    Not in scope: ‘System.IO.putStr’
    No module named ‘System.IO’ is imported.

<interactive>:0:57: error:
    Not in scope: ‘System.Environment.getExecutablePath’
    No module named ‘System.Environment’ is imported.

The minimum to reproduce is to simply add the liquid-base (should replace the base) :

dependencies:
# - base
- liquid-base
# - liquid-vector
# - liquid-containers
# - liquid-bytestring
- liquidhaskell  

if I comment out the liquid-base and put back the base then HLS works but LH integration is crippled (it needs the liquid-base to work properly).

thestack.yaml file, taken verbatim from lh-plugin-demo https://github.com/ucsd-progsys/lh-plugin-demo :

allow-newer: true
resolver: lts-18.27
compiler: ghc-8.10.7
packages:
  - .
extra-deps:
  - git: https://github.com/ucsd-progsys/liquidhaskell
    commit: a4f2198f894810a729feb0f8d06301790ee8d1fb
    subdirs:
      - .
      - liquid-base
      - liquid-prelude
      - liquid-ghc-prim
      # - liquid-containers
      # - liquid-bytestring
      # - liquid-vector
  - git: https://github.com/ucsd-progsys/liquid-fixpoint
    commit: 08fa6b6e0001c2da6b96a135523ca56107a3c0d6
  - git: https://github.com/facundominguez/rest
    commit: 31e974979c90e910efe5199ee0d3721b791667f6

package.yaml file :

name:                learn-lh
version:             0.1.0.0
github:              "githubuser/learn-lh"
license:             BSD3
author:              "Author name here"
maintainer:          "[email protected]"
copyright:           "2022 Author name here"

extra-source-files:
- README.md
- CHANGELOG.md
description:         Please see the README on GitHub at <https://github.com/githubuser/learn-lh#readme>

dependencies:
# - base
- liquid-base
# - liquid-vector
# - liquid-containers
# - liquid-bytestring
- liquidhaskell

ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
- -fdefer-type-errors -fplugin=LiquidHaskell

library:
  source-dirs:
    - src

executables:
  learn-lh-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - learn-lh

tests:
  learn-lh-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - learn-lh

Thanks.

ashkann avatar Sep 01 '22 21:09 ashkann

I spent some more time on it. Running the main executable works fine but the wrapper results in the exact same error :

Users/ashkan/.ghcup/tmp/ghcup-ghc-8.10.7_cabal-3.6.2.0_hls-1.7.0.0_stack-2.7.5/haskell-language-server-wrapper-1.7.0.0 
Found "/Users/ashkan/Hobby/Haskell/learn-lh/hie.yaml" for "/Users/ashkan/Hobby/Haskell/learn-lh/a"
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper-1.7.0.0) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /Users/ashkan/Hobby/Haskell/learn-lh
Operating system: darwin
Arguments: []
Cradle directory: /Users/ashkan/Hobby/Haskell/learn-lh
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.6.2.0
stack:          2.7.5
ghc:            8.10.7


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:/Users/ashkan/.ghcup/bin/haskell-language-server-8.10.7
Failed to get project GHC executable path: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)","","\n<interactive>:0:1: error:\n    Not in scope: \8216Control.Monad.join\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:21: error:\n    Not in scope: \8216Control.Monad.fmap\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:40: error:\n    Not in scope: \8216System.IO.putStr\8217\n    No module named \8216System.IO\8217 is imported.\n\n<interactive>:0:57: error:\n    Not in scope: \8216System.Environment.getExecutablePath\8217\n    No module named \8216System.Environment\8217 is imported.\n"]}

Notice that I run the wrapper haskell-language-server-wrapper-1.7.0.0 as opposed to haskell-language-server-8.10.7 (which runs with no errors, shows the expected output and terminates).

ashkann avatar Sep 04 '22 13:09 ashkann

I have trouble getting a liquid Haskell project up and running, your example doesn't compile for me with stack:

> stack build
Building all executables for `liquid-haskell-test' once. After a successful build of all of them, only specified executables will be rebuilt.
liquid-haskell-test> configure (exe)
Configuring liquid-haskell-test-0.1.0.0...
liquid-haskell-test> build (exe)
Preprocessing executable 'liquid-haskell-test' for liquid-haskell-test-0.1.0.0..
Building executable 'liquid-haskell-test' for liquid-haskell-test-0.1.0.0..
[1 of 1] Compiling Main

/home/hugin/Documents/haskell/liquid-haskell-test/src/Main.hs:1:8: error:
    Ambiguous module name ‘Prelude’:
      it was found in multiple packages:
      base-4.14.3.0 liquid-base-4.14.3.0
  |
1 | module Main (main) where
  |        ^^^^


--  While building package liquid-haskell-test-0.1.0.0 (scroll up to its section to see the error) using:
      /home/hugin/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0 build exe:liquid-haskell-test --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

Can you maybe share an example I just have to check out?

EDIT: Managed to make it compile with

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PackageImports #-}
module Main (main) where

import "base" Prelude (putStrLn, IO)

main :: IO ()
main = do
  putStrLn "hello world"

Managed to reproduce the error.

Curiously, with cabal it works. This cabal.project:

packages: ./

source-repository-package
    type: git
    location: https://github.com/ucsd-progsys/liquidhaskell
    tag: a4f2198f894810a729feb0f8d06301790ee8d1fb

source-repository-package
    type: git
    location: https://github.com/ucsd-progsys/liquidhaskell
    tag: a4f2198f894810a729feb0f8d06301790ee8d1fb
    subdir: liquid-base

source-repository-package
    type: git
    location: https://github.com/ucsd-progsys/liquidhaskell
    tag: a4f2198f894810a729feb0f8d06301790ee8d1fb
    subdir: liquid-prelude

source-repository-package
    type: git
    location: https://github.com/ucsd-progsys/liquidhaskell
    tag: a4f2198f894810a729feb0f8d06301790ee8d1fb
    subdir: liquid-ghc-prim

source-repository-package
    type: git
    location: https://github.com/ucsd-progsys/liquid-fixpoint
    tag: 08fa6b6e0001c2da6b96a135523ca56107a3c0d6

source-repository-package
    type: git
    location: https://github.com/facundominguez/rest
    tag: 31e974979c90e910efe5199ee0d3721b791667f6

And the output:

> haskell-language-server-wrapper --debug src/
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /home/hugin/Documents/haskell/liquid-haskell-test
Operating system: linux
Arguments: ["--debug","src/"]
Cradle directory: /home/hugin/Documents/haskell/liquid-haskell-test
Cradle type: Cabal

Tool versions found on the $PATH
cabal:		3.6.2.0
stack:		2.7.5
ghc:		8.10.7


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/hugin/.ghcup/bin/haskell-language-server-8.10.7
2022-09-05T08:56:48.018299Z | Info | No log file specified; using stderr.
2022-09-05T08:56:48.018909Z | Info | haskell-language-server version: 1.7.0.0 (GHC: 8.10.7) (PATH: /home/hugin/.ghcup/hls/1.7.0.0/lib/haskell-language-server-1.7.0.0/bin/haskell-language-server-8.10.7)
2022-09-05T08:56:48.019350Z | Info | Directory: /home/hugin/Documents/haskell/liquid-haskell-test
2022-09-05T08:56:48.019568Z | Info | Logging heap statistics every 60.00s
 ghcide setup tester in /home/hugin/Documents/haskell/liquid-haskell-test.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/hugin/Documents/haskell/liquid-haskell-test
Found 1 files

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

Step 3/4: Initializing the IDE
2022-09-05T08:56:48.022162Z | Debug | Initializing exports map from hiedb
2022-09-05T08:56:48.022679Z | Debug | Shake session initialized

Step 4/4: Ty2022-09-05T08:56:48.022875Z | Debug | Done initializing exports map from hiedb. Size: 1
pe checking the files
2022-09-05T08:56:48.023568Z | Info | Cradle path: src/Main.hs
2022-09-05T08:56:48.023645Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Main.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2022-09-05T08:56:48.025250Z | Debug | Cradle: Cradle {cradleRootDir = "/home/hugin/Documents/haskell/liquid-haskell-test", cradleOptsProg = CradleAction: Cabal}
2022-09-05 10:56:48.504027794 [ThreadId 36] INFO hie-bios:	Build profile: -w ghc-8.10.7 -O1
2022-09-05 10:56:48.504234826 [ThreadId 36] INFO hie-bios:	In order, the following will be built (use -v for more details):
2022-09-05 10:56:48.504303337 [ThreadId 36] INFO hie-bios:	- liquid-haskell-test-0.1.0.0 (exe:liquid-haskell-test) (first run)
2022-09-05 10:56:48.548587599 [ThreadId 36] INFO hie-bios:	Preprocessing executable 'liquid-haskell-test' for liquid-haskell-test-0.1.0.0..
2022-09-05T08:56:49.083973Z | Debug | Session loading result: Right (ComponentOptions {componentOptions = ["-fbuilding-cabal-package","-O0","-outputdir","/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/liquid-haskell-test-tmp","-odir","/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/liquid-haskell-test-tmp","-hidir","/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/liquid-haskell-test-tmp","-stubdir","/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/liquid-haskell-test-tmp","-i","-i/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/liquid-haskell-test-tmp","-isrc","-i/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/autogen","-i/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/global-autogen","-I/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/autogen","-I/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/global-autogen","-I/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/liquid-haskell-test-tmp","-optP-include","-optP/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/build/liquid-haskell-test/autogen/cabal_macros.h","-hide-all-packages","-Wmissing-home-modules","-no-user-package-db","-package-db","/home/hugin/.cabal/store/ghc-8.10.7/package.db","-package-db","/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/packagedb/ghc-8.10.7","-package-db","/home/hugin/.cache/hie-bios/dist-liquid-haskell-test-01c5d2f92db76955a21e804cba13cc8d/build/x86_64-linux/ghc-8.10.7/liquid-haskell-test-0.1.0.0/x/liquid-haskell-test/package.conf.inplace","-package-id","base-4.14.3.0","-package-id","liquid-base-4.14.3.0-d2c76e0d134a9a2a5cfa5eacfc48a284873089393e677127877f3c67d5c69d4f","-package-id","liquidhaskell-0.8.10.7.1-87749dd76b2438075bcf77745a3b278d5d72e9d2dd4a794a0dd96357d24a90b4","-XHaskell2010","src/Main.hs","-Wall","-Wcompat","-Widentities","-Wincomplete-record-updates","-Wincomplete-uni-patterns","-Wmissing-export-lists","-Wmissing-home-modules","-Wpartial-fields","-Wredundant-constraints","-fdefer-type-errors","-fplugin=LiquidHaskell","-hide-all-packages"], componentRoot = "/home/hugin/Documents/haskell/liquid-haskell-test", componentDependencies = ["liquid-haskell-test.cabal","cabal.project","cabal.project.local"]},"/home/hugin/.ghcup/ghc/8.10.7/lib/ghc-8.10.7")
2022-09-05T08:56:49.607735Z | Info | Interface files cache directory: /home/hugin/.cache/ghcide/main-f016c6d4fc4ab21ca3cccb6c22a867d9bbdd1de6
2022-09-05T08:56:49.607990Z | Info | Making new HscEnv. In-place unit ids: [main]
2022-09-05T08:56:49.981452Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 5),fromList [("cabal.project",Just 2022-09-05 08:27:12.224045721 UTC),("cabal.project.local",Nothing),("liquid-haskell-test.cabal",Just 2022-09-05 08:23:13.459544185 UTC)])
2022-09-05T08:56:49.981746Z | Debug | Known files updated:
  fromList [(TargetFile NormalizedFilePath "/home/hugin/Documents/haskell/liquid-haskell-test/src/Main.hs",fromList ["/home/hugin/Documents/haskell/liquid-haskell-test/src/Main.hs"])]
2022-09-05T08:56:49.981894Z | Debug | Finished build session
AsyncCancelled
2022-09-05T08:56:49.981930Z | Debug | Restarting build session due to new component
Action Queue: [User TypeCheck]
Keys: [GhcSessionIO; , GetKnownTargets; ]
Aborting previous build session took 0.00s 
2022-09-05T08:56:49.982179Z | Debug | Getting hlint ideas for  NormalizedFilePath "/home/hugin/Documents/haskell/liquid-haskell-test/src/Main.hs"
2022-09-05T08:56:50.512623Z | Debug | Finished: User TypeCheck Took: 0.53s
2022-09-05T08:56:50.646394Z | Debug | Finished: GetHie Took: 0.10s
2022-09-05T08:56:50.674797Z | Debug | Finished: GenerateCore Took: 0.00s

Completed (1 file worked, 0 files failed)

fendor avatar Sep 05 '22 08:09 fendor

Maybe stack instructs GHC too eagerly to not use implicit prelude, or something? Or the package-env is cleared too vigorously?

fendor avatar Sep 05 '22 09:09 fendor

Narrowed it down to this :

stack exec ghc -- -e "System.Environment.getExecutablePath"

<interactive>:0:1: error:
    Not in scope: ‘System.Environment.getExecutablePath’
    No module named ‘System.Environment’ is imported.

and maybe even narrower :

stack exec ghc -- -e "import Prelude"

<no location info>: error:
    Ambiguous module name ‘Prelude’:
      it was found in multiple packages:
      base-4.14.3.0 liquid-base-4.14.3.0       

I'm basically a n00b on both Haskell and LH but the second command is rather confusing because didn't we just opted out of base and opted in for liquid-base in stack.yaml ?

ashkann avatar Sep 05 '22 13:09 ashkann

About reproducing , I can reproduce with the following minimum code. The only requirement is to have LH in your build config as stated in the issue description:

module Lib() where

I have no Main.hs and this is my package.yaml:

name:                learn-lh
version:             0.1.0.0
github:              "githubuser/learn-lh"
license:             BSD3
author:              "Author name here"
maintainer:          "[email protected]"
copyright:           "2022 Author name here"

extra-source-files:
- README.md
- CHANGELOG.md

# Metadata used when publishing your package
# synopsis:            Short description of your package
# category:            Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description:         Please see the README on GitHub at <https://github.com/githubuser/learn-lh#readme>

dependencies:
- liquid-base
- base
- liquid-prelude
- liquid-containers
- liquidhaskell


ghc-options:
- -Wall
- -Wcompat
- -Widentities
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wmissing-export-lists
- -Wmissing-home-modules
- -Wpartial-fields
- -Wredundant-constraints
# - -fdefer-type-errors -fplugin=LiquidHaskell

library:
  # ghc-options: -fdefer-type-errors -fplugin=LiquidHaskell
  source-dirs:
    - src
  exposed-modules:
    - Lib
    # - Tutorial_01_Introduction
    # - Tutorial_02_Logic
    # - Tutorial_03_Basic
    # - Tutorial_04_Polymorphism
    # - Tutorial_05_Datatypes
    # - Tutorial_06_Measure_Bool
    # - Tutorial_07_Measure_Int
    # - Tutorial_08_Measure_Set
    # - Tutorial_09_Case_Study_Lazy_Queues
    # - Tutorial_10_Case_Study_Associative_Maps
    # - Tutorial_11_Case_Study_Pointers
    # - Tutorial_12_Case_Study_AVL    

# executables:
#   learn-lh-exe:
#     main:                Main.hs
#     source-dirs:         app
#     ghc-options:
#     - -threaded
#     - -rtsopts
#     - -with-rtsopts=-N
#     dependencies:
#     - learn-lh

As you can see essentially everything is commented out. I can strip down the noise and push a repo if that helps ...

Maybe stack instructs GHC too eagerly to not use implicit prelude, or something? Or the package-env is cleared too vigorously?

I wish I could understand what you are saying :D I'll try ... so why would stack tell GHC to not use implicit prelude ? besides in Wrapper code it is explicitly mentioned the lines that cause the error are there to support NoImplicitPrelude https://github.com/haskell/haskell-language-server/blob/b5a37f7fc360596899cb2945f363030f44156415/exe/Wrapper.hs#L117

      let Cradle { cradleOptsProg = CradleAction { runGhcCmd } } = cradle
      -- we need to be compatible with NoImplicitPrelude
      ghcBinary <- (fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-ignore-dot-ghci", "-e", "Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)"])
        >>= cradleResult "Failed to get project GHC executable path"

I'm thinking, since HLS works fine otherwise then it shouldn't be stack's fault 🤔 my understanding is including the LH somehow messes up with the prelude and stack is a victim here as well :D but how ? and why cabal works !

ashkann avatar Sep 05 '22 13:09 ashkann

Published the min reproduce on https://github.com/ashkann/stack-lh-min

  • Doesn't list any dependencies in package.yaml, only in stack.yaml
  • Doesn't actually include LH GHC plugin (no ghc-options in package.yaml)
  • stack build succeeds but HLS fails
/Users/ashkan/.ghcup/tmp/ghcup-ghc-8.10.7_cabal-3.6.2.0_hls-1.7.0.0_stack-2.7.5/haskell-language-server-wrapper-1.7.0.0
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper-1.7.0.0) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /Users/ashkan/Hobby/Haskell/stack-lh-min
Operating system: darwin
Arguments: []
Cradle directory: /Users/ashkan/Hobby/Haskell/stack-lh-min
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.6.2.0
stack:          2.7.5
ghc:            8.10.7


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:/Users/ashkan/.ghcup/bin/haskell-language-server-8.10.7
Failed to get project GHC executable path: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)","","\n<interactive>:0:1: error:\n    Not in scope: \8216Control.Monad.join\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:21: error:\n    Not in scope: \8216Control.Monad.fmap\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:40: error:\n    Not in scope: \8216System.IO.putStr\8217\n    No module named \8216System.IO\8217 is imported.\n\n<interactive>:0:57: error:\n    Not in scope: \8216System.Environment.getExecutablePath\8217\n    No module named \8216System.Environment\8217 is imported.\n"]}
  • Also running directly on shell :
stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e "Control.Monad.join (Control.Monad fmap System.IO.putStr System.Environment.getExecutablePath)"

<interactive>:0:1: error:
    Not in scope: ‘Control.Monad.join’
    No module named ‘Control.Monad’ is imported.

<interactive>:0:21: error:
    Not in scope: data constructor ‘Control.Monad’
    No module named ‘Control’ is imported.

<interactive>:0:40: error:
    Not in scope: ‘System.IO.putStr’
    No module named ‘System.IO’ is imported.

<interactive>:0:57: error:
    Not in scope: ‘System.Environment.getExecutablePath’
    No module named ‘System.Environment’ is imported.
  • Making it simpler :
stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e "System.Environment.getExecutablePath"

<interactive>:0:1: error:
    Not in scope: ‘System.Environment.getExecutablePath’
    No module named ‘System.Environment’ is imported.
  • Removing all the flags etc and trying to import Prelude:
stack exec ghc -- -e "import Prelude"

<no location info>: error:
    Ambiguous module name ‘Prelude’:
      it was found in multiple packages:
      base-4.14.3.0 liquid-base-4.14.3.0

ashkann avatar Sep 05 '22 14:09 ashkann

Your example project seems to work for me :see_no_evil:

image

My logs:

> haskell-language-server-wrapper --debug app/
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /home/hugin/Documents/haskell/stack-lh-min
Operating system: linux
Arguments: ["--debug","app/"]
Cradle directory: /home/hugin/Documents/haskell/stack-lh-min
Cradle type: Stack

Tool versions found on the $PATH
cabal:		3.6.2.0
stack:		2.7.5
ghc:		8.10.7


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/hugin/.ghcup/bin/haskell-language-server-8.10.7
2022-09-05T14:32:46.375716Z | Info | No log file specified; using stderr.
2022-09-05T14:32:46.376381Z | Info | haskell-language-server version: 1.7.0.0 (GHC: 8.10.7) (PATH: /home/hugin/.ghcup/hls/1.7.0.0/lib/haskell-language-server-1.7.0.0/bin/haskell-language-server-8.10.7)
2022-09-05T14:32:46.376820Z | Info | Directory: /home/hugin/Documents/haskell/stack-lh-min
2022-09-05T14:32:46.377010Z | Info | Logging heap statistics every 60.00s
 ghcide setup tester in /home/hugin/Documents/haskell/stack-lh-min.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /home/hugin/Documents/haskell/stack-lh-min
Found 1 files

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

Step 3/4: Initializing the IDE
2022-09-05T14:32:46.379319Z | Debug | Initializing exports map from hiedb
2022-09-05T14:32:46.379722Z | Debug | Shake session initialized

Step 4/4: Type checking the files2022-09-05T14:32:46.380271Z | Debug | Done initializing exports map from hiedb. Size: 9

2022-09-05T14:32:46.380907Z | Info | Cradle path: app/Main.hs
2022-09-05T14:32:46.380978Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for app/Main.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2022-09-05T14:32:46.383361Z | Debug | Cradle: Cradle {cradleRootDir = "/home/hugin/Documents/haskell/stack-lh-min", cradleOptsProg = CradleAction: Stack}
2022-09-05 16:32:46.697356972 [ThreadId 30] INFO hie-bios:	Using main module: 1. Package `stack-lh-min' component stack-lh-min:exe:stack-lh-min-exe with main-is file: /home/hugin/Documents/haskell/stack-lh-min/app/Main.hs
2022-09-05 16:32:46.850556841 [ThreadId 30] INFO hie-bios:	The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
2022-09-05 16:32:46.850642001 [ThreadId 30] INFO hie-bios:	Configuring GHCi with the following packages: stack-lh-min
2022-09-05 16:32:47.347897295 [ThreadId 37] INFO hie-bios:	/home/hugin/Documents/haskell/stack-lh-min/.stack-work/install/x86_64-linux-tinfo6/7c444beeea79842f1b013590dc23a79fb9a40e04eb4aa3bf7bdcf007de05a149/8.10.7/pkgdb:/home/hugin/.stack/snapshots/x86_64-linux-tinfo6/7c444beeea79842f1b013590dc23a79fb9a40e04eb4aa3bf7bdcf007de05a149/8.10.7/pkgdb:/home/hugin/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/package.conf.d
2022-09-05T14:32:48.253228Z | Debug | Session loading result: Right (ComponentOptions {componentOptions = ["-i","-odir=/home/hugin/Documents/haskell/stack-lh-min/.stack-work/odir","-hidir=/home/hugin/Documents/haskell/stack-lh-min/.stack-work/odir","-hide-all-packages","-i/home/hugin/Documents/haskell/stack-lh-min/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/stack-lh-min-exe","-i/home/hugin/Documents/haskell/stack-lh-min/app","-i/home/hugin/Documents/haskell/stack-lh-min/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/stack-lh-min-exe/autogen","-i/home/hugin/Documents/haskell/stack-lh-min/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/global-autogen","-i/home/hugin/Documents/haskell/stack-lh-min/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/stack-lh-min-exe/stack-lh-min-exe-tmp","-stubdir=/home/hugin/Documents/haskell/stack-lh-min/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build","-package-id=base-4.14.3.0","-Wall","-Wcompat","-Widentities","-Wincomplete-record-updates","-Wincomplete-uni-patterns","-Wmissing-export-lists","-Wmissing-home-modules","-Wpartial-fields","-Wredundant-constraints","-rtsopts","-with-rtsopts=-N","-optP-include","-optP/home/hugin/Documents/haskell/stack-lh-min/.stack-work/ghci/65f48719/cabal_macros.h","-ghci-script=/tmp/haskell-stack-ghci/902b433f/ghci-script","-package-db","/home/hugin/Documents/haskell/stack-lh-min/.stack-work/install/x86_64-linux-tinfo6/7c444beeea79842f1b013590dc23a79fb9a40e04eb4aa3bf7bdcf007de05a149/8.10.7/pkgdb","-package-db","/home/hugin/.stack/snapshots/x86_64-linux-tinfo6/7c444beeea79842f1b013590dc23a79fb9a40e04eb4aa3bf7bdcf007de05a149/8.10.7/pkgdb","-package-db","/home/hugin/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/package.conf.d"], componentRoot = "/home/hugin/Documents/haskell/stack-lh-min", componentDependencies = ["stack-lh-min.cabal","package.yaml","stack.yaml"]},"/home/hugin/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7")
2022-09-05T14:32:48.291672Z | Info | Interface files cache directory: /home/hugin/.cache/ghcide/main-ff5c5a8fe83d845319b93f906dddc7472085f147
2022-09-05T14:32:48.291852Z | Info | Making new HscEnv. In-place unit ids: [main]
2022-09-05T14:32:48.297784Z | Debug | New component cache HscEnvEq: (([],Just HscEnvEq 5),fromList [("package.yaml",Just 2022-09-05 14:29:52.273424872 UTC),("stack-lh-min.cabal",Just 2022-09-05 14:29:52.273424872 UTC),("stack.yaml",Just 2022-09-05 14:29:52.273424872 UTC)])
2022-09-05T14:32:48.299448Z | Debug | Known files updated:
  fromList [(TargetFile NormalizedFilePath "/home/hugin/Documents/haskell/stack-lh-min/app/Main.hs",fromList ["/home/hugin/Documents/haskell/stack-lh-min/app/Main.hs"]),(TargetModule Paths_stack_lh_min,fromList ["/home/hugin/Documents/haskell/stack-lh-min/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/stack-lh-min-exe/autogen/Paths_stack_lh_min.hs"])]
2022-09-05T14:32:48.299635Z | Debug | Finished build session
AsyncCancelled
2022-09-05T14:32:48.299683Z | Debug | Restarting build session due to new component
Action Queue: [User TypeCheck]
Keys: [GhcSessionIO; , GetKnownTargets; ]
Aborting previous build session took 0.00s 
2022-09-05T14:32:48.299933Z | Debug | Getting hlint ideas for  NormalizedFilePath "/home/hugin/Documents/haskell/stack-lh-min/app/Main.hs"
2022-09-05T14:32:48.456384Z | Debug | Finished: User TypeCheck Took: 0.16s
2022-09-05T14:32:48.457724Z | Debug | Finished: GetHie Took: 0.00s
2022-09-05T14:32:48.457926Z | Debug | Finished: GenerateCore Took: 0.00s

Completed (1 file worked, 0 files failed)

I'm thinking, since HLS works fine otherwise then it shouldn't be stack's fault thinking my understanding is including the LH somehow messes up with the prelude and stack is a victim here as well :D but how ? and why cabal works !

Difficult to say, the build tools may instruct ghci slightly differently...

Just to make sure, you can run successfully stack build in your liquid haskell project while HLS fails?

fendor avatar Sep 05 '22 14:09 fendor

hmm ... how do I get your client settings ? any particular vscode settings you might think is affecting this ? image stack build image

My logs looks exactly like yours before the error. Maybe its a MacOS thing ?

2022-09-05 14:36:26.3990000 [client] INFO Starting language server
[Trace - 4:36:26 PM] Sending request 'initialize - (0)'.
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /Users/ashkan/Hobby/Haskell/stack-lh-min
Operating system: darwin
Arguments: ["--lsp","-d"]
Cradle directory: /Users/ashkan/Hobby/Haskell/stack-lh-min
Cradle type: Stack

Tool versions found on the $PATH
cabal:		3.6.2.0
stack:		2.7.5
ghc:		8.10.7


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:/Users/ashkan/.ghcup/tmp/ghcup-ghc-8.10.7_cabal-3.6.2.0_hls-1.7.0.0_stack-2.7.5/haskell-language-server-8.10.7
Failed to get project GHC executable path: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)","","\n<interactive>:0:1: error:\n    Not in scope: \8216Control.Monad.join\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:21: error:\n    Not in scope: \8216Control.Monad.fmap\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:40: error:\n    Not in scope: \8216System.IO.putStr\8217\n    No module named \8216System.IO\8217 is imported.\n\n<interactive>:0:57: error:\n    Not in scope: \8216System.Environment.getExecutablePath\8217\n    No module named \8216System.Environment\8217 is imported.\n"]}
[Info  - 4:36:29 PM] Connection to server got closed. Server will restart.

I see your arguments my arguments are Arguments: ["--lsp","-d"] but yours are ["--debug","app/"]. Tried it manually with the same results:

/Users/ashkan/.ghcup/tmp/ghcup-ghc-8.10.7_cabal-3.6.2.0_hls-1.7.0.0_stack-2.7.5/haskell-language-server-wrapper-1.7.0.0 --debug app/
No 'hie.yaml' found. Try to discover the project type!
Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper-1.7.0.0) Version 1.7.0.0 x86_64 ghc-9.2.2
Current directory: /Users/ashkan/Hobby/Haskell/stack-lh-min
Operating system: darwin
Arguments: ["--debug","app/"]
Cradle directory: /Users/ashkan/Hobby/Haskell/stack-lh-min
Cradle type: Stack

Tool versions found on the $PATH
cabal:          3.6.2.0
stack:          2.7.5
ghc:            8.10.7


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:/Users/ashkan/.ghcup/bin/haskell-language-server-8.10.7
Failed to get project GHC executable path: CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -ignore-dot-ghci -e Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)","","\n<interactive>:0:1: error:\n    Not in scope: \8216Control.Monad.join\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:21: error:\n    Not in scope: \8216Control.Monad.fmap\8217\n    No module named \8216Control.Monad\8217 is imported.\n\n<interactive>:0:40: error:\n    Not in scope: \8216System.IO.putStr\8217\n    No module named \8216System.IO\8217 is imported.\n\n<interactive>:0:57: error:\n    Not in scope: \8216System.Environment.getExecutablePath\8217\n    No module named \8216System.Environment\8217 is imported.\n"]}

ashkann avatar Sep 05 '22 14:09 ashkann

After reading some more on how stack.yaml and extra-deps work I'm even more confused :

extra-deps:
 - acme-missiles-0.3

what you're saying to Stack is: "if at any point you find that you need to build the acme-missiles package, please use version 0.3". You are not saying "please build acme-missiles now." You are also not saying "my package depends on acme-missiles." You are simply making it available should the need arise.

So basically listing LH packages in stack.yaml under extra-deps should have exactly zero effects unless you are also listing them in pckage.yaml or maybe transiently referring to them somehow(?) which is not the case here as in seen in the example repo since it only depends on base (not liquid-base) 🤔

ashkann avatar Sep 08 '22 18:09 ashkann

Switched to cabal and it works. Maybe this is not a HLS issue ?

ashkann avatar Sep 08 '22 20:09 ashkann

hmm ... how do I get your client settings ? any particular vscode settings you might think is affecting this ?

No special config, used HLS on the cli and vscode.

Maybe this is not a HLS issue ?

Might still be an HLS issue, keep open until we know what's up.

fendor avatar Sep 09 '22 10:09 fendor

There is the fact though that just listing the LH packages in extra-deps breaks the setup. Asked stack people and they also agree this shouldn't be. So wether or not this is part an HLS issue as well, at any rate stack shouldn't break things when a dependency is listed but never used (which is the case here).

ashkann avatar Sep 10 '22 10:09 ashkann

Resolved as blocked on stack.

fendor avatar Oct 26 '22 15:10 fendor

I have the same problem, is there any hope to get this working with stack without having to use cabal?

89oinotna avatar Nov 07 '22 20:11 89oinotna

To fix this, you should probably raise an issue with stack and see what the maintainers think about it.

fendor avatar Nov 08 '22 09:11 fendor

I'm getting this exact same problem now using this stack file from https://github.com/ucsd-progsys/lh-plugin-demo/

igormoreno avatar Apr 29 '23 13:04 igormoreno