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

Keep type lenses stable #3558

Merged
merged 15 commits into from
May 5, 2023
Merged

Keep type lenses stable #3558

merged 15 commits into from
May 5, 2023

Conversation

July541
Copy link
Collaborator

@July541 July541 commented Apr 7, 2023

I got the same effect without using PositionMapping compared to instance lenses, but don't know why.

Can anyone explain this?

@michaelpj
Copy link
Collaborator

I think you should still need the position mapping otherwise the edit might go in the wrong place? It doesn't look like there's a usesWithStale that just gives you one PositionMapping for the lot, which feels like an oversight (probably what you want if you're getting multiple stale pieces of info). I guess otherwise you could try to use the PositionMapping for the bit you get positions from?

@July541
Copy link
Collaborator Author

July541 commented Apr 15, 2023

Introducing useWithStale need some refactoring. Taking this opportunity, I'm wondering if it is worth extracting type lens code to a new plugin?

cc @michaelpj @pepeiborra

@michaelpj
Copy link
Collaborator

No particular opinion from me, I can't remember if we have any clear policy about where we're going with the ghcide plugins.

@July541 July541 marked this pull request as ready for review April 17, 2023 14:30
@July541 July541 requested a review from pepeiborra as a code owner April 17, 2023 14:30
@July541
Copy link
Collaborator Author

July541 commented Apr 17, 2023

Replace use with useWithStale without more design.

I'll open a new pr to refactor these messed code.

@July541
Copy link
Collaborator Author

July541 commented Apr 19, 2023

@michaelpj Would you mind doing a review, I don't want mix bug fixing and refactoring

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.

A few nits but generally looks fine.

I generally feel like we should have a usesWithStale that returns a single position mapping for all the values, so you can request many things and get a single coherent stale mapping. The current setup probably works but feels risky to me.

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

July541 commented Apr 22, 2023

Stale lens for diagnostics doesn't make sense, because we always have fresh diagnostics even if current module parsed failed( the diagnostic is parse failed).

So there is nothing to do if we generate lenses from diagnostics.

@michaelpj
Copy link
Collaborator

Stale lens for diagnostics doesn't make sense, because we always have fresh diagnostics even if current module parsed failed

But don't we mix together things we got from the diagnostics with things we got from the bindings? So the locations could be all messed up there? I haven't quite understood what's going on there.

@July541
Copy link
Collaborator Author

July541 commented Apr 22, 2023

But don't we mix together things we got from the diagnostics with things we got from the bindings? So the locations could be all messed up there? I haven't quite understood what's going on there.

We don't. The secret is getDiagnostics will never fail, which means the lenses from diagnostic will flicker but others from parsed module won't.

We have 3 modes for type lenses, only lenses from generateLensForGlobal should keep stable, suggestLocalSignature relies on diagnostics. Different modes need different methods to generate lenses, so they won't be mixed.

case mode of
Always ->
pure (catMaybes $ generateLensForGlobal <$> gblSigs')
<> generateLensFromDiags (suggestLocalSignature False env tmr bindings) -- we still need diagnostics for local bindings
Exported -> pure $ catMaybes $ generateLensForGlobal <$> filter gbExported gblSigs'
Diagnostics -> generateLensFromDiags $ suggestSignature False env gblSigs tmr bindings

@michaelpj michaelpj added the merge me Label to trigger pull request merge label Apr 23, 2023
, Just range <- toCurrentRange mp beforeLine
-- If `mmp` is `Nothing`, return the original range, it used by lenses from diagnostic,
-- otherwise we apply `toCurrentRange`, and the guard should fail if `toCurrentRange` failed.
, Just range <- maybe (Just beforeLine) (flip toCurrentRange beforeLine) mmp
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mixed the scene if mmp is Nothing, thanks ci halt this 😅

@mergify mergify bot merged commit 41cd52e into haskell:master May 5, 2023
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.

2 participants