Skip to content

Commit 17cd0af

Browse files
Fix bug in Retrive "fold/unfold in local file" commands (#1202)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 63a69f6 commit 17cd0af

File tree

1 file changed

+9
-21
lines changed
  • plugins/hls-retrie-plugin/src/Ide/Plugin

1 file changed

+9
-21
lines changed

plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs

+9-21
Original file line numberDiff line numberDiff line change
@@ -106,29 +106,19 @@ retrieCommand =
106106
data RunRetrieParams = RunRetrieParams
107107
{ description :: T.Text,
108108
rewrites :: [RewriteSpec],
109-
originatingFile :: NormalizedUriJSON,
109+
originatingFile :: Uri,
110110
restrictToOriginatingFile :: Bool
111111
}
112112
deriving (Eq, Show, Generic, FromJSON, ToJSON)
113-
114-
newtype NormalizedUriJSON = NormalizedUriJSON NormalizedUri
115-
deriving (Eq, Show)
116-
117-
instance FromJSON NormalizedUriJSON where
118-
parseJSON = fmap NormalizedUriJSON . genericParseJSON Aeson.defaultOptions
119-
120-
instance ToJSON NormalizedUriJSON where
121-
toJSON (NormalizedUriJSON x) = Aeson.genericToJSON Aeson.defaultOptions x
122-
123113
runRetrieCmd ::
124114
LspFuncs a ->
125115
IdeState ->
126116
RunRetrieParams ->
127117
IO (Either ResponseError Value, Maybe (ServerMethod, ApplyWorkspaceEditParams))
128-
runRetrieCmd lsp state RunRetrieParams{originatingFile = NormalizedUriJSON nuri, ..} =
118+
runRetrieCmd lsp state RunRetrieParams{originatingFile = uri, ..} =
129119
withIndefiniteProgress lsp description Cancellable $ do
130120
res <- runMaybeT $ do
131-
nfp <- MaybeT $ return $ uriToNormalizedFilePath nuri
121+
nfp <- MaybeT $ return $ uriToNormalizedFilePath $ toNormalizedUri uri
132122
(session, _) <- MaybeT $
133123
runAction "Retrie.GhcSessionDeps" state $
134124
useWithStale GhcSessionDeps $
@@ -181,20 +171,19 @@ provider :: CodeActionProvider IdeState
181171
provider _a state plId (TextDocumentIdentifier uri) range ca = response $ do
182172
let (J.CodeActionContext _diags _monly) = ca
183173
nuri = toNormalizedUri uri
184-
nuriJson = NormalizedUriJSON nuri
185174
nfp <- handleMaybe "uri" $ uriToNormalizedFilePath nuri
186175

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

190179
pos <- handleMaybe "pos" $ _start <$> fromCurrentRange posMapping range
191180
let rewrites =
192-
concatMap (suggestBindRewrites nuriJson pos ms_mod) topLevelBinds
193-
++ concatMap (suggestRuleRewrites nuriJson pos ms_mod) hs_ruleds
181+
concatMap (suggestBindRewrites uri pos ms_mod) topLevelBinds
182+
++ concatMap (suggestRuleRewrites uri pos ms_mod) hs_ruleds
194183
++ [ r
195184
| TyClGroup {group_tyclds} <- hs_tyclds,
196185
L l g <- group_tyclds,
197-
r <- suggestTypeRewrites nuriJson ms_mod g,
186+
r <- suggestTypeRewrites uri ms_mod g,
198187
pos `isInsideSrcSpan` l
199188

200189
]
@@ -233,7 +222,7 @@ getBinds nfp = runMaybeT $ do
233222
return (tmrModSummary tm, topLevelBinds, posMapping, hs_ruleds, hs_tyclds)
234223

235224
suggestBindRewrites ::
236-
NormalizedUriJSON ->
225+
Uri ->
237226
Position ->
238227
GHC.Module ->
239228
HsBindLR GhcRn GhcRn ->
@@ -260,7 +249,7 @@ describeRestriction restrictToOriginatingFile =
260249

261250
suggestTypeRewrites ::
262251
(Outputable (IdP pass)) =>
263-
NormalizedUriJSON ->
252+
Uri ->
264253
GHC.Module ->
265254
TyClDecl pass ->
266255
[(T.Text, CodeActionKind, RunRetrieParams)]
@@ -279,7 +268,7 @@ suggestTypeRewrites originatingFile ms_mod (SynDecl {tcdLName = L _ rdrName}) =
279268
suggestTypeRewrites _ _ _ = []
280269

281270
suggestRuleRewrites ::
282-
NormalizedUriJSON ->
271+
Uri ->
283272
Position ->
284273
GHC.Module ->
285274
LRuleDecls pass ->
@@ -351,7 +340,6 @@ callRetrie ::
351340
IO ([CallRetrieError], WorkspaceEdit)
352341
callRetrie state session rewrites origin restrictToOriginatingFile = do
353342
knownFiles <- toKnownFiles . unhashed <$> readVar (knownTargetsVar $ shakeExtras state)
354-
print knownFiles
355343
let reuseParsedModule f = do
356344
pm <-
357345
useOrFail "GetParsedModule" NoParse GetParsedModule f

0 commit comments

Comments
 (0)