Commit Graph

102 Commits

Author SHA1 Message Date
Neil Mitchell
3354a4f38c
Remove unnecessary HLint ignores now HLint 3.0.4 is out (#545) 2020-05-04 09:12:56 +02:00
Moritz Kiefer
9adb11125e
Fix HLint (#544)
Looks like the new version of hlint has a couple of new hints.

changelog_begin
changelog_end
2020-05-03 19:30:40 +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
4f9c7561ee
Parse module headers (#511)
* 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>
2020-04-27 11:05:39 +02: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
Moritz Kiefer
9b6e712251
Fix emptyPathUri (#502)
* Fix emptyPathUri

* Remove platform dependency
2020-03-23 12:21:23 +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
Moritz Kiefer
45f9742461
Improve completion contexts (#495)
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.
2020-03-20 14:42:10 +01:00
Matthew Pickering
7ecdd21874
Pass correct SafeHaskell information to mkIfaceTc (#489)
Seems like this was never implemented the first time, woops!

Fixes #424
2020-03-19 13:49:46 +01:00
Alan Zimmerman
111b6855e2
Use tasty-rerun to allow rerunning failed tests only (#484)
Use by

  stack --stack-yaml=stack84.yaml test --test-arguments "--rerun"
2020-03-16 09:07:50 +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
da92de218a
Guess all imports (#459)
* 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>
2020-03-09 13:22:46 +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
acc4a0a77c
Guess more imports (#451)
Now guess missing imports also works for:

- Type names
- Data constructors
- Operators
- qualified things

Avoiding:

- internal modules
2020-02-25 18:19:25 +01:00
fendor
1e68cb0e05
Group Imports in Outline into a single node (#443)
* 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
2020-02-21 11:21:00 +01:00
Pepe Iborra
5bea92f9d3
Code action to suggest adding missing imports from pkg db (#437)
* 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)"
2020-02-18 09:36:38 +01:00
Pepe Iborra
f586955e8a
Fix redundant import code action corner cases (#433)
- Redundant "All" imports, e.g. Maybe(..)
 - Redundant datatype plus constructors, e.g. Maybe(Just)

Fixes #352
2020-02-18 09:22:17 +01:00
Pepe Iborra
286635bac8
Suggestions for missing pattern signatures (#436) 2020-02-17 11:22:51 +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
Pepe Iborra
fd01d20cc9
Fix add suggested import for operators (#428) 2020-02-14 14:41:33 +01:00
Pepe Iborra
ffb05636b6
Workspace roots and getFileExists (#412)
* 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>
2020-02-13 13:34:11 +01:00
Matthew Pickering
2d71599faf
Run simplifier before generating ByteCode (#410)
Running the simplifier is necessary to do things like inline data
constructor wrappers.

Fixes #256 and #393
2020-02-12 13:09:47 +01:00
Neil Mitchell
52f3feab3e
Require GHC 8.6.5 for some docs tests (#398)
These doc tests fail on GHC 8.6.4, so restrict them to 8.6.5 and above. See https://github.com/haskell/haskell-language-server/issues/22
2020-02-02 18:51:58 +01:00
Neil Mitchell
913aa5f9fa Don't support old haddock-library versions (#375)
* 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
2020-01-28 20:20:38 +01:00
Moritz Kiefer
f695c50bda
Migrate tests for position mapping from DAML repository (#388)
Given that the code for this lives in ghcide it makes no sense for the
tests to be part of the DAML repository.
2020-01-28 10:31:28 +01:00
Alejandro Serrano
956e11dff8 Enhancements to Haddock -> Markdown conversion (#344)
* 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>
2020-01-27 16:30:54 +01:00
Alejandro Serrano
ea50c27fad Support more kinds of literals in hover (#339)
* 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>
2020-01-27 15:12:09 +01:00
Neil Mitchell
ae5c6d34d4 Move the definition of __GHCIDE__ (#377)
* Move the definition of __GHCIDE__ so we don't modify upstream copied code

* Add a test that __GHCIDE__ works
2020-01-27 12:57:27 +01:00
Neil Mitchell
c660830739 Fix some whitespace (#376)
* Trailing whitespace makes for unnecessary diffs

* Add trailing newline
2020-01-27 12:42:04 +01:00
sheaf
46c7634111 use GHC language extension names (#362) 2020-01-26 14:45:50 +00:00
Alejandro Serrano
1d32025e93 Keywords in completion (#351)
* 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>
2020-01-25 08:36:20 +00:00
Alejandro Serrano
2154bb2eaf Show constraints on hover (#338) 2020-01-22 10:40:26 +01:00
Alejandro Serrano
6d0b6ea18a Enhancements to hover (#317)
* 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
2020-01-21 09:15:19 +01: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
789f4031e6 Code action to insert new definitions (#309)
* code action to insert new definitions
2020-01-13 09:08:54 +01:00
Moritz Kiefer
4f61cb66c9
Fix source spans for multi-clause definitions (#318)
* 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.
2020-01-10 15:37:09 +01:00
Alejandro Serrano
c122ebdc4f Trigger completion after dot (#313)
* Trigger completion after dot

* Fix stupid mistake in test
2020-01-10 10:05:44 +01:00
Alejandro Serrano
a0aa013e33 Better docs for completions (#288)
* 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
2020-01-09 09:44:32 +01:00
Jacek Generowicz
5f4384e8ef Tests for issue 310 (misleading hover on inner signature) (#311)
* 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
2020-01-08 14:27:31 +01:00
Pepe Iborra
b7208a333f Smarter logic to remove redundant import bindings (#308)
* 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>
2020-01-08 12:01:59 +01:00
Pepe Iborra
fd163cd8e9 Insert imports code action (#295)
*  #46 Code action to add suggested imports

* code action to fix constructor imports

* #46 Add test for (broken) constructor import
2020-01-06 09:37:53 +01:00
Pepe Iborra
f8e6ab171f Fix #247 (#292) 2020-01-06 09:17:22 +01:00
Alejandro Serrano
821c7f6ffa Remove JSON instances for unused completion code (#305)
* Remove JSON instances for completions, since we are not implementing "resolve"

* Remove completion resolve data from tests
2020-01-06 09:16:00 +01:00
Jinwoo Lee
8f50699d24 Collect CPP error logs into diagnostics. (#296)
* Collect CPP error logs into diagnostics.

Fixes https://github.com/digital-asset/ghcide/issues/87
2020-01-06 09:14:55 +01:00
Moritz Kiefer
64693eddd8
Fix check for empty file path (#304)
I accidentally broke this on Windows in #303 by letting the two
conversirons get out of sync.
2020-01-04 01:25:31 +01:00
Pepe Iborra
6bb1e4e05a jjk (#300) 2020-01-02 17:31:51 +01:00
Pepe Iborra
5ca06a1d24 Document symbols provider (#293)
* 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>
2019-12-31 10:31:55 +01:00
Pepe Iborra
0bcdc6a226 Fix for #45 - remove redundant symbols from imports (#290)
* 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>
2019-12-30 10:40:13 +01:00
Alejandro Serrano
b52ee607f9 [WIP] Completion support (#227)
* 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
2019-12-19 15:00:39 +01:00
Neil Mitchell
70cb92cc01 #279, support preprocessors (#282)
* Support preprocessors

* Add a preprocessor for testing

* Add a preprocessor test
2019-12-19 12:06:03 +01:00