Skip to content

Commit 90f5134

Browse files
committed
Add the correct file offset to metaprogram parse errors
1 parent 6c93d03 commit 90f5134

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

plugins/hls-tactics-plugin/src/Wingman/LanguageServer/Metaprogram.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Development.IDE.Core.RuleTypes
2222
import Development.IDE.Core.Shake (IdeState (..))
2323
import Development.IDE.Core.UseStale
2424
import Development.IDE.GHC.Compat
25-
import GhcPlugins (containsSpan, realSrcLocSpan)
25+
import GhcPlugins (containsSpan, realSrcLocSpan, realSrcSpanStart)
2626
import Ide.Types
2727
import Language.LSP.Types
2828
import Prelude hiding (span)
@@ -50,8 +50,9 @@ hoverProvider state plId (HoverParams (TextDocumentIdentifier uri) (unsafeMkCurr
5050
case (find (flip containsSpan (unTrack loc) . unTrack . fst) holes) of
5151
Just (trss, program) -> do
5252
let tr_range = fmap realSrcSpanToRange trss
53+
rsl = realSrcSpanStart $ unTrack trss
5354
HoleJudgment{hj_jdg=jdg, hj_ctx=ctx} <- judgementForHole state nfp tr_range cfg
54-
z <- liftIO $ attempt_it ctx jdg $ T.unpack program
55+
z <- liftIO $ attempt_it rsl ctx jdg $ T.unpack program
5556
pure $ Hover
5657
{ _contents = HoverContents
5758
$ MarkupContent MkMarkdown

plugins/hls-tactics-plugin/src/Wingman/Metaprogramming/Parser.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import Wingman.Metaprogramming.Parser.Documentation
2020
import Wingman.Metaprogramming.ProofState (proofState, layout)
2121
import Wingman.Tactics
2222
import Wingman.Types
23+
import Development.IDE.GHC.Compat (RealSrcLoc, srcLocLine, srcLocCol, srcLocFile)
24+
import FastString (unpackFS)
2325

2426

2527
nullary :: T.Text -> TacticsM () -> Parser (TacticsM ())
@@ -420,17 +422,30 @@ wrapError :: String -> String
420422
wrapError err = "```\n" <> err <> "\n```\n"
421423

422424

425+
fixErrorOffset :: RealSrcLoc -> P.ParseErrorBundle a b -> P.ParseErrorBundle a b
426+
fixErrorOffset rsl (P.ParseErrorBundle ne (P.PosState a n (P.SourcePos _ line col) pos s))
427+
= P.ParseErrorBundle ne
428+
$ P.PosState a n
429+
(P.SourcePos
430+
(unpackFS $ srcLocFile rsl)
431+
((<>) line $ P.mkPos $ srcLocLine rsl - 1)
432+
((<>) col $ P.mkPos $ srcLocCol rsl - 1 + length @[] "[wingman|")
433+
)
434+
pos
435+
s
436+
423437
------------------------------------------------------------------------------
424438
-- | Attempt to run a metaprogram tactic, returning the proof state, or the
425439
-- errors.
426440
attempt_it
427-
:: Context
441+
:: RealSrcLoc
442+
-> Context
428443
-> Judgement
429444
-> String
430445
-> IO (Either String String)
431-
attempt_it ctx jdg program =
446+
attempt_it rsl ctx jdg program =
432447
case P.runParser tacticProgram "<splice>" (T.pack program) of
433-
Left peb -> pure $ Left $ wrapError $ P.errorBundlePretty peb
448+
Left peb -> pure $ Left $ wrapError $ P.errorBundlePretty $ fixErrorOffset rsl peb
434449
Right tt -> do
435450
res <- runTactic
436451
ctx

0 commit comments

Comments
 (0)