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

Setup ghcide for rules_haskell repository #1262

Merged
merged 16 commits into from
Jun 4, 2020
Merged

Setup ghcide for rules_haskell repository #1262

merged 16 commits into from
Jun 4, 2020

Conversation

aherrmann
Copy link
Member

@aherrmann aherrmann commented Mar 4, 2020

Depends on #1350.

This configures hie-bios for ghcide for rules_haskell.

  • Adds ghcide as built by stack_snapshot and haskell_cabal_binary to the repository. stack_snapshot build executable components #1304 will make this easier in the future.
  • Adds a haskell_repl target to determine GHC flags required for the REPL session.
  • Adds a .hie-bios script to the repository that is picked up by hie-bios's bios cradle. When executed that should write all GHCi flags to a file specified by the HIE_BIOS_OUTPUT environment variable. See hie-bios README. Once multi-component support is implemented in ghcide this should become more flexible. See Multi Component haskell/ghcide#522 (comment)
  • Adds a simple test case that builds ghcide and checks that ghcide --version works. This is run on nixpkgs and bindist configurations.
  • Adds a more involved test case to RunTests that invokes ghcide on a target and checks if it can successfully determine the required GHC flags. This is only run on nixpkgs configurations, since run-tests is only executed there.
  • Adds a section to the use-case documentation explaining how to setup ghcide with rules_haskell. The setup is still pretty involved, stack_snapshot build executable components #1304 will simplify it a fair bit. We may want to hold off wider announcement, e.g. a tweet, until this is merged.

In order to make use of ghcide on rules_haskell you need to configure your editor to use it. See setup instructions. For example, the following works for neovim with coc:
.vim/coc-settings.json

{
    "languageserver": {
        "haskell": {
            "command": "nix-shell",
            "args": [
                "--run",
                "./.ghcide --lsp"
            ],
            "rootPatterns": [
                ".hie-bios"
            ],
            "filetypes": [
                "hs",
                "lhs",
                "haskell"
            ]
        }
    }
}

@smelc
Copy link
Contributor

smelc commented Mar 17, 2020

Cool! I could successfully reproduce the setup as follows:

> nix-shell --pure
pure> bazel test //... # To make sure everything is right
pure> bazel build @ghcide//:ghcide # Took approximately 10 minutes

Then in another shell, because I didn't want to pull neovim's coc dependencies from nix; and used my system install instead:

Video is a bit laggy because of the recording, but it's really smooth otherwise. In case things aren't working as expected:

  • In the pure shell, check that executing bazel-bin/external/ghcide/_install/bin/ghcide works (It should stop at Step 1/6: Finding files to test in ...)
  • Within neovim, check that content displayed at :CocConfig is the one posted by @aherrmann above. If you're using neovim in other contexts, it may be configured differently.

@mboes
Copy link
Member

mboes commented Mar 17, 2020

Once this merged, don't forget to schedule a tweet.

@thufschmitt thufschmitt self-requested a review March 30, 2020 09:12
Copy link
Contributor

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

That's awesome!

My only pain point is that setting this up is a bit involved. I'd really like this to be easier (as close to zero-config as can be). Though that's not a blocker for this PR and can be solved incrementally later

@thufschmitt
Copy link
Contributor

After a bit more testing it looks like hover only display the haddock documentation for the values that come from libraries bundled with GHC (so not from cabal_library nor haskell_library deps). Is that expected?

@aherrmann aherrmann force-pushed the ghcide branch 2 times, most recently from bf0cb60 to 7eaddfc Compare April 8, 2020 09:29
@aherrmann aherrmann force-pushed the ghcide branch 2 times, most recently from 7aab355 to ed233c1 Compare April 22, 2020 13:13
@aherrmann aherrmann force-pushed the ghcide branch 2 times, most recently from 90045a7 to 12198ba Compare May 6, 2020 15:10
@aherrmann aherrmann changed the title [WIP] Setup ghcide for rules_haskell repository Setup ghcide for rules_haskell repository May 6, 2020
@aherrmann
Copy link
Member Author

This is now ready for review.

I've updated the PR description to reflect the latest state.

@aherrmann aherrmann marked this pull request as ready for review May 6, 2020 16:00
#!/usr/bin/env bash
set -euo pipefail
bazel build //:hie-bios --output_groups=hie_bios
cat bazel-bin/hie-bios@hie-bios >"$HIE_BIOS_OUTPUT"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure where to put this, but I ran into some issues with targets building with -Werror because ghcide forcibly sets some warnings (like missing-signatures), so the combination of both might lead to spurious errors. The common way out of this is that most hie bioses seem to filter out -Werror or add -Wwarn, and that's what I also did by added an echo -Wwarn at the end of .hie_bios

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point, another way to deal with this is to add -Wwarn to the toolchain's GHCi flags, e.g. https://github.com/digital-asset/daml/blob/a47c734401a70e5b9dd94cd9717a2192bc28c703/WORKSPACE#L382.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nvm, I see that the hie-bios output group doesn't include those. Though maybe it should.

aherrmann added a commit that referenced this pull request May 8, 2020
Comment on lines 363 to 365
Note, that if you are using Nix, then you may need to invoke ghcide within a
``nix-shell``.
Be sure to configure your editor to invoke the above wrapper script instead of
another instance of `ghcide`. Also note, that if you are using Nix, then you
may need to invoke ghcide within a ``nix-shell``.
Copy link
Member Author

Choose a reason for hiding this comment

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

@smelc I made the docs a bit more explicit regarding pointing the editor to the correct instance of ghcide.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@thufschmitt
Copy link
Contributor

I stumbled across a strange error with this on #1342

aherrmann added a commit that referenced this pull request Jun 3, 2020
@aherrmann aherrmann changed the base branch from master to cc-wrapper June 3, 2020 13:54
Copy link
Contributor

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Just one minor comment but can be solved as a follow-up if needs be

Next, we need to hook this up to `hie-bios`_ using the `bios cradle`_. To that
end, define a small shell script named ``.hie-bios`` that looks as follows::

#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

This is out-of-sync with the .hie-bios script in this repo.

I guess it's on purpose (to show a simple-but-working script in the docs), but maybe we could export the full-featured script as a bazel target and let the client-side .hie-bios script just be something like

#!/bin/bash

bazel run @rules_haskell//:hie-bios //:hie-bios

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed that was intentional to keep the documentation simple.

but maybe we could export the full-featured script as a bazel target

That's a very nice idea, thanks!

@thufschmitt thufschmitt added the merge-queue merge on green CI label Jun 4, 2020
Base automatically changed from cc-wrapper to master June 4, 2020 10:13
@dpulls
Copy link

dpulls bot commented Jun 4, 2020

🎉 All dependencies have been resolved !

aherrmann added 16 commits June 4, 2020 10:14
Verifies that the ghcide binary builds and can be executed. Does not
test actual loading of sources into ghcide.

Also ensures that ghcide is built during the build stage in CI.
The ghcide binary is built as a static binary and uses the static RTS.
That means that GHCi's linker within ghcide will not look for dynamic
libraries of the form `libHSfoo-ghc8.8.2.so`, but only for static
libraries of the form `libHSfoo.a` (oddly also for `libHSfoo.so`).

Closes #1342
The -pgm arguments contain spaces and need to be quoted for the REPL
script. However, hie-bios expects unquoted arguments one per line of the
hie-bios file.
@mergify mergify bot merged commit 05b5554 into master Jun 4, 2020
@mergify mergify bot deleted the ghcide branch June 4, 2020 11:34
@mergify mergify bot removed the merge-queue merge on green CI label Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants