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

Improve wrapper cradle errors #2711

Merged
merged 4 commits into from Feb 14, 2022
Merged

Conversation

hasufell
Copy link
Member

@hasufell hasufell commented Feb 14, 2022

@hasufell
Copy link
Member Author

@jhrcek build via:

ghcup compile hls -r https://github.com/hasufell/haskell-language-server.git -g improve-wrapper-error --ghc 8.10.7

@jhrcek
Copy link
Collaborator

jhrcek commented Feb 14, 2022

Thank you @hasufell , you're really fast!

I'm getting this error:

Failed to get project GHC executable path:CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -e putStr =<< System.Environment.getExecutablePath","","\n<interactive>:0:1: error: Variable not in scope: putStr\n\n<interactive>:0:8: error:\n    Variable not in scope:\n      (=<<) :: t0 -> GHC.Types.IO GHC.IO.FilePath -> t\n"]}

@hasufell
Copy link
Member Author

hasufell commented Feb 14, 2022

Thank you @hasufell , you're really fast!

I'm getting this error:

Failed to get project GHC executable path:CradleError {cradleErrorDependencies = [], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Error when calling stack exec ghc -- -v0 -package-env=- -e putStr =<< System.Environment.getExecutablePath","","\n<interactive>:0:1: error: Variable not in scope: putStr\n\n<interactive>:0:8: error:\n    Variable not in scope:\n      (=<<) :: t0 -> GHC.Types.IO GHC.IO.FilePath -> t\n"]}

Uh... can you run

stack exec ghc -- -v0 -package-env=- -e 'putStr =<< System.Environment.getExecutablePath'

inside your project? What if you run it outside of your project? Is NoImplicitPrelude activated?

What are the contents of ~/.stack/global-project/stack.yaml.

@hasufell
Copy link
Member Author

Yeah, pretty sure it's NoImplicitPrelude:

stack exec ghc -- -XNoImplicitPrelude -v0 -package-env=- -e 'putStr =<< System.Environment.getExecutablePath'

<interactive>:0:1: error: Variable not in scope: putStr

<interactive>:0:8: error:
    Variable not in scope:
      (=<<) :: t0 -> GHC.Types.IO GHC.IO.FilePath -> t

@jhrcek
Copy link
Collaborator

jhrcek commented Feb 14, 2022

Outside of any project it works fine

~> stack exec ghc -- -v0 -package-env=- -e "putStr =<< System.Environment.getExecutablePath"
/home/jhrcek/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/bin/ghc

within our work codebase it doesn't:

~/Devel/github.com/Holmusk/PI/backend> stack exec ghc -- -v0 -package-env=- -e "putStr =<< System.Environment.getExecutablePath"

<interactive>:0:1: error: Variable not in scope: putStr

<interactive>:0:8: error:
    Variable not in scope:
      (=<<) :: t0 -> GHC.Types.IO GHC.IO.FilePath -> t

Indeed we are using NoImplicitPrelude 😄

@hasufell hasufell marked this pull request as draft February 14, 2022 14:24
@hasufell
Copy link
Member Author

Ok, I'll push a fix to this PR.

@hasufell hasufell marked this pull request as ready for review February 14, 2022 14:30
@hasufell
Copy link
Member Author

@jhrcek please try again

@jhrcek
Copy link
Collaborator

jhrcek commented Feb 14, 2022

$ stack exec ghc -- -v0 -package-env=- -e "Prelude.putStr Prelude.=<< System.Environment.getExecutablePath"

<interactive>:0:1: error:
    Not in scope: ‘Prelude.putStr’
    No module named ‘Prelude’ is imported.

<interactive>:0:16: error:
    Not in scope: ‘Prelude.=<<’
    No module named ‘Prelude’ is imported.

I should mention that we're using Relude + base-noprelude, basically setup described here
https://github.com/kowainik/relude#base-noprelude

@jhrcek
Copy link
Collaborator

jhrcek commented Feb 14, 2022

I wonder if it woulndn't be maybe easier to do

$ stack exec ghc -- -v0  -e "System.Environment.getExecutablePath"
"/home/jhrcek/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/bin/ghc"

and then strip the quotes?

Or alternatively use System.IO.putStr to avoid Prelude altogether?

@hasufell
Copy link
Member Author

stack exec ghc -- -XNoImplicitPrelude -v0 -package-env=- -e 'do e <- System.Environment.getExecutablePath ; System.IO.putStr e'

@jhrcek
Copy link
Collaborator

jhrcek commented Feb 14, 2022

That works ok

stack exec ghc -- -XNoImplicitPrelude -v0 -package-env=- -e 'do e <- System.Environment.getExecutablePath ; System.IO.putStr e'
/home/jhrcek/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/lib/ghc-8.10.7/bin/ghc

Copy link
Collaborator

@jhrcek jhrcek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for quick response. Works for me 👍

exe/Wrapper.hs Outdated Show resolved Hide resolved
@@ -114,13 +114,21 @@ launchHaskellLanguageServer parsedArgs = do
callProcess e args
#else
let Cradle { cradleOptsProg = CradleAction { runGhcCmd } } = cradle
(CradleSuccess ghcBinary) <- fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-e", "putStr =<< System.Environment.getExecutablePath"]
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
ghcBinary <- (fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-e", "do e <- System.Environment.getExecutablePath ; System.IO.putStr e"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment, very non-obvious that you're doing it this way to be compatible with NoImplicitPrelude.

Also, this probably won't work with RebindableSyntax still, but surely nobody sets that globally...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RebindableSyntax

oh dear...

exe/Wrapper.hs Outdated Show resolved Hide resolved
@michaelpj michaelpj added the merge me Label to trigger pull request merge label Feb 14, 2022
@mergify mergify bot merged commit 5271f63 into haskell:master Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants