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

Commits:

4 changed files:

Changes:

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -3764,13 +3764,8 @@ instance Diagnostic TcRnMessage where
    3764 3764
         TcRnZonkerMessage{} -> []
    
    3765 3765
     
    
    3766 3766
     -- | The prior occurrences of a duplicated entity, for use as the related
    
    3767
    --- locations of a \"duplicate\" diagnostic. Given all occurrences in ascending
    
    3768
    --- source order with the primary span last, return the earlier ones, omitting
    
    3769
    --- repeated spans and spans that coincide with the primary. Several
    
    3770
    --- occurrences can share a single span -- e.g. duplicate declarations brought
    
    3771
    --- into being by one TH splice -- and repeating the primary span among the
    
    3772
    --- related locations would draw its caret twice and emit it again in the JSON
    
    3773
    --- relatedSpans field.
    
    3767
    +-- locations of a \"duplicate\" diagnostic.
    
    3768
    +--
    
    3774 3769
     -- See Note [Choosing the primary and related spans] in GHC.Types.Error.
    
    3775 3770
     priorOccurrences :: NE.NonEmpty SrcSpan -> [SrcSpan]
    
    3776 3771
     priorOccurrences locs =
    

  • compiler/GHC/Tc/Errors/Types.hs
    ... ... @@ -3981,13 +3981,7 @@ data TcRnMessage where
    3981 3981
       TcRnDuplicateDecls :: !OccName -- ^ The name of the declarations
    
    3982 3982
                          -> !(NE.NonEmpty Name)
    
    3983 3983
                             -- ^ The individual declarations, in ascending source
    
    3984
    -                        -- order. The last one is the primary span of the
    
    3985
    -                        -- message; 'diagnosticRelatedLocations' returns the
    
    3986
    -                        -- earlier ones, omitting any that coincide with the
    
    3987
    -                        -- primary span (all occurrences can share one span,
    
    3988
    -                        -- e.g. when spliced by a single TH splice). See
    
    3989
    -                        -- Note [Choosing the primary and related spans]
    
    3990
    -                        -- in GHC.Types.Error.
    
    3984
    +                        -- order.
    
    3991 3985
                          -> TcRnMessage
    
    3992 3986
     
    
    3993 3987
       {-| TcRnPackageImportsDisabled is an error indicating that an import uses
    

  • compiler/GHC/Types/Error.hs
    ... ... @@ -258,30 +258,14 @@ which GHC's diagnostics are forwarded by HLS: an LSP diagnostic carries a single
    258 258
     
    
    259 259
       https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic
    
    260 260
     
    
    261
    -How the locations are rendered:
    
    262
    -
    
    263
    -  * Related spans are additional to the primary span, not replacements for it.
    
    264
    -    The spans that receive a caret are @primary :| relatedLocations@ (see
    
    265
    -    'GHC.Driver.Errors.printMessage' and 'defaultLogActionWithHandles').
    
    266
    -
    
    267
    -  * Locations are shown — both as carets and in the @At:@ list below — in
    
    268
    -    exactly the order the message author gives them: the primary span first,
    
    269
    -    then 'diagnosticRelatedLocations' as listed. The rendering layer neither
    
    270
    -    reorders nor deduplicates.
    
    271
    -
    
    272
    -  * Not every location can be shown as a caret: carets are optional
    
    273
    -    (@-fno-diagnostics-show-caret@), and some spans have no source to display
    
    274
    -    anyway (e.g. GHCi input or TH-generated code). Locations that get no caret
    
    275
    -    are instead listed under an @At:@ heading ('pprAtLocations'; dropped when it
    
    276
    -    would name only the primary span, which the header already states).
    
    277
    -    Every location with a real source position thus appears either as a caret
    
    278
    -    or in the @At:@ list — only spans without one ('UnhelpfulSpan') are dropped
    
    279
    -    altogether — so messages need not spell the locations out in their prose.
    
    280
    -    Carets require 'IO' to read the source, so renderers other than
    
    281
    -    'GHC.Utils.Logger.decorateDiagnostic' — in particular the pure
    
    282
    -    'GHC.Utils.Error.pprLocMsgEnvelope', used e.g. when 'show'ing a
    
    283
    -    'GHC.Types.SourceError.SourceError' and for deferred type errors — list
    
    284
    -    /all/ the locations under @At:@.
    
    261
    +Locations are rendered exactly in the order they are provided.
    
    262
    +Not every location can be shown as a caret:
    
    263
    +  - carets are optional (@-fno-diagnostics-show-caret@)
    
    264
    +  - some spans have no source to display anyway (e.g. GHCi input or TH-generated code)
    
    265
    +  - they require 'IO' to read the source code, so pure code (e.g. 'Show SourceError')
    
    266
    +    doesn't include them.
    
    267
    +
    
    268
    +Locations that get no caret are instead listed under an @At:@ heading.
    
    285 269
     
    
    286 270
     How a message author should pick and order the spans is the subject of
    
    287 271
     Note [Choosing the primary and related spans].
    
    ... ... @@ -903,11 +887,9 @@ pprAtLocations primary spans
    903 887
     
    
    904 888
     -- | When @show_caret@ is set, render carets for the given spans; otherwise
    
    905 889
     -- render nothing. Either way, return the real spans that did /not/ get a caret,
    
    906
    --- so the caller can report those locations textually. A span is missed when
    
    907
    --- carets are disabled, or when its source is unavailable (an unhelpful span —
    
    908
    --- dropped here — or unreadable source such as GHCi input or TH-generated code).
    
    909
    --- The spans are kept in the order they were given in; see Note [The source span
    
    910
    --- model for diagnostics].
    
    890
    +-- so the caller can report those locations textually.
    
    891
    +--
    
    892
    +-- See Note [The source span model for diagnostics].
    
    911 893
     getCaretDiagnostics :: Bool -> MessageClass -> NonEmpty SrcSpan -> IO (SDoc, [RealSrcSpan])
    
    912 894
     getCaretDiagnostics show_caret msg_class spans
    
    913 895
       | not show_caret = pure (empty, realSpans)
    

  • compiler/GHC/Utils/Logger.hs
    ... ... @@ -479,11 +479,7 @@ decorateDiagnostic logflags msg_class srcSpan msg = addLocations
    479 479
             _                        -> []
    
    480 480
     
    
    481 481
           -- The primary span is always caret'd, with the related spans drawn as
    
    482
    -      -- additional carets.  Order is the message author's: the primary first,
    
    483
    -      -- then the related spans as given.  'getCaretDiagnostics' preserves that
    
    484
    -      -- order and does not deduplicate, so an author must not repeat the primary
    
    485
    -      -- among the related spans.
    
    486
    -      -- See Note [The source span model for diagnostics] in GHC.Types.Error.
    
    482
    +      -- additional carets. See Note [The source span model for diagnostics] in GHC.Types.Error.
    
    487 483
           sourceSpans :: NonEmpty SrcSpan
    
    488 484
           sourceSpans = srcSpan :| relatedSpans
    
    489 485