hls-gadt-plugin 2.4.0.0 → 2.5.0.0
raw patch · 2 files changed
+5/−93 lines, 2 filesdep ~ghcidedep ~hls-plugin-apidep ~hls-test-utils
Dependency ranges changed: ghcide, hls-plugin-api, hls-test-utils, lsp
Files
- hls-gadt-plugin.cabal +5/−5
- src/Ide/Plugin/GHC.hs +0/−88
hls-gadt-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: hls-gadt-plugin-version: 2.4.0.0+version: 2.5.0.0 synopsis: Convert to GADT syntax plugin description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server/tree/master/plugins/hls-gadt-plugin#readme>@@ -35,13 +35,13 @@ , containers , extra , ghc- , ghcide == 2.4.0.0+ , ghcide == 2.5.0.0 , ghc-boot-th , ghc-exactprint- , hls-plugin-api == 2.4.0.0+ , hls-plugin-api == 2.5.0.0 , hls-refactor-plugin , lens- , lsp >=2.2.0.0+ , lsp >=2.3 , mtl , text , transformers@@ -68,7 +68,7 @@ , base , filepath , hls-gadt-plugin- , hls-test-utils == 2.4.0.0+ , hls-test-utils == 2.5.0.0 , lens , lsp , lsp-test
src/Ide/Plugin/GHC.hs view
@@ -21,7 +21,6 @@ import Ide.PluginUtils (subRange) import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl) -#if MIN_VERSION_ghc(9,2,1) import GHC.Parser.Annotation (AddEpAnn (..), Anchor (Anchor), AnchorOperation (MovedAnchor),@@ -35,15 +34,6 @@ import GHC.Parser.Annotation (TokenLocation (..)) #endif import Language.Haskell.GHC.ExactPrint (showAst)-#else-import qualified Data.Map.Lazy as Map-import Language.Haskell.GHC.ExactPrint.Types (AnnConName (CN),- AnnKey (AnnKey),- Annotation (..),- DeltaPos (DP),- KeywordId (G),- deltaColumn)-#endif type GP = GhcPass Parsed @@ -104,9 +94,6 @@ [con_name] #endif -#if !MIN_VERSION_ghc(9,2,1)- con_forall-#endif #if MIN_VERSION_ghc(9,5,0) (L NoTokenLoc HsNormalTok) #endif@@ -119,7 +106,6 @@ x -> x where -- Parameters in the data constructor-#if MIN_VERSION_ghc(9,2,1) renderDetails :: HsConDeclH98Details GP -> HsConDeclGADTDetails GP renderDetails (PrefixCon _ args) = PrefixConGADT args renderDetails (InfixCon arg1 arg2) = PrefixConGADT [arg1, arg2]@@ -129,11 +115,6 @@ renderDetails (RecCon recs) = RecConGADT recs #endif -#else- renderDetails (PrefixCon args) = PrefixCon args- renderDetails (InfixCon arg1 arg2) = PrefixCon [arg1, arg2]- renderDetails (RecCon recs) = RecCon recs-#endif -- | Construct GADT result type renderResultTy :: LHsType GP@@ -192,7 +173,6 @@ 3. Make every data constructor start with a new line and 2 spaces -} prettyGADTDecl :: DynFlags -> TyClDecl GP -> Either String String-#if MIN_VERSION_ghc(9,2,1) prettyGADTDecl df decl = let old = printOutputable decl hsDecl = parseDecl df "unused" (T.unpack old)@@ -237,63 +217,7 @@ removeExtraEmptyLine s = case stripInfix "\n\n" s of Just (x, xs) -> x <> "\n" <> xs Nothing -> s-#else-prettyGADTDecl df decl =- let old = printOutputable decl- hsDecl = parseDecl df "unused" (T.unpack old)- tycld = adjustTyClD hsDecl- in removeExtraEmptyLine . uncurry (flip exactPrint) <$> tycld- where- adjustTyClD = \case- Right (anns, t@(L _ (TyClD _ _))) -> Right (adjustDataDeclAnns anns, t)- Right _ -> Left "Expect TyClD"- Left err -> Left $ show err - adjustDataDeclAnns = Map.mapWithKey go- where- isDataDeclAnn (AnnKey _ (CN name)) = name == "DataDecl"- isConDeclGADTAnn (AnnKey _ (CN name)) = name == "ConDeclGADT"-- go key ann- | isDataDeclAnn key = adjustWhere ann- | isConDeclGADTAnn key = adjustCon ann- | otherwise = ann-- -- Adjust where annotation to the same line of the type constructor- adjustWhere Ann{..} = Ann- { annsDP = annsDP <&>- (\(keyword, dp) ->- if keyword == G AnnWhere- then (keyword, DP (0, 1))- else (keyword, dp))- , ..- }-- -- Make every data constructor start with a new line and 2 spaces- --- -- Here we can't force every GADT constructor has (1, 2)- -- delta. For the first constructor with (1, 2), it prints- -- a new line with 2 spaces, but for other constructors- -- with (1, 2), it will print a new line with 4 spaces.- --- -- The original ann parsed with `praseDecl` shows the first- -- constructor has (1, 4) delta, but others have (1, 0).- -- Hence, the following code only deal with the first- -- constructor.- adjustCon Ann{..} = let c = deltaColumn annEntryDelta- in Ann- { annEntryDelta = DP $ (1,) $ if c > 0 then 2 else 0- , ..- }-- -- Remove the first extra line if exist- removeExtraEmptyLine s = case stripInfix "\n\n" s of- Just (x, xs) -> x <> "\n" <> xs- Nothing -> s--#endif--#if MIN_VERSION_ghc(9,2,1) wrap :: forall a. WrapXRec GP a => a -> XRec GP a wrap = wrapXRec @GP wrapCtxt = id@@ -301,20 +225,8 @@ unWrap = unXRec @GP mapX = mapXRec @GP noUsed = EpAnnNotUsed-#else-wrapCtxt = Just-wrap = L noSrcSpan-emptyCtxt = wrap []-unWrap (L _ r) = r-mapX = fmap-noUsed = noExtField-#endif pattern UserTyVar' :: LIdP pass -> HsTyVarBndr flag pass pattern UserTyVar' s <- UserTyVar _ _ s -#if MIN_VERSION_ghc(9,2,1) implicitTyVars = (wrapXRec @GP mkHsOuterImplicit)-#else-implicitTyVars = []-#endif