-
-
Notifications
You must be signed in to change notification settings - Fork 389
Add pre-commit hook for cleaning up mixed-line endings #2679
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
Changes from 10 commits
2d7d74b
6b75252
7b9670f
e33e9de
8066fbe
d4a8296
f1a971a
fd63c56
16e9c67
aa379b9
5648ad8
fe3708a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"repos": [ | ||
{ | ||
"hooks": [ | ||
{ | ||
"entry": "stylish-haskell --inplace", | ||
"exclude": "(^Setup.hs$|test/testdata/.*$|test/data/.*$|test/manual/lhs/.*$|^hie-compat/.*$|^plugins/hls-tactics-plugin/.*$|^ghcide/src/Development/IDE/GHC/Compat.hs$|^ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs$|^ghcide/src/Development/IDE/GHC/Compat/Core.hs$|^ghcide/src/Development/IDE/Spans/Pragmas.hs$|^ghcide/src/Development/IDE/LSP/Outline.hs$|^plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs$|^ghcide/test/exe/Main.hs$|ghcide/src/Development/IDE/Core/Rules.hs|^hls-test-utils/src/Test/Hls/Util.hs$)", | ||
"files": "\\.l?hs$", | ||
"id": "stylish-haskell", | ||
"language": "system", | ||
"name": "stylish-haskell", | ||
"pass_filenames": true, | ||
"types": [ | ||
"file" | ||
] | ||
} | ||
], | ||
"repo": "local" | ||
}, | ||
{ | ||
"repo": "https://github.com/pre-commit/pre-commit-hooks", | ||
"rev": "v4.1.0", | ||
"hooks": [ | ||
{ | ||
"id": "mixed-line-ending", | ||
"args": ["--fix", "lf"], | ||
"exclude": "test/testdata/.*CRLF*.hs$" | ||
} | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ steps: | |
|
||
columns: 80 | ||
|
||
newline: native | ||
newline: lf | ||
|
||
language_extensions: | ||
- BangPatterns | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,17 @@ If you don't want to use [nix](https://nixos.org/guides/install-nix.html), you c | |
} | ||
], | ||
"repo": "local" | ||
}, | ||
{ | ||
"repo": "https://github.com/pre-commit/pre-commit-hooks", | ||
"rev": "v4.1.0", | ||
"hooks": [ | ||
{ | ||
"id": "mixed-line-ending", | ||
"args": ["--fix", "lf"], | ||
"exclude": "test/testdata/.*CRLF*.hs$" | ||
} | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do that as well! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although, the pre-commit hook is part of |
||
} | ||
] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,162 +1,162 @@ | ||
{-# LANGUAGE DerivingVia #-} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. omg all those files had incorrect line endings???? 🤦 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, as described in the issue: #2678 |
||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
module Development.IDE.Core.UseStale | ||
( Age(..) | ||
, Tracked | ||
, unTrack | ||
, PositionMap | ||
, TrackedStale (..) | ||
, untrackedStaleValue | ||
, unsafeMkStale | ||
, unsafeMkCurrent | ||
, unsafeCopyAge | ||
, MapAge (..) | ||
, dualPositionMap | ||
, useWithStale | ||
, useWithStale_ | ||
) where | ||
import Control.Arrow | ||
import Control.Category (Category) | ||
import qualified Control.Category as C | ||
import Control.DeepSeq (NFData) | ||
import Data.Aeson | ||
import Data.Coerce (coerce) | ||
import Data.Functor ((<&>)) | ||
import Data.Functor.Identity (Identity (Identity)) | ||
import Data.Kind (Type) | ||
import Data.String (fromString) | ||
import Development.IDE (Action, IdeRule, | ||
NormalizedFilePath, | ||
Range, | ||
rangeToRealSrcSpan, | ||
realSrcSpanToRange) | ||
import qualified Development.IDE.Core.PositionMapping as P | ||
import qualified Development.IDE.Core.Shake as IDE | ||
import Development.IDE.GHC.Compat (RealSrcSpan, srcSpanFile) | ||
import Development.IDE.GHC.Compat.Util (unpackFS) | ||
------------------------------------------------------------------------------ | ||
-- | A data kind for 'Tracked'. | ||
data Age = Current | Stale Type | ||
------------------------------------------------------------------------------ | ||
-- | Some value, tagged with its age. All 'Current' ages are considered to be | ||
-- the same thing, but 'Stale' values are protected by an untouchable variable | ||
-- to ensure they can't be unified. | ||
newtype Tracked (age :: Age) a = UnsafeTracked | ||
{ unTrack :: a | ||
} | ||
deriving stock (Functor, Foldable, Traversable) | ||
deriving newtype (Eq, Ord, Show, Read, ToJSON, FromJSON, NFData) | ||
deriving (Applicative, Monad) via Identity | ||
------------------------------------------------------------------------------ | ||
-- | Like 'P.PositionMapping', but with annotated ages for how 'Tracked' values | ||
-- change. Use the 'Category' instance to compose 'PositionMapping's in order | ||
-- to transform between values of different stale ages. | ||
newtype PositionMap (from :: Age) (to :: Age) = PositionMap | ||
{ _getPositionMapping :: P.PositionMapping | ||
} | ||
instance Category PositionMap where | ||
id = coerce P.zeroMapping | ||
(.) = coerce P.composeDelta | ||
------------------------------------------------------------------------------ | ||
-- | Get a 'PositionMap' that runs in the opposite direction. | ||
dualPositionMap :: PositionMap from to -> PositionMap to from | ||
dualPositionMap (PositionMap (P.PositionMapping (P.PositionDelta from to))) = | ||
PositionMap $ P.PositionMapping $ P.PositionDelta to from | ||
------------------------------------------------------------------------------ | ||
-- | A pair containing a @'Tracked' 'Stale'@ value, as well as | ||
-- a 'PositionMapping' that will fast-forward values to the current age. | ||
data TrackedStale a where | ||
TrackedStale | ||
:: Tracked (Stale s) a | ||
-> PositionMap (Stale s) Current | ||
-> TrackedStale a | ||
instance Functor TrackedStale where | ||
fmap f (TrackedStale t pm) = TrackedStale (fmap f t) pm | ||
untrackedStaleValue :: TrackedStale a -> a | ||
untrackedStaleValue (TrackedStale ta _) = coerce ta | ||
------------------------------------------------------------------------------ | ||
-- | A class for which 'Tracked' values can be run across a 'PositionMapping' | ||
-- to change their ages. | ||
class MapAge a where | ||
{-# MINIMAL mapAgeFrom | mapAgeTo #-} | ||
mapAgeFrom :: PositionMap from to -> Tracked to a -> Maybe (Tracked from a) | ||
mapAgeFrom = mapAgeTo . dualPositionMap | ||
mapAgeTo :: PositionMap from to -> Tracked from a -> Maybe (Tracked to a) | ||
mapAgeTo = mapAgeFrom . dualPositionMap | ||
instance MapAge Range where | ||
mapAgeFrom = coerce P.fromCurrentRange | ||
mapAgeTo = coerce P.toCurrentRange | ||
instance MapAge RealSrcSpan where | ||
mapAgeFrom = | ||
invMapAge (\fs -> rangeToRealSrcSpan (fromString $ unpackFS fs)) | ||
(srcSpanFile &&& realSrcSpanToRange) | ||
. mapAgeFrom | ||
------------------------------------------------------------------------------ | ||
-- | Helper function for deriving 'MapAge' for values in terms of other | ||
-- instances. | ||
invMapAge | ||
:: (c -> a -> b) | ||
-> (b -> (c, a)) | ||
-> (Tracked from a -> Maybe (Tracked to a)) | ||
-> Tracked from b | ||
-> Maybe (Tracked to b) | ||
invMapAge to from f t = | ||
let (c, t') = unTrack $ fmap from t | ||
in fmap (fmap $ to c) $ f $ UnsafeTracked t' | ||
unsafeMkCurrent :: age -> Tracked 'Current age | ||
unsafeMkCurrent = coerce | ||
unsafeMkStale :: age -> Tracked (Stale s) age | ||
unsafeMkStale = coerce | ||
unsafeCopyAge :: Tracked age a -> b -> Tracked age b | ||
unsafeCopyAge _ = coerce | ||
-- | Request a Rule result, it not available return the last computed result, if any, which may be stale | ||
useWithStale :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (Maybe (TrackedStale v)) | ||
useWithStale key file = do | ||
x <- IDE.useWithStale key file | ||
pure $ x <&> \(v, pm) -> | ||
TrackedStale (coerce v) (coerce pm) | ||
-- | Request a Rule result, it not available return the last computed result which may be stale. | ||
-- Errors out if none available. | ||
useWithStale_ :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (TrackedStale v) | ||
useWithStale_ key file = do | ||
(v, pm) <- IDE.useWithStale_ key file | ||
pure $ TrackedStale (coerce v) (coerce pm) | ||
{-# LANGUAGE DerivingVia #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
|
||
module Development.IDE.Core.UseStale | ||
( Age(..) | ||
, Tracked | ||
, unTrack | ||
, PositionMap | ||
, TrackedStale (..) | ||
, untrackedStaleValue | ||
, unsafeMkStale | ||
, unsafeMkCurrent | ||
, unsafeCopyAge | ||
, MapAge (..) | ||
, dualPositionMap | ||
, useWithStale | ||
, useWithStale_ | ||
) where | ||
|
||
import Control.Arrow | ||
import Control.Category (Category) | ||
import qualified Control.Category as C | ||
import Control.DeepSeq (NFData) | ||
import Data.Aeson | ||
import Data.Coerce (coerce) | ||
import Data.Functor ((<&>)) | ||
import Data.Functor.Identity (Identity (Identity)) | ||
import Data.Kind (Type) | ||
import Data.String (fromString) | ||
import Development.IDE (Action, IdeRule, | ||
NormalizedFilePath, | ||
Range, | ||
rangeToRealSrcSpan, | ||
realSrcSpanToRange) | ||
import qualified Development.IDE.Core.PositionMapping as P | ||
import qualified Development.IDE.Core.Shake as IDE | ||
import Development.IDE.GHC.Compat (RealSrcSpan, srcSpanFile) | ||
import Development.IDE.GHC.Compat.Util (unpackFS) | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | A data kind for 'Tracked'. | ||
data Age = Current | Stale Type | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Some value, tagged with its age. All 'Current' ages are considered to be | ||
-- the same thing, but 'Stale' values are protected by an untouchable variable | ||
-- to ensure they can't be unified. | ||
newtype Tracked (age :: Age) a = UnsafeTracked | ||
{ unTrack :: a | ||
} | ||
deriving stock (Functor, Foldable, Traversable) | ||
deriving newtype (Eq, Ord, Show, Read, ToJSON, FromJSON, NFData) | ||
deriving (Applicative, Monad) via Identity | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Like 'P.PositionMapping', but with annotated ages for how 'Tracked' values | ||
-- change. Use the 'Category' instance to compose 'PositionMapping's in order | ||
-- to transform between values of different stale ages. | ||
newtype PositionMap (from :: Age) (to :: Age) = PositionMap | ||
{ _getPositionMapping :: P.PositionMapping | ||
} | ||
|
||
instance Category PositionMap where | ||
id = coerce P.zeroMapping | ||
(.) = coerce P.composeDelta | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Get a 'PositionMap' that runs in the opposite direction. | ||
dualPositionMap :: PositionMap from to -> PositionMap to from | ||
dualPositionMap (PositionMap (P.PositionMapping (P.PositionDelta from to))) = | ||
PositionMap $ P.PositionMapping $ P.PositionDelta to from | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | A pair containing a @'Tracked' 'Stale'@ value, as well as | ||
-- a 'PositionMapping' that will fast-forward values to the current age. | ||
data TrackedStale a where | ||
TrackedStale | ||
:: Tracked (Stale s) a | ||
-> PositionMap (Stale s) Current | ||
-> TrackedStale a | ||
|
||
instance Functor TrackedStale where | ||
fmap f (TrackedStale t pm) = TrackedStale (fmap f t) pm | ||
|
||
|
||
untrackedStaleValue :: TrackedStale a -> a | ||
untrackedStaleValue (TrackedStale ta _) = coerce ta | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | A class for which 'Tracked' values can be run across a 'PositionMapping' | ||
-- to change their ages. | ||
class MapAge a where | ||
{-# MINIMAL mapAgeFrom | mapAgeTo #-} | ||
mapAgeFrom :: PositionMap from to -> Tracked to a -> Maybe (Tracked from a) | ||
mapAgeFrom = mapAgeTo . dualPositionMap | ||
|
||
mapAgeTo :: PositionMap from to -> Tracked from a -> Maybe (Tracked to a) | ||
mapAgeTo = mapAgeFrom . dualPositionMap | ||
|
||
|
||
instance MapAge Range where | ||
mapAgeFrom = coerce P.fromCurrentRange | ||
mapAgeTo = coerce P.toCurrentRange | ||
|
||
|
||
instance MapAge RealSrcSpan where | ||
mapAgeFrom = | ||
invMapAge (\fs -> rangeToRealSrcSpan (fromString $ unpackFS fs)) | ||
(srcSpanFile &&& realSrcSpanToRange) | ||
. mapAgeFrom | ||
|
||
|
||
------------------------------------------------------------------------------ | ||
-- | Helper function for deriving 'MapAge' for values in terms of other | ||
-- instances. | ||
invMapAge | ||
:: (c -> a -> b) | ||
-> (b -> (c, a)) | ||
-> (Tracked from a -> Maybe (Tracked to a)) | ||
-> Tracked from b | ||
-> Maybe (Tracked to b) | ||
invMapAge to from f t = | ||
let (c, t') = unTrack $ fmap from t | ||
in fmap (fmap $ to c) $ f $ UnsafeTracked t' | ||
|
||
|
||
unsafeMkCurrent :: age -> Tracked 'Current age | ||
unsafeMkCurrent = coerce | ||
|
||
|
||
unsafeMkStale :: age -> Tracked (Stale s) age | ||
unsafeMkStale = coerce | ||
|
||
|
||
unsafeCopyAge :: Tracked age a -> b -> Tracked age b | ||
unsafeCopyAge _ = coerce | ||
|
||
|
||
-- | Request a Rule result, it not available return the last computed result, if any, which may be stale | ||
useWithStale :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (Maybe (TrackedStale v)) | ||
useWithStale key file = do | ||
x <- IDE.useWithStale key file | ||
pure $ x <&> \(v, pm) -> | ||
TrackedStale (coerce v) (coerce pm) | ||
|
||
-- | Request a Rule result, it not available return the last computed result which may be stale. | ||
-- Errors out if none available. | ||
useWithStale_ :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (TrackedStale v) | ||
useWithStale_ key file = do | ||
(v, pm) <- IDE.useWithStale_ key file | ||
pure $ TrackedStale (coerce v) (coerce pm) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to put the config into nix setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't use nix so I have no idea, any help would be appreciative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix doesn't support windows so I suppose it is not necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, makes sense.