packages feed

snippet 0.0.0.0 → 0.1.0.0

raw patch · 6 files changed

+44/−79 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.lhs view
@@ -1,13 +1,5 @@ # Snippet -[![Release](https://codeberg.org/pbrisbin/snippet/badges/release.svg)](https://codeberg.org/pbrisbin/snippet/releases)-[![Hackage](https://img.shields.io/hackage/v/snippet.svg?style=flat)](https://hackage.haskell.org/package/snippet)-[![Stackage LTS](http://stackage.org/package/snippet/badge/lts)](http://stackage.org/lts/package/snippet)-[![Stackage Nightly](http://stackage.org/package/snippet/badge/nightly)](http://stackage.org/nightly/package/snippet)-[![CI](https://codeberg.org/pbrisbin/snippet/badges/workflows/ci.yml/badge.svg)](https://codeberg.org/pbrisbin/snippet/actions?workflows=ci.yml)--Pretty-print regions within source code files.- ## Usage  <!--@@ -32,8 +24,8 @@ main = do   let     region = Region-      { startLine = 32-      , endLine = Just 44+      { startLine = 24+      , endLine = Just 36       , startColumn = Just 8       , endColumn = Nothing       }@@ -50,6 +42,14 @@ ![](./example.png)  Supplying an alternative `annToAnsi` function is how you can adjust colors.++> [!NOTE]+>+> The simple `putDoc` function is fine for this toy example because the lines+> are narrow enough not to break. In real usage, you should implement your own+> layout using an [`Unbounded` `PageWidth`][unbounded].++[unbounded]: https://hackage-content.haskell.org/package/prettyprinter-1.7.2/docs/Prettyprinter.html#t:PageWidth  ## License 
README.md view
@@ -1,13 +1,5 @@ # Snippet -[![Release](https://codeberg.org/pbrisbin/snippet/badges/release.svg)](https://codeberg.org/pbrisbin/snippet/releases)-[![Hackage](https://img.shields.io/hackage/v/snippet.svg?style=flat)](https://hackage.haskell.org/package/snippet)-[![Stackage LTS](http://stackage.org/package/snippet/badge/lts)](http://stackage.org/lts/package/snippet)-[![Stackage Nightly](http://stackage.org/package/snippet/badge/nightly)](http://stackage.org/nightly/package/snippet)-[![CI](https://codeberg.org/pbrisbin/snippet/badges/workflows/ci.yml/badge.svg)](https://codeberg.org/pbrisbin/snippet/actions?workflows=ci.yml)--Pretty-print regions within source code files.- ## Usage  <!--@@ -32,8 +24,8 @@ main = do   let     region = Region-      { startLine = 32-      , endLine = Just 44+      { startLine = 24+      , endLine = Just 36       , startColumn = Just 8       , endColumn = Nothing       }@@ -50,6 +42,14 @@ ![](./example.png)  Supplying an alternative `annToAnsi` function is how you can adjust colors.++> [!NOTE]+>+> The simple `putDoc` function is fine for this toy example because the lines+> are narrow enough not to break. In real usage, you should implement your own+> layout using an [`Unbounded` `PageWidth`][unbounded].++[unbounded]: https://hackage-content.haskell.org/package/prettyprinter-1.7.2/docs/Prettyprinter.html#t:PageWidth  ## License 
snippet.cabal view
@@ -1,43 +1,13 @@ cabal-version:   1.18 name:            snippet-version:         0.0.0.0+version:         0.1.0.0 license:         AGPL-3 license-file:    COPYING maintainer:      Patrick Brisbin homepage:        https://codeberg.org/pbrisbin/sarif-tools#readme bug-reports:     https://codeberg.org/pbrisbin/sarif-tools/issues-synopsis:        Pretty-print regions within source code files-description:-    Pretty-print @Region@s of source-code, i.e. snippets.-    .-    This is meant to mimic tooling available in rust and used by tools such as-    @sarif-fmt@.-    .-    For example, focusing on a region within our README:-    .-    @-    \   ┌─ README.md:32:8-    \   │-    \32 │   main = do-    \   │ ╭────────^-    \33 │ │   let-    \34 │ │     region = Region-    \35 │ │       { startLine = 32-    \36 │ │       , endLine = Just 44-    \37 │ │       , startColumn = Just 8-    \38 │ │       , endColumn = Nothing-    \39 │ │       }-    \40 │ │-    \41 │ │   -- Returns Nothing if file is missing/empty or region is invalid-    \42 │ │   mSnippet <- snippetFromFile region "README.md"-    \43 │ │-    \44 │ │   traverse_ (putDoc . reAnnotate annToAnsi . prettySnippet) mSnippet-    \   │ ╰────────────────────────────────────────────────────────────────────^-    @-    .-    To see the code that produces this, and an image of the output (e.g. with-    color), view the [README on Codeberg](https://codeberg.org/pbrisbin/snippet#readme).-+synopsis:        TODO+description:     TODO category:        Data build-type:      Simple extra-doc-files:
src/Snippet/Lines.hs view
@@ -30,7 +30,7 @@ -- | Make 'Line's for the one-line case: -- -- @--- 85 │       , ((annotate AnnIcon "=" \<+\>) . pretty) \<$\> r.fullDescription+-- 85 │       , ((annotate AnnIcon "=" <+>) . pretty) <$> r.fullDescription --    │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- @ makeLines1 :: Region -> NonEmpty Text -> NonEmpty Line
src/Snippet/Pretty.hs view
@@ -53,38 +53,25 @@  -- | 'prettySnippet' but fill the left gutter to the given width -------- This is useful if multiple snippets are being rendered together and their--- line-numbers are different numbers of digits. You can compute the maximum--- width on the outside (see 'snippetGutterWidth') and pass it so they all--- align.------ For example:+-- For example, if 'prettySnippet' gives: -- -- @--- >>> vsep [prettySnippet a, prettySnippet b]---   ┌─ a---   │--- 1 │ ...---   │---    ┌─ b---    │--- 15 │ ...---    │+--   |+-- 1 | ...+--   | -- @ --+-- @'prettySnippetFill' 3@ gives: -- -- @--- >>> vsep [prettySnippetFill 2 a, prettySnippetFill 2 b]---    ┌─---    │--- 1  │ ...---    │---    ┌─ b---    │--- 15 │ ...---    │+--     |+--   1 | ...+--     | -- @+--+-- This is useful if multiple snippets are being rendered together and their+-- line-numbers are different magnitudes. You can compute the width on the+-- outside and pass it in. prettySnippetFill :: Int -> Snippet -> Doc Ann prettySnippetFill w snippet =   vsep
src/Snippet/Region.hs view
@@ -25,6 +25,14 @@   -- ^ Defaults to @1@ if missing   , endColumn :: Maybe Int   -- ^ If missing, the entire last line is considered focused+  --+  -- This follows section 3.30.8 @endColumn@ property of sarif-v2.0+  -- specification, because it's just reasonable behavior:+  --+  -- @+  -- If endColumn is absent, it SHALL default to a value one greater than the+  -- column number of the last character on the line+  -- @   }   deriving stock (Eq, Show)