@@ -21,6 +21,8 @@ import Wingman.Metaprogramming.Parser.Documentation
2121import Wingman.Metaprogramming.ProofState (proofState , layout )
2222import Wingman.Tactics
2323import Wingman.Types
24+ import Development.IDE.GHC.Compat (RealSrcLoc , srcLocLine , srcLocCol , srcLocFile )
25+ import FastString (unpackFS )
2426
2527
2628nullary :: T. Text -> TacticsM () -> Parser (TacticsM () )
@@ -421,17 +423,30 @@ wrapError :: String -> String
421423wrapError err = " ```\n " <> err <> " \n ```\n "
422424
423425
426+ fixErrorOffset :: RealSrcLoc -> P. ParseErrorBundle a b -> P. ParseErrorBundle a b
427+ fixErrorOffset rsl (P. ParseErrorBundle ne (P. PosState a n (P. SourcePos _ line col) pos s))
428+ = P. ParseErrorBundle ne
429+ $ P. PosState a n
430+ (P. SourcePos
431+ (unpackFS $ srcLocFile rsl)
432+ ((<>) line $ P. mkPos $ srcLocLine rsl - 1 )
433+ ((<>) col $ P. mkPos $ srcLocCol rsl - 1 + length @ [] " [wingman|" )
434+ )
435+ pos
436+ s
437+
424438------------------------------------------------------------------------------
425439-- | Attempt to run a metaprogram tactic, returning the proof state, or the
426440-- errors.
427441attempt_it
428- :: Context
442+ :: RealSrcLoc
443+ -> Context
429444 -> Judgement
430445 -> String
431446 -> IO (Either String String )
432- attempt_it ctx jdg program =
447+ attempt_it rsl ctx jdg program =
433448 case P. runParser tacticProgram " <splice>" (T. pack program) of
434- Left peb -> pure $ Left $ wrapError $ P. errorBundlePretty peb
449+ Left peb -> pure $ Left $ wrapError $ P. errorBundlePretty $ fixErrorOffset rsl peb
435450 Right tt -> do
436451 res <- runTactic
437452 ctx
0 commit comments