Simon Jakobi pushed to branch wip/sjakobi/multi-caret at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Driver/Errors.hs
    ... ... @@ -47,7 +47,7 @@ printMessages logger msg_opts opts = mapM_ (printMessage logger msg_opts opts) .
    47 47
     printMessage :: forall a. (Diagnostic a) => Logger -> DiagnosticOpts a -> DiagOpts -> MsgEnvelope a -> IO ()
    
    48 48
     printMessage logger msg_opts opts message
    
    49 49
       | log_diags_as_json = do
    
    50
    -      decorated <- decorateDiagnostic logflags messageClass location relatedSpans doc
    
    50
    +      decorated <- decorateDiagnostic logflags messageClass location doc
    
    51 51
           let
    
    52 52
             rendered :: String
    
    53 53
             rendered = renderWithContext (log_default_user_context logflags) decorated
    

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -424,8 +424,8 @@ defaultLogActionWithHandles out err logflags msg_class srcSpan msg
    424 424
           MCInfo                       -> printErrs msg
    
    425 425
           MCFatal                      -> printErrs msg
    
    426 426
           MCDiagnostic SevIgnore _ _ _ -> pure () -- suppress the message
    
    427
    -      MCDiagnostic _sev _rea _code relatedSpans ->
    
    428
    -        decorateDiagnostic logflags msg_class srcSpan relatedSpans msg >>= printErrs
    
    427
    +      MCDiagnostic{} ->
    
    428
    +        decorateDiagnostic logflags msg_class srcSpan msg >>= printErrs
    
    429 429
         where
    
    430 430
           printOut   = defaultLogActionHPrintDoc  logflags False out
    
    431 431
           printErrs  = defaultLogActionHPrintDoc  logflags False err
    
    ... ... @@ -465,13 +465,19 @@ defaultLogActionWithHandles out err logflags msg_class srcSpan msg
    465 465
     --     `defaultLogActionWithHandles`)
    
    466 466
     --
    
    467 467
     -- This story is tracked by #24113.
    
    468
    -decorateDiagnostic :: LogFlags -> MessageClass -> SrcSpan -> [SrcSpan] -> SDoc -> IO SDoc
    
    469
    -decorateDiagnostic logflags msg_class srcSpan relatedSpans msg = addCaret
    
    468
    +decorateDiagnostic :: LogFlags -> MessageClass -> SrcSpan -> SDoc -> IO SDoc
    
    469
    +decorateDiagnostic logflags msg_class srcSpan msg = addCaret
    
    470 470
         where
    
    471 471
           -- Pretty print the warning flag, if any (#10752)
    
    472 472
           message :: SDoc
    
    473 473
           message = mkLocMessageWarningGroups (log_show_warn_groups logflags) msg_class srcSpan msg
    
    474 474
     
    
    475
    +      -- The related locations are carried by the 'MCDiagnostic' message class.
    
    476
    +      relatedSpans :: [SrcSpan]
    
    477
    +      relatedSpans = case msg_class of
    
    478
    +        MCDiagnostic _ _ _ spans -> spans
    
    479
    +        _                        -> []
    
    480
    +
    
    475 481
           -- The primary span is always caret'd, with the related spans drawn as
    
    476 482
           -- additional carets.  Dedup so the primary isn't drawn twice when it
    
    477 483
           -- also appears among the related spans.