From 895652eeb927db58659b5219a4f922fad1045c6b Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Tue, 19 Dec 2017 15:28:52 +0100 Subject: [PATCH 1/6] Update README.md for stackage lts release --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3196b27..c7bd461 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ log the size of the input, but _not_ the full requests.) # Other usage notes - Supports GHC versions `8.0.*` and `8.2.*`. -- as of November'17, `brittany` is available on stackage nightly. +- included in stackage with lts>=10.0 (or nightlies dating to >=2017-11-15) - config (file) documentation is lacking. - some config values can not be configured via commandline yet. - uses/creates user config file in `~/.config/brittany/config.yaml`; @@ -84,11 +84,11 @@ log the size of the input, but _not_ the full requests.) - via `stack` using a sufficiently recent stackage snapshot (dated to >= 2017-11-15) ~~~~.sh - stack install brittany # --resolver=nightly-2017-11-15 + stack install brittany # --resolver lts-10.0 ~~~~ - (alternatively, should nightlies be unreliable, or you want to use ghc-8.0 or something, then - cloning the repo and doing `stack install` will use an lts resolver.) + (earlier ltss did not include `brittany` yet, but the repo should contain a + `stack.yaml` that works with ghc-8.0.) - on ArchLinux via [the britanny AUR package](https://aur.archlinux.org/packages/brittany/) using `aura`: -- 2.30.2 From 04764aa0f827778d3904e7333910753d75254618 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Sat, 13 Jan 2018 18:02:00 +0100 Subject: [PATCH 2/6] Update readme: Add editor integration paragraph --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index c7bd461..ba6fe36 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,19 @@ log the size of the input, but _not_ the full requests.) aura -A brittany ~~~~ +# Editor Integration + +#### Sublime text + [In this gist](https://gist.github.com/lspitzner/097c33177248a65e7657f0c6d0d12075) + I have described a haskell setup that includes a shortcut to run brittany formatting. +#### VSCode + [This extension](https://marketplace.visualstudio.com/items?itemName=MaxGabriel.brittany) + connects commandline `brittany` to VSCode formatting API. Thanks to Max Garbriel. +#### Via HIE + [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine) + includes a `brittany` plugin that directly uses the brittany library. + Relevant for any editors that properly support the language-server-protocol. + # Usage - Default mode of operation: Transform a single module, from `stdin` to `stdout`. -- 2.30.2 From 7892b0e42d57c1d853a94481a8209cb53be34fbc Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Sat, 13 Jan 2018 18:05:21 +0100 Subject: [PATCH 3/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba6fe36..3850fbd 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ log the size of the input, but _not_ the full requests.) I have described a haskell setup that includes a shortcut to run brittany formatting. #### VSCode [This extension](https://marketplace.visualstudio.com/items?itemName=MaxGabriel.brittany) - connects commandline `brittany` to VSCode formatting API. Thanks to Max Garbriel. + connects commandline `brittany` to VSCode formatting API. Thanks to @MaxGarbriel. #### Via HIE [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine) includes a `brittany` plugin that directly uses the brittany library. -- 2.30.2 From 778381bbb83a1b2a7dd16672ed43ee191c5406cf Mon Sep 17 00:00:00 2001 From: Evan Rutledge Borden Date: Mon, 15 Jan 2018 16:02:14 -0500 Subject: [PATCH 4/6] Fix infix constructor pattern matching for normal constructors Brittany was previously only support symbol based infix constructors. It is common in some libraries (for example Esqueleto) to pattern match on normal constructors as infix. Brittany was failing in this case by not wrapping the constructor name in back ticks/spaces. Backticks and spaces have been added in the case where the constructor contains any alpha characters. --- src-literatetests/10-tests.blt | 3 +++ src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index a3d8591..6659847 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -355,6 +355,9 @@ func (x:xr) = x #pending func (x:+:xr) = x +#test normal infix constructor +func (x `Foo` xr) = x + ############################################################################### ############################################################################### diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs index ebdd91d..2f881a0 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs @@ -13,6 +13,7 @@ where import Language.Haskell.Brittany.Internal.Types import Language.Haskell.Brittany.Internal.LayouterBasics +import Data.Char (isAlpha) import RdrName ( RdrName(..) ) import GHC ( Located, runGhc, GenLocated(L), moduleNameString ) import HsSyn @@ -80,7 +81,9 @@ layoutPat lpat@(L _ pat) = docWrapNode lpat $ case pat of let nameDoc = lrdrNameToText lname leftDoc <- colsWrapPat =<< layoutPat left rightDoc <- colsWrapPat =<< layoutPat right - middle <- docLit nameDoc + middle <- docLit $ if Text.any isAlpha nameDoc + then Text.pack " `" <> nameDoc <> Text.pack "` " + else nameDoc return $ Seq.empty Seq.|> leftDoc Seq.|> middle Seq.|> rightDoc ConPatIn lname (RecCon (HsRecFields [] Nothing)) -> do -- Abc{} -> expr -- 2.30.2 From 3b0b5d3c4f6a23ddc67125247ad189ae0b9bde1e Mon Sep 17 00:00:00 2001 From: Evan Rutledge Borden Date: Mon, 15 Jan 2018 19:11:25 -0500 Subject: [PATCH 5/6] Change infix patterns to include spaces This commit changes infix patterns to utilize `lrdrNameToTextAnn`. This function allows the logic to avoid introspecting on the constructor name. Additionally this adds spaces to all infix operator pattern matches. Previously infix symbols did not include spaces: ``` foo (x:xs) = _ ``` Now they include a space ``` foo (x : xs) = _ ``` --- src-literatetests/10-tests.blt | 4 ++-- src-literatetests/15-regressions.blt | 4 ++-- src-literatetests/tests-context-free.blt | 6 +++--- .../Haskell/Brittany/Internal/Layouters/Pattern.hs | 8 +++----- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index 6659847..af873df 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -349,11 +349,11 @@ func reallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongvariable func (A a) = a #test list constructor -func (x:xr) = x +func (x : xr) = x #test some other constructor symbol #pending -func (x:+:xr) = x +func (x :+: xr) = x #test normal infix constructor func (x `Foo` xr) = x diff --git a/src-literatetests/15-regressions.blt b/src-literatetests/15-regressions.blt index 0fbc830..5c31ab6 100644 --- a/src-literatetests/15-regressions.blt +++ b/src-literatetests/15-regressions.blt @@ -123,8 +123,8 @@ func = do #test list comprehension comment placement func = [ (thing, take 10 alts) --TODO: select best ones - | (thing, _got, alts@(_:_)) <- nosuchFooThing - , gast <- award + | (thing, _got, alts@(_ : _)) <- nosuchFooThing + , gast <- award ] #test if-then-else comment placement diff --git a/src-literatetests/tests-context-free.blt b/src-literatetests/tests-context-free.blt index e8303cd..0d3d8cf 100644 --- a/src-literatetests/tests-context-free.blt +++ b/src-literatetests/tests-context-free.blt @@ -366,11 +366,11 @@ func reallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongvariable func (A a) = a #test list constructor -func (x:xr) = x +func (x : xr) = x #test some other constructor symbol #pending -func (x:+:xr) = x +func (x :+: xr) = x ############################################################################### @@ -748,7 +748,7 @@ func = do #test list comprehension comment placement func = [ (thing, take 10 alts) --TODO: select best ones - | (thing, _got, alts@(_:_)) <- nosuchFooThing + | (thing, _got, alts@(_ : _)) <- nosuchFooThing , gast <- award ] diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs index 2f881a0..317fbe2 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs @@ -78,12 +78,10 @@ layoutPat lpat@(L _ pat) = docWrapNode lpat $ case pat of return $ x1 Seq.<| xR ConPatIn lname (InfixCon left right) -> do -- a :< b -> expr - let nameDoc = lrdrNameToText lname - leftDoc <- colsWrapPat =<< layoutPat left + let nameDoc = lrdrNameToTextAnn lname + leftDoc <- appSep . colsWrapPat =<< layoutPat left rightDoc <- colsWrapPat =<< layoutPat right - middle <- docLit $ if Text.any isAlpha nameDoc - then Text.pack " `" <> nameDoc <> Text.pack "` " - else nameDoc + middle <- appSep . docLit =<< nameDoc return $ Seq.empty Seq.|> leftDoc Seq.|> middle Seq.|> rightDoc ConPatIn lname (RecCon (HsRecFields [] Nothing)) -> do -- Abc{} -> expr -- 2.30.2 From 17eec7471c32c54f1b01928437701433d5d5a665 Mon Sep 17 00:00:00 2001 From: Evan Rutledge Borden Date: Mon, 15 Jan 2018 19:15:51 -0500 Subject: [PATCH 6/6] Remove redundant import. --- src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs index 317fbe2..c04790d 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/Pattern.hs @@ -13,7 +13,6 @@ where import Language.Haskell.Brittany.Internal.Types import Language.Haskell.Brittany.Internal.LayouterBasics -import Data.Char (isAlpha) import RdrName ( RdrName(..) ) import GHC ( Located, runGhc, GenLocated(L), moduleNameString ) import HsSyn -- 2.30.2