on master help sign in
Delete prettyprinter-syntax (#1829)
163bbc9Neil Mitchell
BUILD.bazel+1−7
@@ -24,6 +24,7 @@ depends = [
24 "network-uri",
24 "network-uri",
25 "pretty",
25 "pretty",
26 "prettyprinter",
26 "prettyprinter",
27+ "prettyprinter-ansi-terminal",
27 "rope-utf16-splay",
28 "rope-utf16-splay",
28 "safe-exceptions",
29 "safe-exceptions",
29 "sorted-list",
30 "sorted-list",
@@ -48,9 +49,6 @@ da_haskell_library(
48 ],
49 ],
49 src_strip_prefix = "src",
50 src_strip_prefix = "src",
50 visibility = ["//visibility:public"],
51 visibility = ["//visibility:public"],
51− deps = [
52− "//libs-haskell/prettyprinter-syntax",
53− ],
54)
52)
55
53
56da_haskell_library(
54da_haskell_library(
@@ -70,9 +68,6 @@ da_haskell_library(
70 ],
68 ],
71 src_strip_prefix = "src",
69 src_strip_prefix = "src",
72 visibility = ["//visibility:public"],
70 visibility = ["//visibility:public"],
73− deps = [
74− "//libs-haskell/prettyprinter-syntax",
75− ],
76)
71)
77
72
78da_haskell_binary(
73da_haskell_binary(
@@ -96,6 +91,5 @@ da_haskell_binary(
96 visibility = ["//visibility:public"],
91 visibility = ["//visibility:public"],
97 deps = [
92 deps = [
98 "hie-core-public",
93 "hie-core-public",
99− "//libs-haskell/prettyprinter-syntax",
100 ],
94 ],
101) if not is_windows else None # Disable on Windows until ghc-paths is fixed upstream
95) if not is_windows else None # Disable on Windows until ghc-paths is fixed upstream
hie-core.cabal+1−3
@@ -42,6 +42,7 @@ library
42 mtl,
42 mtl,
43 network-uri,
43 network-uri,
44 pretty,
44 pretty,
45+ prettyprinter-ansi-terminal,
45 rope-utf16-splay,
46 rope-utf16-splay,
46 safe-exceptions,
47 safe-exceptions,
47 shake,
48 shake,
@@ -74,7 +75,6 @@ library
74
75
75 hs-source-dirs:
76 hs-source-dirs:
76 src
77 src
77− ../../libs-haskell/prettyprinter-syntax/src
78 exposed-modules:
78 exposed-modules:
79 Development.IDE.Types.Logger
79 Development.IDE.Types.Logger
80 Development.IDE.GHC.Util
80 Development.IDE.GHC.Util
@@ -103,8 +103,6 @@ library
103 Development.IDE.Types.Diagnostics
103 Development.IDE.Types.Diagnostics
104 Development.IDE.Types.Location
104 Development.IDE.Types.Location
105 Development.IDE.Spans.Type
105 Development.IDE.Spans.Type
106− other-modules:
107− Data.Text.Prettyprint.Doc.Syntax
108
106
109executable hie-core
107executable hie-core
110 default-language: Haskell2010
108 default-language: Haskell2010
src/Development/IDE/Types/Diagnostics.hs+39−8
@@ -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(..)
39 )
39 )
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)
41
44
42import Development.IDE.Types.Location
45import Development.IDE.Types.Location
43
46
@@ -77,7 +80,7 @@ diagnostic rng sev src msg
77--
80--
78type FileDiagnostic = (NormalizedFilePath, Diagnostic)
81type FileDiagnostic = (NormalizedFilePath, Diagnostic)
79
82
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
83
86
@@ -91,10 +94,10 @@ showDiagnosticsColored :: [FileDiagnostic] -> T.Text
91showDiagnosticsColored = srenderColored . prettyDiagnostics
94showDiagnosticsColored = srenderColored . prettyDiagnostics
92
95
93
96
94−prettyDiagnostics :: [FileDiagnostic] -> Doc SyntaxClass
97+prettyDiagnostics :: [FileDiagnostic] -> Doc Terminal.AnsiStyle
95prettyDiagnostics = vcat . map prettyDiagnostic
98prettyDiagnostics = vcat . map prettyDiagnostic
96
99
97−prettyDiagnostic :: FileDiagnostic -> Doc SyntaxClass
100+prettyDiagnostic :: FileDiagnostic -> Doc Terminal.AnsiStyle
98prettyDiagnostic (fp, LSP.Diagnostic{..}) =
101prettyDiagnostic (fp, LSP.Diagnostic{..}) =
99 vcat
102 vcat
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
112 ]
115 ]
@@ -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)
160+
161+
162+
163+-- | Label a document.
164+slabel_ :: String -> Doc a -> Doc a
165+slabel_ t d = nest 2 $ sep [pretty t, d]
166+
167+-- | The layout options used for the SDK assistant.
168+cliLayout ::
169+ Int
170+ -- ^ Rendering width of the pretty printer.
171+ -> LayoutOptions
172+cliLayout renderWidth = LayoutOptions
173+ { layoutPageWidth = AvailablePerLine renderWidth 0.9
174+ }
175+
176+-- | Render without any syntax annotations
177+srenderPlain :: Doc ann -> T.Text
178+srenderPlain = renderStrict . layoutSmart (cliLayout defaultTermWidth)
179+
180+-- | Render a 'Document' as an ANSII colored string.
181+srenderColored :: Doc Terminal.AnsiStyle -> T.Text
182+srenderColored =
183+ Terminal.renderStrict .
184+ layoutSmart defaultLayoutOptions { layoutPageWidth = AvailablePerLine 100 1.0 }
185+
186+defaultTermWidth :: Int
187+defaultTermWidth = 80