Currently this only searches local documentation (generated with
`cabal haddock --haddock-hyperlink-source` or equivalent) but could be
extended to support searching via Hoogle in the future. And it works for
any of the core libraries since they come installed with documentation.
Will show up in hover and (non-local) completions.
Also fixes extra markdown horizontal rules being inserted with no
content in between them.
* Code action: remove redundant constraints for type signature
* Handle peculiar formatting
Make the content parsing safe for type signature formatted with an
arbitrary and unexpected number of spaces and/or line feeds.
* Update to hie-bios 0.6.1
* Obtain the GHC libdir at runtime using hie-bios
This replaces hardcoding the GHC libdir path with ghc-paths and instead
gets it at runtime through the hie-bios cradle. This means that the
ghcide binary should be a bit more distributable now, since it won't
rely on paths baked at compile time that are local to the machine it was
compiled on. And we also no longer need the ghcLibCheck since we are
comparing the coompiled and runtime versions with the installationCheck
(ghcVersionChecker)
Co-authored-by: Fendor <power.walross@gmail.com>
* Code action to add default type annotation to satisfy the contraints
this is useful when using `traceShow` with with OverloadedStrings
and type-defaults warning enabled
Handle the following cases:
- there is one literal and one contraint to be satisfied
- there are mulitple literals and/or multiple constraints
Adding type annotations to expressions that trigger type-defaults
warning is not part of this changes
* Simplify older test
* Fix hlint issue
* Use global NameCache for reading HIE files
Co-authored-by: Matthew Pickering <matthewtpickering@gmail.com>
* ignore hlint
* redundant imports
* Use hie files as source of truth for name source spans.
Since we started reusing `.hi` files, this exposes a bug where definitions
aren't available since a bad source span from the `.hi` file gets put into
the NameCache. We rectify by ensuring the span in the NameCache always matches
the one from the `.hie` file.
This has surfaced because an interaction between the commit which uses `.hi`
instead of retypechecking and the change to use the shared global NameCache
to read `.hie` files.
* Add test for missing definitions
Co-authored-by: Matthew Pickering <matthewtpickering@gmail.com>
* Faster completions
* optimize withProgressVar
We never remove elements from the map so alter is unnecesary
* [ghcide-bench] accept ghcide options
* Expand completion tests suite
* hlints
* completions for local foreign decls
* Minor improvements for local completions
* Restore completion docs in legacy code path
* Compatibility with GHC < 8.8
* fix merge issue
* address review feedback
* Fix regression in SpanInfo haddocks for local modules
The regression was introduced in #630.
I added `GhcSessionDeps` with the idea of reusing the typecheck GHC session
for computing the SpanInfo, instead of rebuilding it from scratch.
But I forgot to actually reuse it, or maybe the change got lost during the merge.
* Add test
* Hi file stability
* fix missing early cutoff in GetModIface
* tests for TH reloading
* Do not run hlint on test/data
* hlints
* Fix legacy code path
* Update test/exe/Main.hs
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Add missing instance constraint
* Add missing instance constraint with existing constraints
* Add missing function constraint
* Add missing function consraint with existing constraints
* Add some comments
* Improve type signature regex
* Remove redundant bracket
* Improve missing constraint searching.
Create entrypoint for missing constraint code action, in order to have a more
efficient parsing by routing to the relevant implementation.
Fix type signature name parsing.
Minor refactor.
* Minor refactor
* Delete unused top level binding code action
* Remove redundant brackets according to hlint
* Attempt to fix build issue on ghc-8.4
* Fix delete unused binding code action
- handle case of top level bindings defined in infix form
- when deleting some unused binding expand text deletion range to
beginning of next top level binding (if any was found)
* Modify delete unused binding code action
Sort all inspected bindings by location before processing
* Avoid sending top level binding delete action with no TextEdit
Happens when there is unused local binding
* Add test for inconsistent diagnostics
* Refactoring ModIfaceFromDisk
This started as a pure refactoring to clarify the responsibilities between
ModIface and ModIfaceFromDisk, but ended up having some behaviour changes:
1. Regenerate interface when checkOldIface returns something other than
UpToDate. This was a bug.
2. Do not generate a diagnostic when regenerating an interface.
2. Previously we conflated stale interface with other errors,
and would regenerate in both cases. Now we only regenerate in the first case.
Tentative fix for #597
* Split interface tests
* Always recompile modules with TH splices
Tentative fix for #614
TODO support stability
* Fix expectDiagnostics in MacOs
* Avoid File does not exist diagnostics for interface files
Fixes#642
* Clarify interface tests
* hlints
* Performance fixes
The previous changes were 10X slower, this is 20X faster than those, so 2X
faster than upstream, for some benchmarks
* formatting
* Fix GetModificationTime identity
The answer for a GetModification query is independent of the missingFileDiagnostics field
(as the diagnostics are not part of the answer)
* remove stale comment
* Avoid calling ghcSessionDepsDefinition twice
* Apply suggestions from code review
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Code review feedback
* Address review feedback
49b0d9ac65 (r443383239)
* Change recomp to direct cradle
Co-authored-by: Zubin Duggal <zubin@cmi.ac.in>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Cache the results of loadSession until the components change
* Track the cradle dependencies
* hlint
* Add cradle to watched files test
* Add comment on sessionVersion field
* send WorkDoneProgressEnd only when work done
* Progress reporting now spans over multiple overlapping kicks
* Repurpose benchmark experiments as tests
Fixes#650
* use stack to fetch from Hackage
* benchmark tests run with the same lsp-test config as other tests
* Fix stack cradle in benchmark
* Make stack unpack --silent
* Fix issues in "code actions after edit" experiment
- Repeated breaking edits make ghc run out of suggestions
- Diagnostics seem to come and go in-between edits, which leads to a timing
issue when asking for code actions. The fix is to wait for diagnostics to be
present before asking for code actions
* Fix stack.yaml generation in example project
* Fix getDefinition in GHC 8.4
Did it break before 0.2.0 or after?
* better naming for the progress event TVar
* stop progress reporting in shakeShut
https://github.com/digital-asset/ghcide/pull/649#discussion_r443408884
* hlint
Since the code action for language extension suggestions uses substring
matching, the presence of the literal name of an extension can trigger
a false positive.
`Strict` is an identifier that occurs frequently in imports, causing
the extension to be suggested rather than the removal of a redundant
import.
On macOS, the $TMPDIR folder leads to /var/blahblahblah, but this is
canonicalized to /private/var/blahblahblah for reasons beyond my
understanding. Either way, there were some test failures because of a
mismatch between the two, so canonicalize the Uris inside the locations
to fix this
* ShakeSession and shakeRunGently
Currently we start a new Shake session for every interaction with the Shake
database, including type checking, hovers, code actions, completions, etc.
Since only one Shake session can ever exist, we abort the active session if any
in order to execute the new command in a responsive manner.
This is suboptimal in many, many ways:
- A hover in module M aborts the typechecking of module M, only to start over!
- Read-only commands (hover, code action, completion) need to typecheck all the
modules! (or rather, ask Shake to check that the typechecks are current)
- There is no way to run non-interfering commands concurrently
This is an experiment inspired by the 'ShakeQueue' of @mpickering, and
the follow-up discussion in https://github.com/mpickering/ghcide/issues/7
We introduce the concept of the 'ShakeSession' as part of the IDE state.
The 'ShakeSession' is initialized by a call to 'shakeRun', and survives until
the next call to 'shakeRun'. It is important that the session is restarted as
soon as the filesystem changes, to ensure that the database is current.
The 'ShakeSession' enables a new command 'shakeRunGently', which appends work to
the existing 'ShakeSession'. This command can be called in parallel without any
restriction.
* Simplify by assuming there is always a ShakeSession
* Improved naming and docs
* Define runActionSync on top of shakeEnqueue
shakeRun is not correct as it never returns anymore
* Drive progress reporting from newSession
The previous approach reused the shakeProgress thread, which doesn't work anymore as ShakeSession keeps the ShakeDatabase open until the next edit
* Deterministic progress messages in tests
Dropping the 0.1s sleep to ensure that progress messages during tests are
deterministic
* Make kick explicit
This is required for progress reporting to work, see notes in shakeRun
As to whether this is the right thing to do:
1. Less magic, more explicit
2. There's only 2 places where kick is actually used
* apply Neil's feedback
* avoid a deadlock when the enqueued action throws
* Simplify runAction + comments
* use a Barrier for clarity
A Barrier is a smaller abstraction than an MVar, and the next version of the extra package will come with a suitably small implementation:
98c2a83585
* Log timings for code actions, hovers and completions
* Rename shakeRun to shakeRestart
The action returned by shakeRun now blocks until another call to shakeRun is made, which is a change in behaviour,. but all the current uses of shakeRun ignore this action.
Since the new behaviour is not useful, this change simplifies and updates the docs and name accordingly
* delete runActionSync as it's just runAction
* restart shake session on new component created
* requeue pending actions on session restart
* hlint
* Bumped the delay from 5 to 6
* Add a test for the non-lsp command line
* Update exe/Main.hs
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* 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>
* 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 820aa24189.
* 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 <alan.zimm@gmail.com>
Co-authored-by: fendor <power.walross@gmail.com>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* 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>
* Track dependencies when using qAddDependentFile
Closes#492
* Add test for qAddDependentFile
* Update test/exe/Main.hs
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Update test/exe/Main.hs
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* [#518] Build ghcide with GHC 8.10.1
Resolves#518
* Move CPP logic to the Compat module
* Revert changes to mkHieFile
* Add local fork of HieAst for 8.10.1
The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed
* Ignore hlint in src-ghc810/HieAst.hs
* Whitelist CPP for Development.IDE.GHC.Orphans
* [#518] Build ghcide with GHC 8.10.1
Resolves#518
* Move CPP logic to the Compat module
* Revert changes to mkHieFile
* Add local fork of HieAst for 8.10.1
The fix for mkHieFile didn't make it into 8.10.1, so the override is still needed
* Ignore hlint in src-ghc810/HieAst.hs
* Whitelist CPP for Development.IDE.GHC.Orphans
* Plugin tests known broken in 8.10.1 (#556)
* Bump up ghc-check version
Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>
Co-authored-by: pepe iborra <pepeiborra@gmail.com>
* 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
* Create rule to get ModSummary without parsing entire source file
* Load file source from disk if not available in memory
* Fix build after cherry pick
* Couple of fixes
- extract getModSummaryFromImports and fix diagnostics
- replace GetParsedModule by GetModSummary where possible
There is only one usage of GetParsedModule left, and that is in GetSpanInfos
for documentation. This the wrong approach, docs should be loaded from
interface files and not from sources. TODO
* Fix watched file tests
Progress notifications are not being sent anymore
* Compat with GHC 8.6
* Avoid parsing source files for completions and documentation
Instead, embed haddocks in interface files
* Allow CPP in module
* Force things after parsing in order to release buffers
* avoid holding on to stringbuffer unnecessarily
* Skip unnecessary file contents read
* Drop HscEnv requirement
* Add comments on forcing things
* Add comments on GHC_LIB restriction
* Parse files of interest twice to capture Haddock errors
If Opt_Haddock is not enabled we parse twice to capture Haddock parse errors
* Parallelize two-pass parsing
* Update src/Development/IDE/Core/Compile.hs
Co-authored-by: Marcelo Lazaroni <lazaronijunior@gmail.com>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* 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>
* 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
The completion context determines whether we show completions for
types or completions for values. This is done by looking at the parsed
module.
This PR fixes two things:
1. While we only use the parsed module for getting the context
previously we got the parsed module out of the typechecked
module. This means that if you have a module that parses but
doesn’t typecheck, we will use the parsed module at the point where
it last typechecked which is out of date and produces incorrect (or
just no) contexts.
2. When we could not find a context, we defaulted to assuming we are
in a value context. Especially in combination with 1 but also just
in general, this is rather annoying. If we aren’t sure we should
show the user everything we have and not filter out some
completions. Filtering out completions interacts particularly badly
with VSCode’s default behavior of accepting the first completion
when you press return.
* 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
* Suggest missing imports via package exports map
At the expense of some space and initialization time, suggest imports now is
able to find suggestions in all the packages available to the project.
* BadDependency - include the key in the error message
* remove the assumption that the GhcSession is always available
* fix bad spacing
Co-Authored-By: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Add type annotation to clarify rule being defined
* Remove file dependency from PackageExports rule
* Guess patterns
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* 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)
* Group Imports in Outline into a single node
Makes it easier to see symbols in scope when you have lots of
import statements.
* Prefer explicit Maybe over List type
* Code action to suggest adding missing imports from pkg db
The implementation looks in modules loaded from the package database. It should
only look in packages declared as dependencies of the project. The package
modules are loaded lazily and are global to the HscEnv, so the success rate will
depend on what has been loaded so far in the env.
* Avoid overlapping with extend import suggestions
> import Data.Text (Text)
> foo = pack "foo"
Teach ghcide to suggest only:
"Add pack to the import list of Data.Text"
and avoid suggesting also:
"Import Data.Text (pack)"
* 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