Skip to content

Fix bug in Retrie "fold/unfold in local file" commands #1202

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

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,19 @@ retrieCommand =
data RunRetrieParams = RunRetrieParams
{ description :: T.Text,
rewrites :: [RewriteSpec],
originatingFile :: NormalizedUriJSON,
originatingFile :: Uri,
restrictToOriginatingFile :: Bool
}
deriving (Eq, Show, Generic, FromJSON, ToJSON)

newtype NormalizedUriJSON = NormalizedUriJSON NormalizedUri
deriving (Eq, Show)

instance FromJSON NormalizedUriJSON where
parseJSON = fmap NormalizedUriJSON . genericParseJSON Aeson.defaultOptions

instance ToJSON NormalizedUriJSON where
toJSON (NormalizedUriJSON x) = Aeson.genericToJSON Aeson.defaultOptions x

runRetrieCmd ::
LspFuncs a ->
IdeState ->
RunRetrieParams ->
IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
runRetrieCmd lsp state RunRetrieParams{originatingFile = NormalizedUriJSON nuri, ..} =
runRetrieCmd lsp state RunRetrieParams{originatingFile = uri, ..} =
withIndefiniteProgress lsp description Cancellable $ do
res <- runMaybeT $ do
nfp <- MaybeT $ return $ uriToNormalizedFilePath nuri
nfp <- MaybeT $ return $ uriToNormalizedFilePath $ toNormalizedUri uri
(session, _) <- MaybeT $
runAction "Retrie.GhcSessionDeps" state $
useWithStale GhcSessionDeps $
Expand Down Expand Up @@ -181,20 +171,19 @@ provider :: CodeActionProvider IdeState
provider _a state plId (TextDocumentIdentifier uri) range ca = response $ do
let (J.CodeActionContext _diags _monly) = ca
nuri = toNormalizedUri uri
nuriJson = NormalizedUriJSON nuri
nfp <- handleMaybe "uri" $ uriToNormalizedFilePath nuri

(ModSummary{ms_mod}, topLevelBinds, posMapping, hs_ruleds, hs_tyclds)
<- handleMaybeM "typecheck" $ runAction "retrie" state $ getBinds nfp

pos <- handleMaybe "pos" $ _start <$> fromCurrentRange posMapping range
let rewrites =
concatMap (suggestBindRewrites nuriJson pos ms_mod) topLevelBinds
++ concatMap (suggestRuleRewrites nuriJson pos ms_mod) hs_ruleds
concatMap (suggestBindRewrites uri pos ms_mod) topLevelBinds
++ concatMap (suggestRuleRewrites uri pos ms_mod) hs_ruleds
++ [ r
| TyClGroup {group_tyclds} <- hs_tyclds,
L l g <- group_tyclds,
r <- suggestTypeRewrites nuriJson ms_mod g,
r <- suggestTypeRewrites uri ms_mod g,
pos `isInsideSrcSpan` l

]
Expand Down Expand Up @@ -233,7 +222,7 @@ getBinds nfp = runMaybeT $ do
return (tmrModSummary tm, topLevelBinds, posMapping, hs_ruleds, hs_tyclds)

suggestBindRewrites ::
NormalizedUriJSON ->
Uri ->
Position ->
GHC.Module ->
HsBindLR GhcRn GhcRn ->
Expand All @@ -260,7 +249,7 @@ describeRestriction restrictToOriginatingFile =

suggestTypeRewrites ::
(Outputable (IdP pass)) =>
NormalizedUriJSON ->
Uri ->
GHC.Module ->
TyClDecl pass ->
[(T.Text, CodeActionKind, RunRetrieParams)]
Expand All @@ -279,7 +268,7 @@ suggestTypeRewrites originatingFile ms_mod (SynDecl {tcdLName = L _ rdrName}) =
suggestTypeRewrites _ _ _ = []

suggestRuleRewrites ::
NormalizedUriJSON ->
Uri ->
Position ->
GHC.Module ->
LRuleDecls pass ->
Expand Down Expand Up @@ -351,7 +340,6 @@ callRetrie ::
IO ([CallRetrieError], WorkspaceEdit)
callRetrie state session rewrites origin restrictToOriginatingFile = do
knownFiles <- toKnownFiles . unhashed <$> readVar (knownTargetsVar $ shakeExtras state)
print knownFiles
let reuseParsedModule f = do
pm <-
useOrFail "GetParsedModule" NoParse GetParsedModule f
Expand Down