Skip to content

Commit

Permalink
Delete prettyprinter-syntax (digital-asset#1829)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
neil-da authored and ndmitchell committed Jun 24, 2019
1 parent b0a4657 commit 282f8b4
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .hie-bios
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
bazel run --define hie_bios_ghci=True //daml-foundations/daml-tools/da-hs-damlc-app:da-hs-damlc-app@ghci | sed "s/'//g" | sed "s/-qg//g" | sed "s/+RTS.*-RTS//" | sed "s|/bazel-out|bazel-out|g" | sed "s/-fexternal-interpreter//g"
echo -idaml-foundations/daml-ghc/ide/src -icompiler/scenario-service/client/src -icompiler/daml-lf-ast/src -icompiler/hie-core/src -idaml-foundations/daml-ghc/ghc-compiler/src -icompiler/daml-lf-proto/src -idaml-foundations/daml-ghc/ghc-compiler/src -ilibs-haskell/da-hs-base/src -ilibs-haskell/bazel-runfiles/src -icompiler/daml-lf-tools/src -ibazel-out/k8-fastbuild/genfiles/daml-lf/archive -ilibs-haskell/prettyprinter-syntax/src -ibazel-out/k8-fastbuild/genfiles/compiler/scenario-service/protos
echo -idaml-foundations/daml-ghc/ide/src -icompiler/scenario-service/client/src -icompiler/daml-lf-ast/src -icompiler/hie-core/src -idaml-foundations/daml-ghc/ghc-compiler/src -icompiler/daml-lf-proto/src -idaml-foundations/daml-ghc/ghc-compiler/src -ilibs-haskell/da-hs-base/src -ilibs-haskell/bazel-runfiles/src -icompiler/daml-lf-tools/src -ibazel-out/k8-fastbuild/genfiles/daml-lf/archive -ibazel-out/k8-fastbuild/genfiles/compiler/scenario-service/protos
8 changes: 1 addition & 7 deletions compiler/hie-core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ depends = [
"network-uri",
"pretty",
"prettyprinter",
"prettyprinter-ansi-terminal",
"rope-utf16-splay",
"safe-exceptions",
"sorted-list",
Expand All @@ -48,9 +49,6 @@ da_haskell_library(
],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
"//libs-haskell/prettyprinter-syntax",
],
)

da_haskell_library(
Expand All @@ -70,9 +68,6 @@ da_haskell_library(
],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
"//libs-haskell/prettyprinter-syntax",
],
)

da_haskell_binary(
Expand All @@ -96,6 +91,5 @@ da_haskell_binary(
visibility = ["//visibility:public"],
deps = [
"hie-core-public",
"//libs-haskell/prettyprinter-syntax",
],
) if not is_windows else None # Disable on Windows until ghc-paths is fixed upstream
4 changes: 1 addition & 3 deletions compiler/hie-core/hie-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ library
mtl,
network-uri,
pretty,
prettyprinter-ansi-terminal,
rope-utf16-splay,
safe-exceptions,
shake,
Expand Down Expand Up @@ -74,7 +75,6 @@ library

hs-source-dirs:
src
../../libs-haskell/prettyprinter-syntax/src
exposed-modules:
Development.IDE.Types.Logger
Development.IDE.GHC.Util
Expand Down Expand Up @@ -103,8 +103,6 @@ library
Development.IDE.Types.Diagnostics
Development.IDE.Types.Location
Development.IDE.Spans.Type
other-modules:
Data.Text.Prettyprint.Doc.Syntax

executable hie-core
default-language: Haskell2010
Expand Down
47 changes: 39 additions & 8 deletions compiler/hie-core/src/Development/IDE/Types/Diagnostics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Data.Maybe as Maybe
import Data.Foldable
import qualified Data.Map as Map
import qualified Data.Text as T
import Data.Text.Prettyprint.Doc.Syntax
import Data.Text.Prettyprint.Doc
import qualified Data.SortedList as SL
import qualified Text.PrettyPrint.Annotated.HughesPJClass as Pretty
import qualified Language.Haskell.LSP.Types as LSP
Expand All @@ -38,6 +38,9 @@ import Language.Haskell.LSP.Types as LSP (
, DiagnosticRelatedInformation(..)
)
import Language.Haskell.LSP.Diagnostics
import Data.Text.Prettyprint.Doc.Render.Text
import qualified Data.Text.Prettyprint.Doc.Render.Terminal as Terminal
import Data.Text.Prettyprint.Doc.Render.Terminal (Color(..), color)

import Development.IDE.Types.Location

Expand Down Expand Up @@ -77,7 +80,7 @@ diagnostic rng sev src msg
--
type FileDiagnostic = (NormalizedFilePath, Diagnostic)

prettyRange :: Range -> Doc SyntaxClass
prettyRange :: Range -> Doc Terminal.AnsiStyle
prettyRange Range{..} = f _start <> "-" <> f _end
where f Position{..} = pretty (_line+1) <> colon <> pretty _character

Expand All @@ -91,10 +94,10 @@ showDiagnosticsColored :: [FileDiagnostic] -> T.Text
showDiagnosticsColored = srenderColored . prettyDiagnostics


prettyDiagnostics :: [FileDiagnostic] -> Doc SyntaxClass
prettyDiagnostics :: [FileDiagnostic] -> Doc Terminal.AnsiStyle
prettyDiagnostics = vcat . map prettyDiagnostic

prettyDiagnostic :: FileDiagnostic -> Doc SyntaxClass
prettyDiagnostic :: FileDiagnostic -> Doc Terminal.AnsiStyle
prettyDiagnostic (fp, LSP.Diagnostic{..}) =
vcat
[ slabel_ "File: " $ pretty (fromNormalizedFilePath fp)
Expand All @@ -103,10 +106,10 @@ prettyDiagnostic (fp, LSP.Diagnostic{..}) =
, slabel_ "Severity:" $ pretty $ show sev
, slabel_ "Message: "
$ case sev of
LSP.DsError -> annotate ErrorSC
LSP.DsWarning -> annotate WarningSC
LSP.DsInfo -> annotate InfoSC
LSP.DsHint -> annotate HintSC
LSP.DsError -> annotate $ color Red
LSP.DsWarning -> annotate $ color Yellow
LSP.DsInfo -> annotate $ color Blue
LSP.DsHint -> annotate $ color Magenta
$ stringParagraphs _message
, slabel_ "Code:" $ pretty _code
]
Expand Down Expand Up @@ -154,3 +157,31 @@ filterDiagnostics ::
DiagnosticStore
filterDiagnostics keep =
Map.filterWithKey (\uri _ -> maybe True (keep . toNormalizedFilePath) $ uriToFilePath' $ fromNormalizedUri uri)



-- | Label a document.
slabel_ :: String -> Doc a -> Doc a
slabel_ t d = nest 2 $ sep [pretty t, d]

-- | The layout options used for the SDK assistant.
cliLayout ::
Int
-- ^ Rendering width of the pretty printer.
-> LayoutOptions
cliLayout renderWidth = LayoutOptions
{ layoutPageWidth = AvailablePerLine renderWidth 0.9
}

-- | Render without any syntax annotations
srenderPlain :: Doc ann -> T.Text
srenderPlain = renderStrict . layoutSmart (cliLayout defaultTermWidth)

-- | Render a 'Document' as an ANSII colored string.
srenderColored :: Doc Terminal.AnsiStyle -> T.Text
srenderColored =
Terminal.renderStrict .
layoutSmart defaultLayoutOptions { layoutPageWidth = AvailablePerLine 100 1.0 }

defaultTermWidth :: Int
defaultTermWidth = 80
1 change: 0 additions & 1 deletion daml-foundations/daml-ghc/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def daml_ghc_integration_test(name, main_function):
"//daml-lf/archive:daml_lf_haskell_proto",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
"//libs-haskell/prettyprinter-syntax",
],
hazel_deps = [
"aeson",
Expand Down
1 change: 0 additions & 1 deletion daml-foundations/daml-tools/da-hs-daml-cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ da_haskell_library(
"//daml-lf/archive:daml_lf_haskell_proto",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
"//libs-haskell/prettyprinter-syntax",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module DA.Cli.Damlc.Test (

import Control.Monad.Except
import qualified DA.Pretty
import qualified DA.Pretty as Pretty
import DA.Cli.Damlc.Base
import Data.Maybe
import Data.List.Extra
Expand All @@ -23,7 +24,6 @@ import qualified DA.Daml.LF.Ast as LF
import qualified DA.Daml.LF.PrettyScenario as SS
import qualified DA.Daml.LF.ScenarioServiceClient as SSC
import qualified Data.Text as T
import qualified Data.Text.Prettyprint.Doc.Syntax as Pretty
import qualified Data.Vector as V
import qualified Development.Shake as Shake
import qualified Development.IDE.State.API as CompilerService
Expand Down
1 change: 0 additions & 1 deletion libs-haskell/da-hs-base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ da_haskell_library(
visibility = ["//visibility:public"],
deps = [
"//daml-assistant:daml-project-config",
"//libs-haskell/prettyprinter-syntax",
],
)

Expand Down
20 changes: 19 additions & 1 deletion libs-haskell/da-hs-base/src/DA/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,25 @@ import System.Console.ANSI
, setSGRCode
)

import Data.Text.Prettyprint.Doc.Syntax (SyntaxClass(..))

-- | Classes of syntax elements, which are used for highlighting.
data SyntaxClass
= -- ^ Annotation to use as a no-op for highlighting.
OperatorSC
| KeywordSC
| PredicateSC
| ConstructorSC
| TypeSC
| ErrorSC
| WarningSC
| InfoSC
| HintSC
| LinkSC T.Text T.Text
-- ^ @LinkSC url title@: Create a link to the 'url'
| IdSC T.Text
-- ^ @IdSC id@: Identifier for the node. For linking into.
| OnClickSC T.Text
deriving (Eq, Ord, Show)


------------------------------------------------------------------------------
Expand Down
17 changes: 0 additions & 17 deletions libs-haskell/prettyprinter-syntax/BUILD.bazel

This file was deleted.

This file was deleted.

0 comments on commit 282f8b4

Please sign in to comment.