Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Type Signature Plugin #2660

Merged
merged 32 commits into from
Mar 3, 2022
Merged

Conversation

drsooch
Copy link
Collaborator

@drsooch drsooch commented Jan 31, 2022

This plugin is designed to take care of #2436 . This a very rough first draft, with a basic outline targeting one specific GHC Type Error message (see error.txt for an example). There are certain instances of this error message that WILL NOT work in the current implementation. I just wanted to get a first look and any potential help for further expansion.

It should be noted that this currently sits in ghcide as when I started out I assumed there would be some code reuse between some similar ghcide internal plugins. Turns out that's not the case so far.

This implementation only matches a single GHC Error message:

```
    • Couldn't match type ‘Int’
                     with ‘Data.HashSet.Internal.HashSet Int’
      Expected type: Int -> Int
        Actual type: Data.HashSet.Internal.HashSet Int -> Int
    • In the expression: head . toList
      In an equation for ‘test’: test = head . toList
```

Specifically on `Expected type: ...`, `Actual type:...` and `In an equation ...`.

There are plenty of error messages that match this format but aren't actually valid.
@drsooch
Copy link
Collaborator Author

drsooch commented Feb 3, 2022

Does anyone have a preference as to where this plugin should go (if the functionality expands out a bit more?) Separate module? Leave it in ghcide?

@pepeiborra
Copy link
Collaborator

Does anyone have a preference as to where this plugin should go (if the functionality expands out a bit more?) Separate module? Leave it in ghcide?

Move it outside please - standalone plugins have better isolation, error handling, run in parallel, and are much easier to upgrade gradually when there is a new GHC version

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me

ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good!

Since Pepe mentioned the structured errors infrastructure, I wonder whether this is actually a good opportunity to make a feature request upstream! I know Richard has been looking for feedback from us about what would actually be useful in structured errors. Maybe we could open a GHC issue explaining what we're trying to do and asking if there would be a good way to include extra information in structured type-mismatch errors so we could always work out the "actual" type of the enclosing binding or something.

ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
ghcide/src/Development/IDE/Plugin/ChangeTypeAction.hs Outdated Show resolved Hide resolved
@drsooch
Copy link
Collaborator Author

drsooch commented Feb 9, 2022

https://gitlab.haskell.org/ghc/ghc/-/issues/21063 -- Linking this here

- Add new regex for matching extra errors message types

- Revamp original regex to match more.

- Add basic test suite.

- Begin adding `tidyActualType` semantics to provide slightly prettier
TyVars
- Add Pretty Printing for Types
- Added a few test scenarios
@drsooch drsooch marked this pull request as ready for review February 18, 2022 03:57
@drsooch
Copy link
Collaborator Author

drsooch commented Feb 18, 2022

Going to mark this as ready for review, there are a few things I'd like to clean up and I've left relevant comments.

- Be able to tidy signatures with operators in it
- Use T.words instead of regex matching to split tyVars
Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On tiny doc nit otherwise LGTM!

drsooch and others added 5 commits February 23, 2022 08:21
* convert to contravariant logging style part 1, uses additional hardcoded log file to see it side by side with original logging

* convert Session to contravariant logging style

* convert Plugin/HLS and FireStore to contravariant logging style

* convert Rules (and most of the universe) to contravariant logging style

* fix tests, allow old style logging and contravariant logging to write to same log file

* fix import inside wrong CPP

* add CPP for LogTactic constructor

* remove redundant import

* fix ghcide tests

* remove unused import

* fix plugin tests

* LSP_TEST_STDERR should apply to contra logger as well

* fix tactic plugin test

* use CPP for Log datatype plugin constructors, remove unused imports

* add a few Pretty instances, add prettyprinter to haskell-language-sever and hls-plugin-api dependencies

* add Pretty Log instances for Session, FileStore, Notifications

* add remaining Pretty Log instances

* add logToPriorities

* fix slight interleaving issue with hslogger and logger both logging, have default logger be mutex stderr or file handle, use stderr if failing to open log file

* forgot to add .cabal files with hslogger dep

* dont use UnliftIO file IO helpers because they are too new

* remove log helper comments, use Doc instead of Text as final console/file logger input, renaming, export Log constructors

* remove accidentally added useless file, removed prettyprinter dep from hls-plugin-api because stack ghc8.6.5 doesnt have it?

* use deprecated prettyprint modules import for the sake of circleci ghc-8.6.5

* use dummy stderr logger for plugin cli commands, use priorityToHsLoggerPriority function instead of manual mapping

* remove old plugin detritus that somehow got committed

* fix prettyprinter imports for 8.6.5

* try enforcing prettyprinter bounds?

* enforcing bound makes no sense

* maybe changing stack yamls does trick

* filter out warnings when their diags are empty to more closely match original

* add ability to select wanted logging columns, match prev ghcide exe logging behaviour

* dont log anything when diags are empty in some defineEarlyCutoff versions

* use non-deprecated prettyprinter imports

* fix ghcide test module

* change logWith to accept priority at call site, remove all logToPriority functions, add cmapWithPrio that contramaps through WithPriority

* remove useless hiding import list, add comments to default recorder makers

* make cradleToOptsAndLibDir take concrete cradle to remove existential type var in Log constructor

* Types.Logger now re-exports prettyprinter, remove unused dependencies on prettyprinter and hslogger

* existential type var to remove boilerplate in Plugins.hs, remove a few Show instances

* add SourceLoc logging column, inline logToDoc functions, add comment explaining hslogger setup existence

* qualify a name to match original source

* fix -WError
It's a bit non-standard, and moreover it's entirely dead.
@drsooch
Copy link
Collaborator Author

drsooch commented Feb 23, 2022

Sorry for this marathon PR. I pushed a change to handling local signatures for better support. New tests aren't passing locally, just going to see if it'll work in CI. I'll revisit this tonight.

@michaelpj
Copy link
Collaborator

This looks green but I wasn't sure if you still have work you want to do or not!

@drsooch
Copy link
Collaborator Author

drsooch commented Feb 27, 2022

Yes this is all set!

@pepeiborra pepeiborra added the merge me Label to trigger pull request merge label Mar 3, 2022
@mergify mergify bot merged commit 911fe59 into haskell:master Mar 3, 2022
@pepeiborra
Copy link
Collaborator

pepeiborra commented Mar 5, 2022

@drsooch drsooch deleted the change-type-signature branch August 20, 2022 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants