Skip to content

Commit a73a305

Browse files
committed
Stick judgment and context into the RTR
1 parent d8b3753 commit a73a305

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ tacticCmd tac state (TacticParams uri range var_name)
182182
Left err ->
183183
Left $ mkErr InvalidRequest $ T.pack $ show err
184184
Right rtr ->
185-
mkWorkspaceEdits rtr jdg span ctx dflags clientCapabilities uri pm
185+
mkWorkspaceEdits rtr span dflags clientCapabilities uri pm
186186
pure $ joinNote (mkErr InvalidRequest "timed out") x
187187

188188
case res of
@@ -206,8 +206,8 @@ joinNote _ (Just a) = a
206206
------------------------------------------------------------------------------
207207
-- | Turn a 'RunTacticResults' into concrete edits to make in the source
208208
-- document.
209-
mkWorkspaceEdits rtr jdg span ctx dflags clientCapabilities uri pm = do
210-
let g = graftHole jdg (RealSrcSpan span) ctx rtr
209+
mkWorkspaceEdits rtr span dflags clientCapabilities uri pm = do
210+
let g = graftHole (RealSrcSpan span) rtr
211211
response = transform dflags clientCapabilities uri g pm
212212
in case response of
213213
Right res -> Right $ Just res
@@ -219,25 +219,22 @@ mkWorkspaceEdits rtr jdg span ctx dflags clientCapabilities uri pm = do
219219
-- deals with top-level holes, in which we might need to fiddle with the
220220
-- 'Match's that bind variables.
221221
graftHole
222-
:: Judgement' a2
223-
-> SrcSpan
224-
-> Context
225-
-> RunTacticResults
226-
-> Graft (Either String) ParsedSource
227-
graftHole jdg span ctx rtr
228-
| _jIsTopHole jdg
222+
:: SrcSpan
223+
-> RunTacticResults
224+
-> Graft (Either String) ParsedSource
225+
graftHole span rtr
226+
| _jIsTopHole (rtr_jdg rtr)
229227
= graftSmallestDeclsWithM span
230-
$ graftDecl span
231-
$ \pats ->
232-
splitToDecl (fst $ last $ ctxDefiningFuncs ctx)
228+
$ graftDecl span $ \pats ->
229+
splitToDecl (fst $ last $ ctxDefiningFuncs $ rtr_ctx rtr)
233230
$ iterateSplit
234231
$ mkFirstAgda (fmap unXPat pats)
235232
$ unLoc
236233
$ rtr_extract rtr
237-
graftHole jdg span _ rtr
234+
graftHole span rtr
238235
= graftWithoutParentheses span
239236
-- Parenthesize the extract iff we're not in a top level hole
240-
$ bool maybeParensAST id (_jIsTopHole jdg)
237+
$ bool maybeParensAST id (_jIsTopHole $ rtr_jdg rtr)
241238
$ rtr_extract rtr
242239

243240

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Machinery.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ runTactic ctx jdg t =
9797
Down $ scoreSolution ext jdg holes
9898
case sorted of
9999
(((tr, ext), _) : _) ->
100-
Right
101-
. RunTacticResults tr (simplify ext)
102-
. reverse
103-
. fmap fst
104-
$ take 5 sorted
100+
Right $
101+
RunTacticResults
102+
{ rtr_trace = tr
103+
, rtr_extract = simplify ext
104+
, rtr_other_solns = reverse . fmap fst $ take 5 sorted
105+
, rtr_jdg = jdg
106+
, rtr_ctx = ctx
107+
}
105108
-- guaranteed to not be empty
106109
_ -> Left []
107110

plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Types.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ data Context = Context
337337
, ctxModuleFuncs :: [(OccName, CType)]
338338
-- ^ Everything defined in the current module
339339
}
340-
deriving stock (Eq, Ord)
340+
deriving stock (Eq, Ord, Show)
341341

342342

343343
------------------------------------------------------------------------------
@@ -374,6 +374,8 @@ data RunTacticResults = RunTacticResults
374374
{ rtr_trace :: Trace
375375
, rtr_extract :: LHsExpr GhcPs
376376
, rtr_other_solns :: [(Trace, LHsExpr GhcPs)]
377+
, rtr_jdg :: Judgement
378+
, rtr_ctx :: Context
377379
} deriving Show
378380

379381

0 commit comments

Comments
 (0)