Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Data.Text qualified in dhall-lsp-server #2636

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dhall-lsp-server/src/Dhall/LSP/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ module Dhall.LSP.Util (
unlines'
) where

import Data.List.NonEmpty
import Data.Text
import Data.List.NonEmpty (NonEmpty (..))
import Data.Text (Text)

import qualified Data.Text as Text

-- | Shorthand for @pack . show@. Useful since we are mostly working with Text
-- rather than String.
tshow :: Show a => a -> Text
tshow = pack . show
tshow = Text.pack . show

-- | A variant of @Data.Text.lines@ that does not swallow the last empty. Always
-- returns at least the empty line!
lines' :: Text -> NonEmpty Text
lines' text =
case split (== '\n') text of
case Text.split (== '\n') text of
[] -> "" :| [] -- this case never occurs!
l : ls -> l :| ls

-- | A variant of @Data.Text.unlines@ that is the exact inverse to @lines'@ (and
-- vice-versa).
unlines' :: [Text] -> Text
unlines' = intercalate "\n"
unlines' = Text.intercalate "\n"

rightToMaybe :: Either a b -> Maybe b
rightToMaybe (Right b) = Just b
Expand Down
Loading