1-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
5module Development.IDE.Types.Diagnostics (
8 LSP.DiagnosticSeverity(..),
13 showDiagnosticsColored,
16import Data.Maybe as Maybe
17import qualified Data.Text as T
18import Data.Text.Prettyprint.Doc
19import qualified Language.Haskell.LSP.Types as LSP
20import Language.Haskell.LSP.Types as LSP (
21 DiagnosticSeverity(..)
25import Language.Haskell.LSP.Diagnostics
26import Data.Text.Prettyprint.Doc.Render.Text
27import qualified Data.Text.Prettyprint.Doc.Render.Terminal as Terminal
28import Data.Text.Prettyprint.Doc.Render.Terminal (Color(..), color)
30import Development.IDE.Types.Location
33ideErrorText :: NormalizedFilePath -> T.Text -> FileDiagnostic
34ideErrorText fp msg = (fp, LSP.Diagnostic {
36 _severity = Just LSP.DsError,
38 _source = Just "compiler",
40 _relatedInformation = Nothing
44-- | Human readable diagnostics for a specific file.
46-- This type packages a pretty printed, human readable error message
47-- along with the related source location so that we can display the error
48-- on either the console or in the IDE at the right source location.
50type FileDiagnostic = (NormalizedFilePath, Diagnostic)
52prettyRange :: Range -> Doc Terminal.AnsiStyle
53prettyRange Range{..} = f _start <> "-" <> f _end
54 where f Position{..} = pretty (_line+1) <> colon <> pretty _character
56stringParagraphs :: T.Text -> Doc a
57stringParagraphs = vcat . map (fillSep . map pretty . T.words) . T.lines
59showDiagnostics :: [FileDiagnostic] -> T.Text
60showDiagnostics = srenderPlain . prettyDiagnostics
62showDiagnosticsColored :: [FileDiagnostic] -> T.Text
63showDiagnosticsColored = srenderColored . prettyDiagnostics
66prettyDiagnostics :: [FileDiagnostic] -> Doc Terminal.AnsiStyle
67prettyDiagnostics = vcat . map prettyDiagnostic
69prettyDiagnostic :: FileDiagnostic -> Doc Terminal.AnsiStyle
70prettyDiagnostic (fp, LSP.Diagnostic{..}) =
72 [ slabel_ "File: " $ pretty (fromNormalizedFilePath fp)
73 , slabel_ "Range: " $ prettyRange _range
74 , slabel_ "Source: " $ pretty _source
75 , slabel_ "Severity:" $ pretty $ show sev
78 LSP.DsError -> annotate $ color Red
79 LSP.DsWarning -> annotate $ color Yellow
80 LSP.DsInfo -> annotate $ color Blue
81 LSP.DsHint -> annotate $ color Magenta
82 $ stringParagraphs _message
85 sev = fromMaybe LSP.DsError _severity
89slabel_ :: String -> Doc a -> Doc a
90slabel_ t d = nest 2 $ sep [pretty t, d]
92-- | The layout options used for the SDK assistant.
95 -- ^ Rendering width of the pretty printer.
97cliLayout renderWidth = LayoutOptions
98 { layoutPageWidth = AvailablePerLine renderWidth 0.9
101-- | Render without any syntax annotations
102srenderPlain :: Doc ann -> T.Text
103srenderPlain = renderStrict . layoutSmart (cliLayout defaultTermWidth)
105-- | Render a 'Document' as an ANSII colored string.
106srenderColored :: Doc Terminal.AnsiStyle -> T.Text
108 Terminal.renderStrict .
109 layoutSmart defaultLayoutOptions { layoutPageWidth = AvailablePerLine 100 1.0 }
111defaultTermWidth :: 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