-
-
Notifications
You must be signed in to change notification settings - Fork 391
Keep instance lenses stable even if parsed results are unavailable #3545
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
Changes from all commits
49aae6d
1f154a5
6f4c1e4
bbc365e
b496ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,10 @@ toMethodName n | |
| otherwise | ||
= n | ||
|
||
-- | Here we use `useWithStale` to compute, Using stale results means that we can almost always return a value. | ||
-- In practice this means the lenses don't 'flicker'. | ||
-- This function is also used in code actions, but it doesn't matter because our actions only work | ||
-- if the module parsed success. | ||
insertPragmaIfNotPresent :: (MonadIO m) | ||
=> IdeState | ||
-> NormalizedFilePath | ||
|
@@ -59,10 +63,10 @@ insertPragmaIfNotPresent state nfp pragma = do | |
(_, fileContents) <- liftIO | ||
$ runAction "classplugin.insertPragmaIfNotPresent.GetFileContents" state | ||
$ getFileContents nfp | ||
pm <- handleMaybeM "Unable to GetParsedModuleWithComments" | ||
(pm, _) <- handleMaybeM "Unable to GetParsedModuleWithComments" | ||
$ liftIO | ||
$ runAction "classplugin.insertPragmaIfNotPresent.GetParsedModuleWithComments" state | ||
$ use GetParsedModuleWithComments nfp | ||
$ useWithStale GetParsedModuleWithComments nfp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly, this seems like somewhere we shouldn't do it. We really want the up-to-date module to compute an edit! But because we return the edit as part of the code lens, we have to. So the thing to do in the long run would be to implment Also relevant for #3536 |
||
let exts = getExtensions pm | ||
info = getNextPragmaInfo sessionDynFlags fileContents | ||
pure [insertNewPragma info pragma | pragma `notElem` exts] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Stale where | ||
|
||
data A a | ||
instance Functor A where | ||
fmap = _ |
Uh oh!
There was an error while loading. Please reload this page.