Skip to content

Commit 373c406

Browse files
mpickeringalanzfendorcocreature
authored
Multi Component (#522)
* Multi component support In this commit we add support for loading multiple components into one ghcide session. The current behaviour is that each component is loaded lazily into the session. When a file from an unrecognised component is loaded, the cradle is consulted again to get a new set of options for the new component. This will cause all the currently loaded files to be reloaded into a new HscEnv which is shared by all the currently known components. The result of this is that functions such as go-to definition work between components if they have been loaded into the same session but you have to open at least one file from each component before it will work. Only minimal changes are needed to the internals to ghcide to make the file searching logic look in include directories for all currently loaded components. The main changes are in exe/Main.hs which has been heavily rewritten to avoid shake indirections. A global map is created which maps a filepath to the HscEnv which should be used to compile it. When a new component is created this map is completely refreshed so each path maps to a new Which paths belong to a componenent is determined by the targets listed by the cradle. Therefore it is important that each cradle also lists all the targets for the cradle. There are some other choices here as well which are less accurate such as mapping via include directories which is the aproach that I implemented in haskell-ide-engine. The commit has been tested so far with cabal and hadrian. Also deleted the .ghci file which was causing errors during testing and seemed broken anyway. Co-authored-by: Alan Zimmerman <[email protected]> Co-authored-by: fendor <[email protected]> * Final tweaks? * Fix 8.4 build * Add multi-component test * Fix hlint * Add cabal to CI images * Modify path * Set PATH in the right place (hopefully) * Always generate interface files and hie files * Use correct DynFlags in mkImportDirs You have to use the DynFlags for the file we are currently compiling to get the right packages in the package db so that lookupPackage doesn't always fail. * Revert "Always generate interface files and hie files" This reverts commit 820aa241890c4498c566e29b0823a803fb2fd297. * remove traces * Another test * lint * Unset env vars set my stack * Fix extra-source-files As usual, stack doesn’t understand Cabal properly and doesn’t seem to like ** wildcards so I’ve enumerated it manually. * Unset env locally Co-authored-by: Alan Zimmerman <[email protected]> Co-authored-by: fendor <[email protected]> Co-authored-by: Moritz Kiefer <[email protected]>
1 parent 51907fe commit 373c406

30 files changed

+855
-439
lines changed

.azure/linux-stack.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ jobs:
3232
./fmt.sh
3333
displayName: "HLint via ./fmt.sh"
3434
- bash: |
35-
sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev
35+
sudo add-apt-repository ppa:hvr/ghc
36+
sudo apt-get update
37+
sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev cabal-install-3.2
3638
if ! which stack >/dev/null 2>&1; then
3739
curl -sSL https://get.haskellstack.org/ | sh
3840
fi
@@ -41,7 +43,9 @@ jobs:
4143
displayName: 'stack setup'
4244
- bash: stack build --only-dependencies --stack-yaml=$STACK_YAML
4345
displayName: 'stack build --only-dependencies'
44-
- bash: stack test --ghc-options=-Werror --stack-yaml=$STACK_YAML || stack test --ghc-options=-Werror --stack-yaml=$STACK_YAML|| stack test --ghc-options=-Werror --stack-yaml=$STACK_YAML
46+
- bash: |
47+
export PATH=/opt/cabal/bin:$PATH
48+
stack test --ghc-options=-Werror --stack-yaml=$STACK_YAML || stack test --ghc-options=-Werror --stack-yaml=$STACK_YAML|| stack test --ghc-options=-Werror --stack-yaml=$STACK_YAML
4549
# ghcide stack tests are flaky, see https://github.com/digital-asset/daml/issues/2606.
4650
displayName: 'stack test --ghc-options=-Werror'
4751
- bash: |

.azure/windows-stack.yml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
# Installing happy and alex standalone to avoid error "strip.exe: unable to rename ../*.exe; reason: File exists"
4747
stack install happy --stack-yaml $STACK_YAML
4848
stack install alex --stack-yaml $STACK_YAML
49+
stack install cabal-install --stack-yaml $STACK_YAML
4950
stack build --only-dependencies --stack-yaml $STACK_YAML
5051
displayName: 'stack build --only-dependencies'
5152
- bash: stack test --no-run-tests --ghc-options=-Werror --stack-yaml $STACK_YAML

.ghci

-25
This file was deleted.

README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ There are more details about our approach [in this blog post](https://4ta.uk/p/s
2525
| Display type and source module of values | hover |
2626
| Remove redundant imports, replace suggested typos for values and module imports, fill type holes, insert missing type signatures, add suggested ghc extensions | codeAction (quickfix) |
2727

28+
29+
## Limitations to Multi-Component support
30+
31+
`ghcide` supports loading multiple components into the same session so that
32+
features such as go-to definition work across components. However, there are
33+
some limitations to this.
34+
35+
1. You will get much better results currently manually specifying the hie.yaml file.
36+
Until tools like cabal and stack provide the right interface to support multi-component
37+
projects, it is always advised to specify explicitly how your project partitions.
38+
2. Cross-component features only work if you have loaded at least one file
39+
from each component.
40+
3. There is a known issue where if you have three components, such that A depends on B which depends on C
41+
then if you load A and C into the session but not B then under certain situations you
42+
can get strange errors about a type coming from two different places. See [this repo](https://github.com/fendor/ghcide-bad-interface-files) for
43+
a simple reproduction of the bug.
44+
2845
## Using it
2946

3047
### Install `ghcide`
@@ -308,7 +325,7 @@ Now opening a `.hs` file should work with `ghcide`.
308325

309326
## History and relationship to other Haskell IDE's
310327

311-
The teams behind this project and the [`haskell-ide-engine`](https://github.com/haskell/haskell-ide-engine#readme) have agreed to join forces under the [`haskell-language-server` project](https://github.com/haskell/haskell-language-server), see the [original announcement](https://neilmitchell.blogspot.com/2020/01/one-haskell-ide-to-rule-them-all.html). The technical work is ongoing, with the likely model being that this project serves as the core, while plugins and integrations are kept in the [`haskell-language-server` project](https://github.com/haskell/haskell-language-server).
328+
The teams behind this project and the [`haskell-ide-engine`](https://github.com/haskell/haskell-ide-engine#readme) have agreed to join forces under the [`haskell-language-server` project](https://github.com/haskell/haskell-language-server), see the [original announcement](https://neilmitchell.blogspot.com/2020/01/one-haskell-ide-to-rule-them-all.html). The technical work is ongoing, with the likely model being that this project serves as the core, while plugins and integrations are kept in the [`haskell-language-server` project](https://github.com/haskell/haskell-language-server).
312329

313330
The code behind `ghcide` was originally developed by [Digital Asset](https://digitalasset.com/) as part of the [DAML programming language](https://github.com/digital-asset/daml). DAML is a smart contract language targeting distributed-ledger runtimes, based on [GHC](https://www.haskell.org/ghc/) with custom language extensions. The DAML programming language has [an IDE](https://webide.daml.com/), and work was done to separate off a reusable Haskell-only IDE (what is now `ghcide`) which the [DAML IDE then builds upon](https://github.com/digital-asset/daml/tree/master/compiler/damlc). Since that time, there have been various [non-Digital Asset contributors](https://github.com/digital-asset/ghcide/graphs/contributors), in addition to continued investment by Digital Asset. All contributions require a [Contributor License Agreement](https://cla.digitalasset.com/digital-asset/ghcide) that states you license the code under the [Apache License](LICENSE).
314331

0 commit comments

Comments
 (0)