Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Add code actions for missing type signatures #81

Merged
merged 2 commits into from
Sep 19, 2019

Conversation

jacg
Copy link
Contributor

@jacg jacg commented Sep 17, 2019

Will need more thorough testing, and maybe more discussion of the different approaches considered in #77.

@jacg
Copy link
Contributor Author

jacg commented Sep 17, 2019

One problem that I am observing locally, is that if I apply one of these actions in Emacs in the context of a larger file, then the signatures are sometimes garbled. As I seem to have lost the ability to apply code actions in VSCode, I can't tell whether this is an Emacs problem, or a problem with the implementation.

@jacg jacg force-pushed the missing-signatures-action branch from 6ba07d8 to 1d37341 Compare September 17, 2019 18:00
@jacg
Copy link
Contributor Author

jacg commented Sep 17, 2019

the signatures ar sometimes garbled

For example, adding the line foo = True just after the imports in ghcide/src/Development/IDE/LSP/CodeAction.hs and running the suggested action, results in

foo :: Bool
foo = True

If the same line is placed at the end of the same file, then the code action results in

fooo::oBool
foo = True

Similar story with abcdefgh a b c = True which gives abcdefgh :: p1 -> p2 -> p3 -> Bool or abcdefgh ::ap1b->cp2d-> p3 -> Bool.

@jacg
Copy link
Contributor Author

jacg commented Sep 17, 2019

The LSP log for the last one shows

  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 238,
          "character": 0
        },
        "end": {
          "line": 238,
          "character": 8
        }
      },
      "rangeLength": 8,
      "text": "abcdefgh ::bp1c->dp2e-> p3 -> Bool\nabcdefgh"
    }
  ]

Which suggests that it's the server which is sending this nonsense?

@jacg
Copy link
Contributor Author

jacg commented Sep 17, 2019

Managed to get code actions working in VS Code once more: it all looks good over there, so this seems to be a problem with Emacs rather than this implementation.

@jacg jacg force-pushed the missing-signatures-action branch from 1d37341 to 1b5533a Compare September 17, 2019 22:35
Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@jacg
Copy link
Contributor Author

jacg commented Sep 18, 2019

The big question that remains is what to do about enabling -Wmissing-signatures, without which none of this works.

The tests force the issue with {-# OPTIONS_GHC -Wmissing-signatures #-}.

Over in #77, @ndmitchell suggested

Maybe ghcide should always turn on this warning, always suggest it as a code action, but then if the user didn't turn on this warning, suppress the resulting warning notification.

Should I try doing it this way, or are there alternative proposals?

@jacg
Copy link
Contributor Author

jacg commented Sep 18, 2019

... or should we just merge it as is, and think deal with enabling the warnings in a separate PR?

@ndmitchell
Copy link
Collaborator

I think this is a great first step for people who enable this warning.

My ideal end state for everyone who doesn't enable the warning would be to have these quick fixes available, but not see even an info level diagnostic for missing signatures. I'm not sure if you can attach a quick fix without a diagnostic. The other option would be that top-level signatures that are omitted show up as code lenses, so you see:

foo :: Int -> Int
foo 1 =1

But the foo :: Int -> Int line is a hyperlink that's useful documentation, but if you click it, inserts the file for real. I could definitely see myself using that.

@jacg jacg marked this pull request as ready for review September 18, 2019 14:56
@jacg
Copy link
Contributor Author

jacg commented Sep 18, 2019

I think this is a great first step for people who enable this warning.

In which case I propose that we merge this as is, and leave further considerations for another PR.

@jacg
Copy link
Contributor Author

jacg commented Sep 18, 2019

But as it stands, it doesn't fully address #77, so I've removed the automatic closing.

@ndmitchell
Copy link
Collaborator

See #88 for how we should be doing inferred signatures if the warning is off, using the proper things in VS Code.

@maralorn
Copy link
Contributor

Fwiw, I think. I would appreciate merging this and caring about the case without the warning enabled later.
That fits together with neils suggestion.

@cocreature cocreature merged commit bf9ee2a into haskell:master Sep 19, 2019
Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Thank you for the PR and sorry for the delay!

@jacg jacg deleted the missing-signatures-action branch September 19, 2019 17:47
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Add code actions for missing top-level type signatures

* Turn signature tester into operator
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Add code actions for missing top-level type signatures

* Turn signature tester into operator
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Add code actions for missing top-level type signatures

* Turn signature tester into operator
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants