1-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
4{-# LANGUAGE OverloadedStrings #-}
6module Development.IDE.Types.Diagnostics (
9 LSP.DiagnosticSeverity(..),
14 showDiagnosticsColored,
17import Data.Maybe as Maybe
18import qualified Data.Text as T
19import Data.Text.Prettyprint.Doc
20import qualified Language.Haskell.LSP.Types as LSP
21import Language.Haskell.LSP.Types as LSP (
22 DiagnosticSeverity(..)
26import Language.Haskell.LSP.Diagnostics
27import Data.Text.Prettyprint.Doc.Render.Text
28import qualified Data.Text.Prettyprint.Doc.Render.Terminal as Terminal
29import Data.Text.Prettyprint.Doc.Render.Terminal (Color(..), color)
31import Development.IDE.Types.Location
34ideErrorText :: NormalizedFilePath -> T.Text -> FileDiagnostic
35ideErrorText fp msg = (fp, LSP.Diagnostic {
37 _severity = Just LSP.DsError,
39 _source = Just "compiler",
41 _relatedInformation = Nothing
45-- | Human readable diagnostics for a specific file.
47-- This type packages a pretty printed, human readable error message
48-- along with the related source location so that we can display the error
49-- on either the console or in the IDE at the right source location.
51type FileDiagnostic = (NormalizedFilePath, Diagnostic)
53prettyRange :: Range -> Doc Terminal.AnsiStyle
54prettyRange Range{..} = f _start <> "-" <> f _end
55 where f Position{..} = pretty (_line+1) <> colon <> pretty _character
57stringParagraphs :: T.Text -> Doc a
58stringParagraphs = vcat . map (fillSep . map pretty . T.words) . T.lines
60showDiagnostics :: [FileDiagnostic] -> T.Text
61showDiagnostics = srenderPlain . prettyDiagnostics
63showDiagnosticsColored :: [FileDiagnostic] -> T.Text
64showDiagnosticsColored = srenderColored . prettyDiagnostics
67prettyDiagnostics :: [FileDiagnostic] -> Doc Terminal.AnsiStyle
68prettyDiagnostics = vcat . map prettyDiagnostic
70prettyDiagnostic :: FileDiagnostic -> Doc Terminal.AnsiStyle
71prettyDiagnostic (fp, LSP.Diagnostic{..}) =
73 [ slabel_ "File: " $ pretty (fromNormalizedFilePath fp)
74 , slabel_ "Range: " $ prettyRange _range
75 , slabel_ "Source: " $ pretty _source
76 , slabel_ "Severity:" $ pretty $ show sev
79 LSP.DsError -> annotate $ color Red
80 LSP.DsWarning -> annotate $ color Yellow
81 LSP.DsInfo -> annotate $ color Blue
82 LSP.DsHint -> annotate $ color Magenta
83 $ stringParagraphs _message
84 , slabel_ "Code:" $ pretty _code
87 sev = fromMaybe LSP.DsError _severity
91slabel_ :: String -> Doc a -> Doc a
92slabel_ t d = nest 2 $ sep [pretty t, d]
94-- | The layout options used for the SDK assistant.
97 -- ^ Rendering width of the pretty printer.
99cliLayout renderWidth = LayoutOptions
100 { layoutPageWidth = AvailablePerLine renderWidth 0.9
103-- | Render without any syntax annotations
104srenderPlain :: Doc ann -> T.Text
105srenderPlain = renderStrict . layoutSmart (cliLayout defaultTermWidth)
107-- | Render a 'Document' as an ANSII colored string.
108srenderColored :: Doc Terminal.AnsiStyle -> T.Text
110 Terminal.renderStrict .
111 layoutSmart defaultLayoutOptions { layoutPageWidth = AvailablePerLine 100 1.0 }
113defaultTermWidth :: Int
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list