* 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
* parse lsp client configuration to track workspace roots
* Only use Watched files on workspace files
* Apply suggestions from code review
Co-Authored-By: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Add tests for watched files
Left as future work: adding tests for workspace folder notifications
* Add a test for file creation outside workspace
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Don't support old haddock-library versions
* Update stack.yaml values
* Remove some more haddock_library CPP
* Make sure the latest haddock-library is on GHC 8.4
* Enhancements to Haddock -> Markdown conversion
* Add tests for Haddock -> Markdown conversion
* Make HLint happy
* Let Haddock tests compile also in 8.4
* Fix build for 8.4
* Fix test for haddock-library 1.8.0
* Fix CPP problem
* Make tests a bit more readable
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Support more kinds of literals in hover
* Fix for HLint
* Fix for GHC 8.8
* Fix for 8.4
* Fix 8.4 + suggestions by @cocreature
* More fixes for 8.4
* Deal with type sigs in all GHC versions
* Additional case for 8.4
* Separate isLit and isChildLit
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
* Keywords in completion
* Update src/Development/IDE/Core/Completions.hs
Co-Authored-By: fendor <fendor@users.noreply.github.com>
* Fix the other usage of "keywrd"
Co-authored-by: fendor <fendor@users.noreply.github.com>
* Show kinds in hover
* Documentation on hover
* Enable kind tests
* Fix tests
* Print literals
* Show (some) overloaded literals
* Fix for 8.4
* Fix tests
* Do not consider literals for definitions
* Suggestions by @cocreature
* No warning for 8.4
* More fixes for 8.4
* Make it work with ghc-lib
* More fixes for warnings when compiled with ghc-lib
* More fixes to build in ghc-lib
* Try once again to build with ghc-lib
* More fixes for ghc-lib
* Fix warning with ghc-lib
* 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
* Fix source spans for multi-clause definitions
Currently, we use the source span of the match which corresponds to
the whole clause instead of just the function identifier. This
resulted in us pointing every goto definition request within a clause
to the function if there is no other information (either because it
failed because it came from an external package or simply because you
are not on an identifier).
This PR fixes this by getting the proper source spans frmo the
HsMatchContext. Somewhat annoyingly, we have to get it from the parsed
module since GHC messes this up during typechecking but it’s
reasonably simple.
* Remove JSON instances for completions, since we are not implementing "resolve"
* Remove completion resolve data from tests
* Better docs
* Fix tests
* Fix for 8.4
* Turn Haddock markup into Markdown
* Add types to completion items
* Make it work on 8.8 and 8.4
* Revert "Remove completion resolve data from tests"
This reverts commit 625d710f11.
* Revert "Remove JSON instances for completions, since we are not implementing "resolve""
This reverts commit 12ff27dce7.
* Fix tests
* Require higher version of regex-pcre-builtin
* Replace Pandoc with direct conversion from Haddock to Markdown
* Show kinds of type constructors too
* A few fixed to Markdown conversion
* Check optNewColonConvention
* Fix build on 8.4 and 8.8
* More fixes for 8.4 and 8.8
* Check only the common part of the completion text
* Make icons consistent with Outline
* Test docs for completions
* Make constructors return the corresponding CompletionItem + tests for that behavior
* Make test work on 8.4
* Tests for issue 310 (misleading hover on inner signature)
The most important pair of tests here is the "inner signature" pair. The others
serve mainly to document, compare and contrast what is happening in related
situations.
In summary, hover and gotoDef
+ on inner signatures: give type and location information for the outer
definition; this is misleading,
+ on outer signatures: give no information at all,
+ on inner definitions: give correct information for the inner definition,
+ on outer definitions: give correct information for the outer definition.
Should hover and gotoDef do anything at all for signatures? or is the current
behaviour for outer signatures (doing nothing at all) what we want?
* Require signature hover/gotoDef to point to first clause of definition
* Remove perhaps superfluous tests for definitions
* Smarter logic to remove redundant import bindings
The new code finds the spans to remove using the GHC parse tree, then manually
extends them to include commas/spaces.
Fixes#299
* Compatibility with GHC 8.4
* Improve comment
Co-Authored-By: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Use breakOnEnd in unqualify
This will handle A.foo as well as A.B.foo
Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Document symbols provider
* Compatibility with GHC 8.4
* Replace large number with more descriptive maxBound
Co-Authored-By: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Use SkFunction for all Val Declarations
* Improve outlining of PatBind and FunBind
No longer relying on gfindtype
Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Test for #45
* Remove redundant symbols from imports
Fixes#45
* Update src/Development/IDE/LSP/CodeAction.hs
Co-Authored-By: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Apply suggestions from code review
Co-Authored-By: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Add regex-tdfa extra deps to ghc-lib build
* Fix for GHC 8.4 (error message prints qualified binding)
GHC ticket #14881 changed this to print identifiers unqualified
* dropBindingsFromImportLine: make total
Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
* Initial implementation of completion support
* Add fuzzy to set of additional dependencies in 8.8
* Fix test
* Work a bit more on completion
* Attempt at getting completions from last good tckd module
* Revert "Attempt at getting completions from last good tckd module"
This reverts commit 04ca13b9d8.
* "useWithStale" everywhere
* Some suggestions by @cocreature
* Adjust positions in the document
* Start working on tests
* Fix compilation problem
* Fix tests
* Better type tests