snippet 0.1.0.0 → 0.1.0.1
raw patch · 6 files changed
+79/−44 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.lhs +10/−10
- README.md +10/−10
- snippet.cabal +33/−3
- src/Snippet/Lines.hs +1/−1
- src/Snippet/Pretty.hs +25/−12
- src/Snippet/Region.hs +0/−8
README.lhs view
@@ -1,5 +1,13 @@ # Snippet +[](https://codeberg.org/pbrisbin/snippet/releases)+[](https://hackage.haskell.org/package/snippet)+[](http://stackage.org/lts/package/snippet)+[](http://stackage.org/nightly/package/snippet)+[](https://codeberg.org/pbrisbin/snippet/actions?workflows=ci.yml)++Pretty-print regions within source code files.+ ## Usage <!--@@ -24,8 +32,8 @@ main = do let region = Region- { startLine = 24- , endLine = Just 36+ { startLine = 32+ , endLine = Just 44 , startColumn = Just 8 , endColumn = Nothing }@@ -42,14 +50,6 @@  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,5 +1,13 @@ # Snippet +[](https://codeberg.org/pbrisbin/snippet/releases)+[](https://hackage.haskell.org/package/snippet)+[](http://stackage.org/lts/package/snippet)+[](http://stackage.org/nightly/package/snippet)+[](https://codeberg.org/pbrisbin/snippet/actions?workflows=ci.yml)++Pretty-print regions within source code files.+ ## Usage <!--@@ -24,8 +32,8 @@ main = do let region = Region- { startLine = 24- , endLine = Just 36+ { startLine = 32+ , endLine = Just 44 , startColumn = Just 8 , endColumn = Nothing }@@ -42,14 +50,6 @@  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,13 +1,43 @@ cabal-version: 1.18 name: snippet-version: 0.1.0.0+version: 0.1.0.1 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: TODO-description: TODO+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).+ 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,25 +53,38 @@ -- | 'prettySnippet' but fill the left gutter to the given width ----- For example, if 'prettySnippet' gives: --+-- 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:+-- -- @--- |--- 1 | ...--- |+-- >>> vsep [prettySnippet a, prettySnippet b]+-- ┌─ a+-- │+-- 1 │ ...+-- │+-- ┌─ b+-- │+-- 15 │ ...+-- │ -- @ ----- @'prettySnippetFill' 3@ gives: -- -- @--- |--- 1 | ...--- |+-- >>> vsep [prettySnippetFill 2 a, prettySnippetFill 2 b]+-- ┌─+-- │+-- 1 │ ...+-- │+-- ┌─ b+-- │+-- 15 │ ...+-- │ -- @------ 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,14 +25,6 @@ -- ^ 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)