Skip to content

Record quick fixes based on fields should be deduped #798

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

Closed
ndmitchell opened this issue Feb 23, 2020 · 12 comments · Fixed by #1334
Closed

Record quick fixes based on fields should be deduped #798

ndmitchell opened this issue Feb 23, 2020 · 12 comments · Fixed by #1334
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@ndmitchell
Copy link
Collaborator

image

Not sure what version of ghcide I'm on...

@jneira
Copy link
Member

jneira commented Sep 24, 2020

Reproduced with lastest hls and ghcide (although i got only 2 duplicates)
It suggests one for each record field (my record has only two), in the problems pane:

Illegal use of punning for field ‘a’
Use NamedFieldPuns to permit this

Illegal use of punning for field ‘b’
Use NamedFieldPuns to permit this

@jneira jneira changed the title Fixes should be deduped Record quick fixes based on fields should be deduped Sep 24, 2020
@gdevanla
Copy link
Contributor

I can take a look at this issue. Any good place to start?

@jneira
Copy link
Member

jneira commented Nov 24, 2020

@gdevanla I think the code that trigger extension completion will be:

https://github.com/haskell/ghcide/blob/863392b9b94777a069a2a31e9b909d1ce45e93d4/src/Development/IDE/Plugin/CodeAction.hs#L526

Not known much about it though, it comes from the time where this was part of daml, according to blame.

@pepeiborra pepeiborra transferred this issue from haskell/ghcide Jan 1, 2021
@jneira jneira added component: ghcide good first issue type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Jan 11, 2021
@ishmum123
Copy link
Contributor

@jneira this might be a noob question. What's the consequence of changing the line to this
= [("Add " <> x <> " extension", [TextEdit (Range (Position 0 0) (Position 0 0)) $ "{-# LANGUAGE " <> x <> " #-}\n"]) | x <- (Set.toList $ Set.fromList exts) ]
?

@jneira
Copy link
Member

jneira commented Jan 31, 2021

it could work, a test case would be the definitive evidence 🙂

@ishmum123
Copy link
Contributor

@jneira can you help me a bit? I am a bit lost on where to provide the pull request for ghcide

@jneira
Copy link
Member

jneira commented Feb 7, 2021

@ishmum123 sorry for the delay, the pull request should be done in this repo, now that ghcide lives here.

But the code responsive of suggest language extensions has been removed from ghcide, cause hls had already a plugin to do the same.
However it suffer the same bug, i think the relevant code could be:

pragmas = concatMap (\d -> genPragma dflags (d ^. J.message)) diags

@Ailrun
Copy link
Member

Ailrun commented Feb 8, 2021

I'm not super confident, but I think it wont't fix this issue as this issue is caused by multiple diagnostics, not by a single diagnostic.

@jneira
Copy link
Member

jneira commented Feb 8, 2021

Mmm, @Ailrun you are right and the fix becomes more complex, i am afraid. ghc is giving us a waning for each field so the alternatives i can think of is:

  • fix ghc to only emit one warning per record constructor (that would be the right one, but we would be blocked upstream)
  • filter diagnostics in hls (not sure if possible or feasible)
  • only emit one code action although we get several diagnostics. It would be feasible i we can access to the set of actual diagnostics (and i think there is a field stored somewhere) or code actions and only emit the new code action if it is not redundant

@berberman
Copy link
Collaborator

You can use getDiagnostics to get global diagnostics, like this:

diag <- fmap (\(_, _, d) -> d) . filter (\(p, _, _) -> mbFile == Just p) <$> getDiagnostics state

@ishmum123
Copy link
Contributor

@berberman you probably did a much better job than I did. I was working on it for a while, so thought I should push the fix if it's of any use.

@berberman
Copy link
Collaborator

@ishmum123 Oops, really sorry, I should ask first if someone has already started working on this :(

@mergify mergify bot closed this as completed in #1334 Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
6 participants