Commit Graph

53 Commits

Author SHA1 Message Date
Matthew Pickering
5e4e87822e Final tweaks? 2020-05-23 10:59:02 +01:00
Matthew Pickering
9527499f45 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 <alan.zimm@gmail.com>
Co-authored-by: fendor <power.walross@gmail.com>
2020-05-23 10:56:58 +01:00
fendor
9129475b87
Update to hie-bios 0.5.0 (#552)
* Update to hie-bios 0.5.0

* Fix test-cases due to changes in the direct cradle

* Update test/exe/Main.hs comment

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-05-23 09:54:25 +02:00
Pepe Iborra
ec0bbd1b1d
Remove interface loading diagnostics (#579)
* Drop interface loading diagnostics

* No reason to skip the --test flag anymore
2020-05-22 16:13:01 +02:00
Pepe Iborra
d54fd38b14
Log cache dir (#567) 2020-05-18 10:26:04 +02:00
Pepe Iborra
15bb044269
Improve ghc version check (#535)
- retrieve runtime version from ghc executable, not from pkg db (ghc-check 0.3.0.0)
- Do not error when unable to retrieve runtime version
2020-05-08 15:48:05 +02:00
Alan Zimmerman
78d4031f7c
Add a custom prefix to command IDs (#500)
* Add a custom prefix to command IDs

A client can run more than one instance of ghcide.  Some clients have a global
command registry, and all commands must be unique in that registry.

So to make the command ids unique, prefix them with the ghcide server process
id, as is done in haskell-ide-engine.

* Use same command naming scheme as in haskell-language-server

To ease interoperability

* Use makeLspCommandId for prefixing commands

This puts all the prefixing logic in one place.

* Add hlint exception for CPP in Development.IDE.Compat

* Bring in Win32 dependency for windows build
2020-04-27 12:59:13 +02:00
Pepe Iborra
39605333c3
Expose an option to control the number of Shake threads (#504) 2020-03-27 10:54:15 +01:00
Pepe Iborra
9ccd9eec08
Detect ghc mismatch (#462)
* Detect ghc version mismatches

* Add ghc-check to stack extra deps

* ghc-check: explicit libdir and delay version error
2020-03-24 12:40:21 +01:00
Pepe Iborra
f804b138dc
Support for interface files (#457)
* Rules for loading interface files

* Typechecking with interface files

* Add a note in the README about the optimal project setup

* Improve support for hs-boot files

The branch was failing to load GHC because the module graph was missing
edges between a .hs file and its .hs-boot file. This means the .hs-boot
file was getting added into the HPT after the .hs file which led to
confusing errors about variables being out of scope.

The fix is to maintain a map from hs-boot to hs files and then add an
edge for this case when calling `transitiveDependencies`.

Also tidy up some code in setupEnv which I assume was attempting to fix
this but in an incorrect manner.

Add the -boot suffix when looking for hi-boot files.

For some reason, the `hi` path is not set to the right thing for
`hs-boot` files. I don't know why not perhaps it is ok to use an
existing `.hi` file in place of an `hs-boot` file. More investigation
needed. My experience is that GHC is quite bad a recompilation avoidance
for hs-boot files anyway.

For example: https://gitlab.haskell.org/ghc/ghc/issues/17434

Add the -boot suffix when writing interface files

* Generate .hi and .hie files during type checking

* Refactor GetModIface to not retain TypeChecked module in memory

This improves memory performance on a cold cache.

* Trailing whitespace

* Turn debug log messages into diagnostics

* Implement "hie" files for ghc-8.6.5

This means that the .hi files patch can also be used with 8.6.5

* Add tests for hover/definition on imported symbols

* hlints

* Generate .hie files when missing

* Fix subtle bug in setDefaultHieDir

* Simplify optimal project setup in README

* Move interface loading diagnostics behind --test flag

Reusing the --test flag for this seems harmless, I cannot justify introducing a
new flag

* Avoid expensive interface file generation for files of interest

* avoid redundant arguments (thanks Moritz K)

* qualify a DAML only comment

* Skip module source when generating hie file

thanks Moritz Kiefer for noting that we don't care for the generated .hie files
to embed module sources

* runGhcEnv <-> evalGhcEnv

* Apply suggestions from code review

Thanks Moritz Kiefer

Co-Authored-By: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

* Add suggested Show instance

Co-Authored-By: Matthew Pickering <matthewtpickering@gmail.com>

* Use Control.Exception.Safe

This is to avoid accidentally capturing asynchronous exceptions

* Rename atomicFileUpdate

* Fix a flaky test

We have to be careful with module naming in tests to avoid interference of .hi
files across tests

* Undo formatting of D.IDE.GHC.Util

* follow changes in master

Co-authored-by: Matthew Pickering <matthewtpickering@gmail.com>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-03-24 12:39:53 +01:00
Javier Neira
9951f35b08
Use NormalizedFilePath and adapt types of haskell-lsp-0.21 (#479)
* Use custom version of h-l-t

* Use normalized path functions from h-l-t

* Restore empty path corner case

* Create a wrapper over NFP to override IsString

* Use maybe instead fromMaybe

* Use patched version of lsp-types in all yaml files

* Remove unused import

* Rename specific NormalizeFilePath to NormalizeFilePath'

* Remove specific newtype and IsString instance

* Use released haskell-lsp-0.21

* Adapt to type changes of haskell-lsp-0.21

* Add tags field to CompletionItem

* Fix test case about empty file path

* Correct stack.yaml used in azure ci cache

* Build ghcide including tests in windows azure ci

* Qualify haskell-lsp modules to avoid name clashes
2020-03-23 09:07:04 +01:00
Alan Zimmerman
8b328bb7c5
Working on Plugin support for haskell-language-server (#477)
* Working on Plugin support for hls

Fix PluginCommand reply type for executeCommand needs

* Remove PluginCommand

It will move to haskell-language-server instead

* Make azure CI hlint happy

By removing explicit OverloadedStrings pragma, in favour of the one already
enabled in the cabal file.

* Remove unneeded 'do'

* Fix more nits from review
2020-03-16 11:31:18 +01:00
Pepe Iborra
c74e9b51f1
Fix two regressions since 0.1.0 (#471)
* Fix isWorkspaceFile for relative paths

This fixes a performance regression on GetFileExists

* Avoid interrupting hie-bios when it's doing its thing

I noticed that the GHC hie-bios direct cradle, which uses Hadrian, a Shake build
system, was failing to start due to the following problem:

1. ghcide starts evaluating the LoadCradle node
2. The evaluation gets cancelled
3. Immediately after, ghcide starts evaluating LoadCradle again
4. Hadrian fails, since there is still another Hadrian process alive taking its
Shake lock

* Improve watched files test suite
2020-03-10 18:06:39 +01:00
Pepe Iborra
0bf4e91ba4
Refactoring: remove isTesting from ShakeExtras (#469)
isTesting got added to ShakeExtras unnecessarily
2020-03-09 13:23:41 +01:00
Moritz Kiefer
bd25cd01ac
Set the streams to utf8 in Main.hs (#466) 2020-03-05 15:34:24 +01:00
Pepe Iborra
df63fd76c0
Tests for cradle loading (#460)
* Refactor: extract Rules to a separate module

* Add tests for cradle loading

* Fix default extensions in exe target

* Move cradle loaded messages behind a flag

* Use satisfy

Following a suggestion by Moritz Kiefer (@cocreature)
2020-03-04 17:31:24 +01:00
Pepe Iborra
ff62fdd87d
Fix regression in cradle loading logic (#450)
We were calling runCradle multiple times per cradle, concurrently. For Cabal
cradles this function runs Cabal, which is neither fast nor designed to be run
concurrently
2020-02-26 09:16:17 +01:00
Pepe Iborra
48a7867a07
Local hidir and hiedir folders to avoid conflicts with Cabal (#441)
* Local hidir and hiedir folders to avoid conflicts with Cabal

hi files created by ghcide would have different optimization settings,
triggering Cabal recompilation if they were stored in Cabal folders

hie files would end up in the src folder as -hiedir is not set by Cabal

Telling GHC to write interface/hie files is pointless since we do it ourselves,
and it also leads to the recompilation checker getting confused

Using hie-bios initSession does things like setting up the cache directory for
interface files and other things which ghcide would rather manage itself.

* linker options

Co-authored-by: Matthew Pickering <matthewtpickering@gmail.com>
2020-02-20 12:32:20 +01:00
Jinwoo Lee
00d914efa7
Automatically pick up new dependencies (#408)
* Automatically pick up new dependencies

hie-bios's componentDependencies returns the dependencies of a cradle
that might change the cradle. Add those deps to the shake graph so that
the GHC session is newly created whenever they change.

For that, add a new rule type, GetHscEnvEq, to cache GHC sessions with
the key of GHC options and dependencies. And delete the optGhcSession
field from IdeOptions.

This is for https://github.com/digital-asset/ghcide/issues/50.

hie-bios's componentDependencies can return files that don't exist yet:
https://github.com/mpickering/hie-bios/blob/master/src/HIE/Bios/Types.hs#L90-L93.
This PR handles changes in the existing dependency files, but doesn't
handle newly created dependency files.

* address comments

* revert hie.yaml

* address more comments

* add test

* make direct cradles work; and use direct cradle in test
2020-02-17 10:33:33 +01:00
Alan Zimmerman
71ecd105d9
Parameterize the haskell-lsp client config type (#416)
So that haskell-language-server can use its own config

And separate it out from the IdeConfiguration which is separately set by the
InitializeRequest message.
2020-02-14 13:21:27 +01:00
Moritz Kiefer
4e89d4574d
Use HashMap/HashSet for maps indexed by Normalized{FilePath,Uri} (#420)
Now that we have optimized Hashable instances for these, it makes
sense to use this consistently.
2020-02-11 10:09:48 +01:00
Matthew Pickering
76221fb354 Display output from initialising cradle in debug mode (#411) 2020-02-10 10:43:42 +01:00
Moritz Kiefer
4aaba4d3e0
Make debouncer configurable (#409)
We have been experiencing a few flaky tests in DAML caused by our CLI
compiler losing diagnostics. The reason for that is the debouncer
which meant that messages got delayed and not send before the process
exited.

This PR makes the debouncer abstract and adds a noopDebouncer which
doesn’t do any debouncing. This is also what we use in the terminal
ghcide test thingy.
2020-02-06 20:57:55 +01:00
fendor
1d04b09add
Update to latest hie-bios (#382)
* Update to latest hie-bios

* Remove explicit usage of type parameter Void from Cradle
2020-02-04 11:09:50 +01:00
Neil Mitchell
f06cae0cd1
Make ghcide on the command line use absolute file paths (#401) 2020-02-04 10:15:49 +01:00
Matthew Pickering
cb2828795d Pass shake-profiling option when not using --lsp (#385) 2020-01-28 09:04:02 +01:00
Neil Mitchell
331a144296 Add plugin type (#365)
* Add a plugin type

* Add a helper to construct codeAction values

* Remove a redundant $
2020-01-26 11:28:11 +00:00
Alan Zimmerman
20a723a47f Fix typo (#366) 2020-01-26 11:11:40 +00:00
Neil Mitchell
3ccebde867 Move the completions and code actions into Plugin (#359)
* Move the completions into a Plugin pile

* Fix HLint

* Turn CodeAction into a plugin as well

* Fix HLint

* Remove a redundant def <>
2020-01-26 09:36:48 +00:00
Pepe Iborra
2d9314ae1d Fix performance of getFileExists (#322)
* Improve hover performance by speeding up getFileExists

We touch the file system only the first time.
After that, we rely on the lsp client to tell us if a file is created or deleted

Fixes #101
2020-01-21 09:05:58 +01:00
Pepe Iborra
db456b0e51 Add a new flag --shake-profiling DIR (#307)
The flag provides a way to enable Shake profiling reports without recompiling.
Debug output prints links to the Shake reports for convenience
2020-01-06 19:56:40 +01:00
Pepe Iborra
b78efe36bb Extend version message to include path and git commit (#306) 2020-01-06 09:13:14 +01:00
Moritz Kiefer
b2ad2eb361
Fix build with Shake 0.18.4 (#272)
Shake 0.18.4 started exporting Info from this module which clashes
with the one from haskell-lsp. Fixes #271
2019-12-18 11:24:54 +01:00
Alejandro Serrano
1b1c58518d Filter out completely warnings not enabled by user (#263)
* Filter out completely warnings not enabled by user

* Suggestions by @cocreature

* Add tests

* Work more on tests

* Fix tests
2019-12-17 15:13:12 +01:00
Moritz Kiefer
fc30f1476f
Upgrade to hie-bios (#257)
This does not yet take advantage of any new features but we should at
least be able to benefit from bugfixes.
2019-12-16 11:42:44 +01:00
Jinwoo Lee
fa2c295f74 Indicate failures with exit code in command-line mode. (#233)
It'd be useful for scripting or integration tests.
2019-12-12 09:00:49 +01:00
Pepe Iborra
5091a1d202 Fix horrible path normalisation issue (#225) 2019-12-08 17:07:15 +01:00
Moritz Kiefer
5febbcbc48
Fix progress reporting (#153)
* Fix progress reporting

* Bump haskell-lsp and lsp-test revisions

* Change client name

* Fix typo

* Bump revisions
2019-10-17 11:11:52 +02:00
Jacek Generowicz
e583f13d8d Issue visual warning for humans if --lsp option used (#161)
Experience shows that people sometimes mistakenly start `ghcide` on
the command line with the `--lsp` option (which is intended to be used
only in server/client communication scenarios) and then wonder why
nothing is working..

So let's issue a warning message whenever `--lsp` is used.
2019-10-08 19:43:32 +02:00
Neil Mitchell
9d45eee21c #137, make the status message clearer about what worked and what didn't (#138) 2019-09-27 15:18:24 +02:00
Neil Mitchell
60ed687de9 Support multiple hie.yaml files (#127)
* Hack around https://github.com/mpickering/hie-bios/pull/56 - hie-bios expects files to really exist on disk

* Fix getLocatedImportsRule to pass the file to the session

* Add support for multiple simultaneous hie.yaml files.
Also rewrites the user experience on setup to be less verbose.
Also adds masking for GHC session construction.

* HLint

* Code review comments

* Switch to the Strict map
2019-09-25 13:01:41 +02:00
Jacek Generowicz
c24ef1c288 Add --version CLI option (#106)
* Add --version CLI option

* Extract ghcide version from cabal

* Extract precise GHC version from cabal preprocessor macro
2019-09-23 08:50:28 +02:00
Neil Mitchell
50e35f0e98 Use the hie-bios function that doesn't perform a downsweep. Fixes #99 (#102) 2019-09-20 17:33:37 +02:00
Ollie Charles
9a5ee23c01 Build on GHC 8.8 (#43) 2019-09-16 15:20:48 +02:00
Neil Mitchell
fc939e7dfb Add a comment that the test needs to change for multi environment 2019-09-11 09:34:16 +01:00
Neil Mitchell
405d62b064 Add multi environment support 2019-09-11 09:13:18 +01:00
Moritz Kiefer
5da86c3e44 Rename hie-core to ghcide (#2820)
* Rename hie-core to ghcide

The name `hie-core` has caused a lot of confusion as to how we relate
to haskell-ide-engine so changing it should hopefully help with that.
I also think that ghcide is still a good name once we hopefully
integrate with haskell-ide-engine more closely.

The name ghcide seems to have a reasonable amount of support on
Twitter https://twitter.com/ndm_haskell/status/1170681262987710464
which is of course the only good way to come up with names.

* Add a readme that points people to the new directory.

* Fix bogus replacements

* Use a proper link

* links are hard
2019-09-10 15:01:29 +02:00
Neil Mitchell
9bd78857d8 #2326, GHC 8.4 compatibility (#2796)
* #2326, GHC 8.4 compatibility

* Fix up CI

* Add a Shake lower bound

* Upgrade to a hie-bios which is GHC 8.4 compatible

* Add a GHC 8.4 stack

* Fix HLint again
2019-09-10 14:52:17 +02:00
Andreas Herrmann
bf7fea4f1d hie-core exe: initDynLinker (#2555)
The hie-core tests are flaky in stack. They can fail with the following
error message

```
hie-core: panic! (the 'impossible' happened)\n  (GHC version 8.6.5 for x86_64-unknown-linux):
        Dynamic linker not initialised

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
```

Explicitly initializing the dynamic linker at session startup should
avoid this issue.
2019-09-10 14:52:17 +02:00
Moritz Kiefer
0f0e6740c1 Only report progress when client supports it (#2517)
* Only report progress when client supports it

This fixes an issue that some people encountered when running hie-core
in Emacs with a version of haskell-lsp that does not understand
progress events.

* Fix tests

* More test fixes
2019-09-10 14:52:17 +02:00