packages feed

snippet 0.2.0.0 → 0.2.0.1

raw patch · 8 files changed

+176/−26 lines, 8 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Snippet.Pretty: snippetInsetWidth :: Snippet -> Int

Files

snippet.cabal view
@@ -1,6 +1,6 @@ cabal-version:      1.18 name:               snippet-version:            0.2.0.0+version:            0.2.0.1 license:            AGPL-3 license-file:       COPYING maintainer:         Patrick Brisbin@@ -41,7 +41,9 @@ category:           Data build-type:         Simple extra-source-files:+    test-cases/nested/readme-2.yaml     test-cases/nested/readme.yaml+    test-cases/simple/hlint.yaml     test-cases/simple/multi-line.yaml     test-cases/simple/one-line.yaml 
src/Snippet/Line.hs view
@@ -130,7 +130,7 @@       if T.null $ T.strip pre         then do           let-            marker = "╭─" <> T.replicate (i + sc - 2) "─"+            marker = "╭" <> T.replicate (i + sc - 1) "─"             doc =               focus (marker <> " " <> marked <> post)                 <> regionMessage (i + ec + 2) region
src/Snippet/Pretty.hs view
@@ -12,13 +12,11 @@   , prettySnippet   , prettySnippetFill   , snippetGutterWidth-  , snippetInsetWidth   ) where  import Prelude  import Data.Maybe (fromMaybe)-import Data.Text qualified as T import Prettyprinter hiding (line) import Snippet.Line import Snippet.Pretty.Ann@@ -33,19 +31,6 @@   sl = snippet.region.startLine   el = fromMaybe sl snippet.region.endLine --- | A 'Snippet's inset matches how far the code is indented to support region--- marking.-snippetInsetWidth :: Snippet -> Int-snippetInsetWidth = regionInsetWidth . (.region)--regionInsetWidth :: Region -> Int-regionInsetWidth region =-  go region + maybe 0 go region.subRegion- where-  go r-    | maybe True (== r.startLine) r.endLine = 0-    | otherwise = 2- prettySnippet :: Snippet -> Doc Ann prettySnippet snippet = prettySnippetFill w snippet  where@@ -92,9 +77,7 @@ prettySnippetFill w snippet =   vsep     [ indent w-        $ annotate-          AnnDecoration-          (pretty $ "┌" <> T.replicate (snippetInsetWidth snippet) "─")+        $ annotate AnnDecoration "┌─"           <+> pretty (snippet.uri)           <> ":"           <> pretty snippet.region.startLine
+ test-cases/nested/readme-2.yaml view
@@ -0,0 +1,134 @@+expected:+  ansi: |2-+       {b}┌─{x} test-cases/nested/readme-2.yaml:32:1+       {b}│{x}+    {b}32 │{x} {g}╭── main = do{x}+    {b}33 │{x} {g}│ {x}{g}    let{x}+    {b}34 │{x} {g}│ {x}{r}╭──── region = Region{x}+    {b}35 │{x} {g}│ {x}{r}│ {x}{r}      { startLine = 32{x}+    {b}36 │{x} {g}│ {x}{r}│ {x}{r}      , startColumn = Just 1{x}+    {b}37 │{x} {g}│ {x}{r}│ {x}{r}      , endLine = Just 64{x}+    {b}38 │{x} {g}│ {x}{r}│ {x}{r}      , endColumn = Nothing{x}+    {b}39 │{x} {g}│ {x}{r}│ {x}{r}      , message = Nothing{x}+    {b}40 │{x} {g}│ {x}{r}│ {x}{r}      , subRegion ={x}+    {b}41 │{x} {g}│ {x}{r}│ {x}{r}          Just{x}+    {b}42 │{x} {g}│ {x}{r}│ {x}{r}            Region{x}+    {b}43 │{x} {g}│ {x}{r}│ {x}{r}              { startLine = 34{x}+    {b}44 │{x} {g}│ {x}{r}│ {x}{r}              , startColumn = Just 5{x}+    {b}45 │{x} {g}│ {x}{r}│ {x}{r}              , endLine = {x}{c}Just{x}{r} 59{x}+    {b}   │{x} {g}│ {x}{r}│ {x}                          {c}^^^^{x}+    {b}46 │{x} {g}│ {x}{r}│ {x}{r}              , endColumn = Nothing{x}+    {b}47 │{x} {g}│ {x}{r}│ {x}{r}              , message = Just "Denotes a region in the snippet"{x}+    {b}48 │{x} {g}│ {x}{r}│ {x}{r}              , subRegion ={x}+    {b}49 │{x} {g}│ {x}{r}│ {x}{r}                  Just{x}+    {b}50 │{x} {g}│ {x}{r}│ {x}{r}                    Region{x}+    {b}51 │{x} {g}│ {x}{r}│ {x}{r}                      { startLine = 45{x}+    {b}52 │{x} {g}│ {x}{r}│ {x}{r}                      , startColumn = Just 27{x}+    {b}53 │{x} {g}│ {x}{r}│ {x}{r}                      , endLine = Nothing{x}+    {b}54 │{x} {g}│ {x}{r}│ {x}{r}                      , endColumn = Just 31{x}+    {b}55 │{x} {g}│ {x}{r}│ {x}{r}                      , message = Just "Would default to startLine"{x}+    {b}56 │{x} {g}│ {x}{r}│ {x}{r}                      , subRegion = Nothing{x}+    {b}57 │{x} {g}│ {x}{r}│ {x}{r}                      }{x}+    {b}58 │{x} {g}│ {x}{r}│ {x}{r}              }{x}+    {b}59 │{x} {g}│ {x}{r}│ {x}{r}      }{x}+    {b}   │{x} {g}│ {x}{r}╰───────^{x}+    {b}60 │{x} {g}│{x}+    {b}61 │{x} {g}│ {x}{g}    -- Returns Nothing if file is missing/empty or region is invalid{x}+    {b}62 │{x} {g}│ {x}{g}    mSnippet <- snippetFromFile region "README.md"{x}+    {b}63 │{x} {g}│{x}+    {b}64 │{x} {g}│ {x}{g}    traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet{x}+    {b}   │{x} {g}╰──────────────────────────────────────────────────────────────────────^{x}+  text: |2-+       ┌─ test-cases/nested/readme-2.yaml:32:1+       │+    32 │ ╭── main = do+    33 │ │     let+    34 │ │ ╭──── region = Region+    35 │ │ │       { startLine = 32+    36 │ │ │       , startColumn = Just 1+    37 │ │ │       , endLine = Just 64+    38 │ │ │       , endColumn = Nothing+    39 │ │ │       , message = Nothing+    40 │ │ │       , subRegion =+    41 │ │ │           Just+    42 │ │ │             Region+    43 │ │ │               { startLine = 34+    44 │ │ │               , startColumn = Just 5+    45 │ │ │               , endLine = Just 59+       │ │ │                           ^^^^+    46 │ │ │               , endColumn = Nothing+    47 │ │ │               , message = Just "Denotes a region in the snippet"+    48 │ │ │               , subRegion =+    49 │ │ │                   Just+    50 │ │ │                     Region+    51 │ │ │                       { startLine = 45+    52 │ │ │                       , startColumn = Just 27+    53 │ │ │                       , endLine = Nothing+    54 │ │ │                       , endColumn = Just 31+    55 │ │ │                       , message = Just "Would default to startLine"+    56 │ │ │                       , subRegion = Nothing+    57 │ │ │                       }+    58 │ │ │               }+    59 │ │ │       }+       │ │ ╰───────^+    60 │ │+    61 │ │     -- Returns Nothing if file is missing/empty or region is invalid+    62 │ │     mSnippet <- snippetFromFile region "README.md"+    63 │ │+    64 │ │     traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet+       │ ╰──────────────────────────────────────────────────────────────────────^+input:+  region:+    endColumn: null+    endLine: 64+    message: null+    startColumn: 1+    startLine: 32+    subRegion:+      endColumn: null+      endLine: 59+      message: null+      startColumn: 5+      startLine: 34+      subRegion:+        endColumn: 31+        endLine: null+        message: null+        startColumn: 27+        startLine: 45+        subRegion: null+  source: |+    main = do+      let+        region = Region+          { startLine = 32+          , startColumn = Just 1+          , endLine = Just 64+          , endColumn = Nothing+          , message = Nothing+          , subRegion =+              Just+                Region+                  { startLine = 34+                  , startColumn = Just 5+                  , endLine = Just 59+                  , endColumn = Nothing+                  , message = Just "Denotes a region in the snippet"+                  , subRegion =+                      Just+                        Region+                          { startLine = 45+                          , startColumn = Just 27+                          , endLine = Nothing+                          , endColumn = Just 31+                          , message = Just "Would default to startLine"+                          , subRegion = Nothing+                          }+                  }+          }++      -- Returns Nothing if file is missing/empty or region is invalid+      mSnippet <- snippetFromFile region "README.md"++      traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet+  sourceStartLine: null
test-cases/nested/readme.yaml view
@@ -1,6 +1,6 @@ expected:   ansi: |2--       {b}┌────{x} test-cases/nested/readme.yaml:32:8+       {b}┌─{x} test-cases/nested/readme.yaml:32:8        {b}│{x}     {b}32 │{x}     main = {g}do{x}     {b}   │{x} {g}╭──────────^{x}@@ -40,7 +40,7 @@     {b}64 │{x} {g}│ {x}{g}    traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet{x}     {b}   │{x} {g}╰──────────────────────────────────────────────────────────────────────^{x}   text: |2--       ┌──── test-cases/nested/readme.yaml:32:8+       ┌─ test-cases/nested/readme.yaml:32:8        │     32 │     main = do        │ ╭──────────^
+ test-cases/simple/hlint.yaml view
@@ -0,0 +1,31 @@+expected:+  ansi: |2-+       {b}┌─{x} test-cases/simple/hlint.yaml:15:1+       {b}│{x}+    {b}15 │{x} {g}╭ data ArtifactLocation = ArtifactLocation{x}+    {b}16 │{x} {g}│ {x}{g}  { uri :: Text{x}+    {b}17 │{x} {g}│ {x}{g}  }{x}+    {b}18 │{x} {g}│ {x}{g}  deriving stock (Eq){x}+    {b}   │{x} {g}╰─────────────────────^{x}+  text: |2-+       ┌─ test-cases/simple/hlint.yaml:15:1+       │+    15 │ ╭ data ArtifactLocation = ArtifactLocation+    16 │ │   { uri :: Text+    17 │ │   }+    18 │ │   deriving stock (Eq)+       │ ╰─────────────────────^+input:+  region:+    endColumn: 22+    endLine: 18+    message: null+    startColumn: 1+    startLine: 15+    subRegion: null+  source: |+    data ArtifactLocation = ArtifactLocation+      { uri :: Text+      }+      deriving stock (Eq)+  sourceStartLine: 15
test-cases/simple/multi-line.yaml view
@@ -1,6 +1,6 @@ expected:   ansi: |2--      {b}┌──{x} test-cases/simple/multi-line.yaml:2:8+      {b}┌─{x} test-cases/simple/multi-line.yaml:2:8       {b}│{x}     {b}1 │{x}   main :: IO ()     {b}2 │{x}   main = {g}do{x}@@ -10,7 +10,7 @@     {b}5 │{x} {g}│ {x}{g}  putStrLn "That other things"{x}     {b}  │{x} {g}╰──────────────────────────────^{x}   text: |2--      ┌── test-cases/simple/multi-line.yaml:2:8+      ┌─ test-cases/simple/multi-line.yaml:2:8       │     1 │   main :: IO ()     2 │   main = do
test-cases/simple/one-line.yaml view
@@ -1,12 +1,12 @@ expected:   ansi: |2--      {b}┌{x} test-cases/simple/one-line.yaml:1:37+      {b}┌─{x} test-cases/simple/one-line.yaml:1:37       {b}│{x}     {b}1 │{x} Here is some source code that has a {g}few{x} lines and I'm trying to target the     {b}  │{x}                                     {g}^^^{x}     {b}2 │{x} word few in the first line   text: |2--      ┌ test-cases/simple/one-line.yaml:1:37+      ┌─ test-cases/simple/one-line.yaml:1:37       │     1 │ Here is some source code that has a few lines and I'm trying to target the       │                                     ^^^