on master help sign in
Delete prettyprinter-syntax (#1829)

* Delete the entirely unused reflow function * Don't have Data.Text.Prettyprint.Doc.Syntax reexport stuff * Move most of the pretty printing inside hie-core * Get rid of the prettyprinter-syntax dependency from hie-core * Get rid of prettyprinter-syntax, by collapsing the one definition into DA.Pretty

commit163bbc9133e44b5b5d4c8bad334d9160e58d3905 authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateMon 24 Jun 2019, 08:00 (7 years ago) parent0452205
3 files changed+41−18
BUILD.bazel+1−7 hie-core.cabal+1−3 src/Development/IDE/Types/Diagnostics.hs+39−8
BUILD.bazel+1−7
@@ -24,6 +24,7 @@ depends = [
2424 "network-uri",
2525 "pretty",
2626 "prettyprinter",
27+ "prettyprinter-ansi-terminal",
2728 "rope-utf16-splay",
2829 "safe-exceptions",
2930 "sorted-list",
@@ -48,9 +49,6 @@ da_haskell_library(
4849 ],
4950 src_strip_prefix = "src",
5051 visibility = ["//visibility:public"],
51− deps = [
52− "//libs-haskell/prettyprinter-syntax",
53− ],
5452)
5553
5654da_haskell_library(
@@ -70,9 +68,6 @@ da_haskell_library(
7068 ],
7169 src_strip_prefix = "src",
7270 visibility = ["//visibility:public"],
73− deps = [
74− "//libs-haskell/prettyprinter-syntax",
75− ],
7671)
7772
7873da_haskell_binary(
@@ -96,6 +91,5 @@ da_haskell_binary(
9691 visibility = ["//visibility:public"],
9792 deps = [
9893 "hie-core-public",
99− "//libs-haskell/prettyprinter-syntax",
10094 ],
10195) 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
4242 mtl,
4343 network-uri,
4444 pretty,
45+ prettyprinter-ansi-terminal,
4546 rope-utf16-splay,
4647 safe-exceptions,
4748 shake,
@@ -74,7 +75,6 @@ library
7475
7576 hs-source-dirs:
7677 src
77− ../../libs-haskell/prettyprinter-syntax/src
7878 exposed-modules:
7979 Development.IDE.Types.Logger
8080 Development.IDE.GHC.Util
@@ -103,8 +103,6 @@ library
103103 Development.IDE.Types.Diagnostics
104104 Development.IDE.Types.Location
105105 Development.IDE.Spans.Type
106− other-modules:
107− Data.Text.Prettyprint.Doc.Syntax
108106
109107executable hie-core
110108 default-language: Haskell2010
src/Development/IDE/Types/Diagnostics.hs+39−8
@@ -27,7 +27,7 @@ import Data.Maybe as Maybe
2727import Data.Foldable
2828import qualified Data.Map as Map
2929import qualified Data.Text as T
30−import Data.Text.Prettyprint.Doc.Syntax
30+import Data.Text.Prettyprint.Doc
3131import qualified Data.SortedList as SL
3232import qualified Text.PrettyPrint.Annotated.HughesPJClass as Pretty
3333import qualified Language.Haskell.LSP.Types as LSP
@@ -38,6 +38,9 @@ import Language.Haskell.LSP.Types as LSP (
3838 , DiagnosticRelatedInformation(..)
3939 )
4040import 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)
4144
4245import Development.IDE.Types.Location
4346
@@ -77,7 +80,7 @@ diagnostic rng sev src msg
7780--
7881type FileDiagnostic = (NormalizedFilePath, Diagnostic)
7982
80−prettyRange :: Range -> Doc SyntaxClass
83+prettyRange :: Range -> Doc Terminal.AnsiStyle
8184prettyRange Range{..} = f _start <> "-" <> f _end
8285 where f Position{..} = pretty (_line+1) <> colon <> pretty _character
8386
@@ -91,10 +94,10 @@ showDiagnosticsColored :: [FileDiagnostic] -> T.Text
9194showDiagnosticsColored = srenderColored . prettyDiagnostics
9295
9396
94−prettyDiagnostics :: [FileDiagnostic] -> Doc SyntaxClass
97+prettyDiagnostics :: [FileDiagnostic] -> Doc Terminal.AnsiStyle
9598prettyDiagnostics = vcat . map prettyDiagnostic
9699
97−prettyDiagnostic :: FileDiagnostic -> Doc SyntaxClass
100+prettyDiagnostic :: FileDiagnostic -> Doc Terminal.AnsiStyle
98101prettyDiagnostic (fp, LSP.Diagnostic{..}) =
99102 vcat
100103 [ slabel_ "File: " $ pretty (fromNormalizedFilePath fp)
@@ -103,10 +106,10 @@ prettyDiagnostic (fp, LSP.Diagnostic{..}) =
103106 , slabel_ "Severity:" $ pretty $ show sev
104107 , slabel_ "Message: "
105108 $ case sev of
106− LSP.DsError -> annotate ErrorSC
107− LSP.DsWarning -> annotate WarningSC
108− LSP.DsInfo -> annotate InfoSC
109− LSP.DsHint -> annotate HintSC
109+ LSP.DsError -> annotate $ color Red
110+ LSP.DsWarning -> annotate $ color Yellow
111+ LSP.DsInfo -> annotate $ color Blue
112+ LSP.DsHint -> annotate $ color Magenta
110113 $ stringParagraphs _message
111114 , slabel_ "Code:" $ pretty _code
112115 ]
@@ -154,3 +157,31 @@ filterDiagnostics ::
154157 DiagnosticStore
155158filterDiagnostics keep =
156159 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