@@ -27,7 +27,7 @@ import Data.Maybe as Maybe
27import Data.Foldable
27import Data.Foldable
28import qualified Data.Map as Map
28import qualified Data.Map as Map
29import qualified Data.Text as T
29import qualified Data.Text as T
30−import Data.Text.Prettyprint.Doc.Syntax
30+import Data.Text.Prettyprint.Doc
31import qualified Data.SortedList as SL
31import qualified Data.SortedList as SL
32import qualified Text.PrettyPrint.Annotated.HughesPJClass as Pretty
32import qualified Text.PrettyPrint.Annotated.HughesPJClass as Pretty
33import qualified Language.Haskell.LSP.Types as LSP
33import qualified Language.Haskell.LSP.Types as LSP
@@ -38,6 +38,9 @@ import Language.Haskell.LSP.Types as LSP (
38 , DiagnosticRelatedInformation(..)
38 , DiagnosticRelatedInformation(..)
40import Language.Haskell.LSP.Diagnostics
40import Language.Haskell.LSP.Diagnostics
41+import Data.Text.Prettyprint.Doc.Render.Text
42+import qualified Data.Text.Prettyprint.Doc.Render.Terminal as Terminal
43+import Data.Text.Prettyprint.Doc.Render.Terminal (Color(..), color)
42import Development.IDE.Types.Location
45import Development.IDE.Types.Location
@@ -77,7 +80,7 @@ diagnostic rng sev src msg
78type FileDiagnostic = (NormalizedFilePath, Diagnostic)
81type FileDiagnostic = (NormalizedFilePath, Diagnostic)
80−prettyRange :: Range -> Doc SyntaxClass
83+prettyRange :: Range -> Doc Terminal.AnsiStyle
81prettyRange Range{..} = f _start <> "-" <> f _end
84prettyRange Range{..} = f _start <> "-" <> f _end
82 where f Position{..} = pretty (_line+1) <> colon <> pretty _character
85 where f Position{..} = pretty (_line+1) <> colon <> pretty _character
@@ -91,10 +94,10 @@ showDiagnosticsColored :: [FileDiagnostic] -> T.Text
91showDiagnosticsColored = srenderColored . prettyDiagnostics
94showDiagnosticsColored = srenderColored . prettyDiagnostics
94−prettyDiagnostics :: [FileDiagnostic] -> Doc SyntaxClass
97+prettyDiagnostics :: [FileDiagnostic] -> Doc Terminal.AnsiStyle
95prettyDiagnostics = vcat . map prettyDiagnostic
98prettyDiagnostics = vcat . map prettyDiagnostic
97−prettyDiagnostic :: FileDiagnostic -> Doc SyntaxClass
100+prettyDiagnostic :: FileDiagnostic -> Doc Terminal.AnsiStyle
98prettyDiagnostic (fp, LSP.Diagnostic{..}) =
101prettyDiagnostic (fp, LSP.Diagnostic{..}) =
100 [ slabel_ "File: " $ pretty (fromNormalizedFilePath fp)
103 [ slabel_ "File: " $ pretty (fromNormalizedFilePath fp)
@@ -103,10 +106,10 @@ prettyDiagnostic (fp, LSP.Diagnostic{..}) =
103 , slabel_ "Severity:" $ pretty $ show sev
106 , slabel_ "Severity:" $ pretty $ show sev
104 , slabel_ "Message: "
107 , slabel_ "Message: "
105 $ case sev of
108 $ case sev of
106− LSP.DsError -> annotate ErrorSC
109+ LSP.DsError -> annotate $ color Red
107− LSP.DsWarning -> annotate WarningSC
110+ LSP.DsWarning -> annotate $ color Yellow
108− LSP.DsInfo -> annotate InfoSC
111+ LSP.DsInfo -> annotate $ color Blue
109− LSP.DsHint -> annotate HintSC
112+ LSP.DsHint -> annotate $ color Magenta
110 $ stringParagraphs _message
113 $ stringParagraphs _message
111 , slabel_ "Code:" $ pretty _code
114 , slabel_ "Code:" $ pretty _code
@@ -154,3 +157,31 @@ filterDiagnostics ::
154 DiagnosticStore
157 DiagnosticStore
155filterDiagnostics keep =
158filterDiagnostics keep =
156 Map.filterWithKey (\uri _ -> maybe True (keep . toNormalizedFilePath) $ uriToFilePath' $ fromNormalizedUri uri)
159 Map.filterWithKey (\uri _ -> maybe True (keep . toNormalizedFilePath) $ uriToFilePath' $ fromNormalizedUri uri)
163+-- | Label a document.
164+slabel_ :: String -> Doc a -> Doc a
165+slabel_ t d = nest 2 $ sep [pretty t, d]
167+-- | The layout options used for the SDK assistant.
170+ -- ^ Rendering width of the pretty printer.
172+cliLayout renderWidth = LayoutOptions
173+ { layoutPageWidth = AvailablePerLine renderWidth 0.9
176+-- | Render without any syntax annotations
177+srenderPlain :: Doc ann -> T.Text
178+srenderPlain = renderStrict . layoutSmart (cliLayout defaultTermWidth)
180+-- | Render a 'Document' as an ANSII colored string.
181+srenderColored :: Doc Terminal.AnsiStyle -> T.Text
183+ Terminal.renderStrict .
184+ layoutSmart defaultLayoutOptions { layoutPageWidth = AvailablePerLine 100 1.0 }
186+defaultTermWidth :: Int
187+defaultTermWidth = 80