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

Multi component ghcide setup #374

Merged
merged 21 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ tmp/
*.hp
*.prof
*.pyc
/hie.yaml

/test.*
/*.html
Expand Down
4 changes: 4 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cradle:
bios:
program: script/ghci-flags
dependency-program: script/ghci-flags-dependencies
Comment on lines +1 to +4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. hie-bios recently added support for multiple cabal component cradles, but I couldn’t get it working with ghcide yet.

  2. My direct configuration wasn’t portable due to VS Code using a PWD env var of / and -i flags being resolved relative to that env var rather than the actual working directory. So we had to compute it.

  3. Computing it is probably better for our purposes anyway, since it allows us to share work between this and script/repl.

47 changes: 47 additions & 0 deletions script/ghci-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
# Computes the flags for ghcide to pass to ghci. You probably won’t be running this yourself, but rather ghcide will via configuration in hie.yaml.
Comment on lines +1 to +2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The approach here is similar to the approach of #373: basically just listing all the options we can think of, collected by clever use of cabal repl -v.

A more robust approach would probably be to do something like cabal repl for each component and union together the options, but that actually seems pretty challenging:

  • stuff like package flags come in as two flags
  • some of the flags, like -outputdir, probably shouldn’t be duplicated
  • ordering matters for a lot of the flags
  • some of them conflict with one another, like -i erasing any previously configured load paths
  • we probably don’t want to pass the module names in as that would force ghcide to load everything eagerly rather than when only when you actually look at the file

Maybe someday all of this will be made unnecessary by cabal itself, but until that happy day, this is a pretty good solution for loading & typechecking all of our sources in ghcide, at the cost of requiring us to do a bit more manual work around the project’s packages & versions.


set -e

cd $(dirname "$0")/..

root="$(pwd)"
ghc_version="$(ghc --numeric-version)"
Comment on lines +8 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve attempted to compute what I can about the project, but I don’t know how to efficiently and robustly parse cabal.project for the .cabal files or the .cabal files for the package version numbers, or how otherwise to ask cabal for this information since it seems reluctant to tell me its secrets.


echo "-O0"
echo "-ignore-dot-ghci"

echo "-i$root/dist-newstyle/build/x86_64-osx/ghc-$ghc_version/semantic-0.8.0.0/build/autogen"

echo "-I$root/dist-newstyle/build/x86_64-osx/ghc-$ghc_version/semantic-0.8.0.0/build/autogen"

echo "-i$root/semantic-analysis/src"
echo "-i$root/semantic-ast/src"
echo "-i$root/semantic-core/src"
echo "-i$root/semantic-java/src"
echo "-i$root/semantic-json/src"
echo "-i$root/semantic-python/src"
echo "-i$root/semantic-tags/src"
echo "-i$root/src"
echo "-i$root/bench"
echo "-i$root/test"

echo "-optP-include"
echo "-optP$root/dist-newstyle/build/x86_64-osx/ghc-$ghc_version/semantic-0.8.0.0/build/autogen/cabal_macros.h"

# Emit package flags from the environment file, removing comments & prefixing with -
cabal exec -v0 bash -- -c 'cat $GHC_ENVIRONMENT' | grep -v '^--' | sed -e 's/^/-/'

echo "-XHaskell2010"

echo "-Weverything"
echo "-Wno-all-missed-specialisations"
echo "-Wno-implicit-prelude"
echo "-Wno-missed-specialisations"
echo "-Wno-missing-import-lists"
echo "-Wno-missing-local-signatures"
echo "-Wno-monomorphism-restriction"
echo "-Wno-name-shadowing"
echo "-Wno-safe"
echo "-Wno-unsafe"
echo "-Wno-star-is-type"
17 changes: 17 additions & 0 deletions script/ghci-flags-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# Computes the paths to files causing changes to the ghci flags. You probably won’t be running this yourself, but rather ghcide will via configuration in hie.yaml.
Comment on lines +1 to +2
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes to the listed files might result in different package flags for ghcide to learn of, so we tell it to watch them.


set -e

cd $(dirname "$0")/..

echo "cabal.project"

echo "semantic.cabal"
echo "semantic-analysis/semantic-analysis.cabal"
echo "semantic-ast/semantic-ast.cabal"
echo "semantic-core/semantic-core.cabal"
echo "semantic-java/semantic-java.cabal"
echo "semantic-json/semantic-json.cabal"
echo "semantic-python/semantic-python.cabal"
echo "semantic-tags/semantic-tags.cabal"