#129, add a very basic setup guide (#142)

This commit is contained in:
Neil Mitchell 2019-09-30 07:54:57 +01:00 committed by Moritz Kiefer
parent a126bf3530
commit e7d3d129ae
2 changed files with 43 additions and 7 deletions

View File

@ -4,7 +4,6 @@ Note: `ghcide` was previously called `hie-core`.
Our vision is that you should build an IDE by combining:
<img style="float:right;" src="img/vscode2.png"/>
* [`hie-bios`](https://github.com/mpickering/hie-bios) for determining where your files are, what are their dependencies, what extensions are enabled and so on;
@ -22,7 +21,7 @@ There are more details about our approach [in this blog post](https://4ta.uk/p/s
| Feature | LSP name |
| - | - |
| Display error messages (parse errors, typecheck errors, etc.) and enabled warnings. | diagnostics |
| Go to definition in local package | definition |
| Go to definition in local package | definition |
| Display type and source module of values | hover |
| Remove redundant imports, replace suggested typos for values and module imports, fill type holes, insert missing type signatures, add suggested ghc extensions | codeAction (quickfix) |
| Organize imports | codeAction (source.organizeImports) |
@ -49,23 +48,22 @@ It's important that `ghcide` is compiled with the same compiler you use to build
Next, check that `ghcide` is capable of loading your code. Change to the project directory and run `ghcide`, which will try and load everything using the same code as the IDE, but in a way that's much easier to understand. For example, taking the example of [`shake`](https://github.com/ndmitchell/shake), running `ghcide` gives some error messages and warnings before reporting at the end:
```
Files that worked: 152
Files that failed: 6
```console
Files that failed:
* .\model\Main.hs
* .\model\Model.hs
* .\model\Test.hs
* .\model\Util.hs
* .\output\docs\Main.hs
* .\output\docs\Part_Architecture_md.hs
Done
Completed (152 worked, 6 failed)
```
Of the 158 files in Shake, as of this moment, 152 can be loaded by the IDE, but 6 can't (error messages for the reasons they can't be loaded are given earlier). The failing files are all prototype work or test output, meaning I can confidently use Shake.
The `ghcide` executable mostly relies on [`hie-bios`](https://github.com/mpickering/hie-bios) to do the difficult work of setting up your GHC environment. If it doesn't work, see [the `hie-bios` manual](https://github.com/mpickering/hie-bios#readme) to get it working. My default fallback is to figure it out by hand and create a `direct` style [`hie.yaml`](https://github.com/ndmitchell/shake/blob/master/hie.yaml) listing the command line arguments to load the project.
Once you have got `ghcide` working outside the editor, the next step is to pick which editor to integrate with.
If you can't get `ghcide` working outside the editor, see [this setup troubleshooting guide](docs/Setup.md). Once you have got `ghcide` working outside the editor, the next step is to pick which editor to integrate with.
### Using with VS Code

38
docs/Setup.md Normal file
View File

@ -0,0 +1,38 @@
# Setup Troubleshooting
This page serves as a dumping ground for setup problems and their resolutions. We recommend everyone first runs `ghcide` on the console to check what files in their project load, and only the moves on to using `ghcide` through an editor (e.g. VS Code).
## "mismatched interface file versions"
If you see a problem such as:
```console
File: ./test/Spec.hs
Range: 1:0-1:0
Source: typecheck
Severity: DsError
Message:
test/Spec.hs:1:1: error:
Bad interface file:
/Users/daml/.stack/programs/x86_64-osx/ghc-8.6.4/lib/ghc-8.6.4/base-4.12.0.0/Prelude.hi
mismatched interface file versions (wanted "8065", got "8064")
```
The cause is that your program is configured to use a different GHC to the one you built `ghcide` with. In `ghcide` you can view the version number it was compiled with on the first line as:
```console
ghcide version: 0.0.3 (GHC: 8.6.5)
```
You can see the version of GHC being used by this project in the second-last line of the output with `ghc-8.6.4/`, or in in mismatch interfaces of wanted `8065` (aka 8.6.5), got `8064` (aka 8.6.4). The solution is to use the same GHC version in both places.
## Works in `ghcide` but not my editor
Does `ghcide` alone work on the console? Did you first enter a Nix shell? Or run `stack exec ghcide`? If so, there are two options:
1. Run your editor via the same mechanism, e.g. `stack exec code`.
2. Change the extension to use the executable as `stack` and the arguments as `exec -- ghcide --lsp`.
## Issues with Nix
If you are using packages installed by Nix, then often Nix will set `NIX_GHC_LIBDIR` to say where the libraries are installed. `ghcide` can cope with that. However, sometimes the `ghc` on your shell will actually be a shell script that sets `NIX_GHC_LIBDIR`, which `ghcide` can't find. If that happens, you need to either set `NIX_GHC_LIBDIR` (so `ghcide` can see it) or use a proper [Nix compatible wrapper](https://github.com/hercules-ci/ghcide-nix) over `ghcide`.