packages feed

hls-class-plugin 2.4.0.0 → 2.5.0.0

raw patch · 2 files changed

+4/−60 lines, 2 filesdep ~ghcidedep ~hls-plugin-apidep ~hls-test-utils

Dependency ranges changed: ghcide, hls-plugin-api, hls-test-utils

Files

hls-class-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hls-class-plugin-version:            2.4.0.0+version:            2.5.0.0 synopsis:   Class/instance management plugin for Haskell Language Server @@ -44,10 +44,10 @@     , deepseq     , extra     , ghc-    , ghcide          == 2.4.0.0+    , ghcide          == 2.5.0.0     , ghc-boot-th     , hls-graph-    , hls-plugin-api  == 2.4.0.0+    , hls-plugin-api  == 2.5.0.0     , lens     , lsp     , mtl@@ -84,7 +84,7 @@     , ghcide     , hls-class-plugin     , hls-plugin-api-    , hls-test-utils     == 2.4.0.0+    , hls-test-utils     == 2.5.0.0     , lens     , lsp-types     , row-types
src/Ide/Plugin/Class/ExactPrint.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE CPP             #-} {-# LANGUAGE GADTs           #-} {-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE ViewPatterns    #-}  module Ide.Plugin.Class.ExactPrint where @@ -13,20 +12,11 @@ import           Language.Haskell.GHC.ExactPrint import           Language.Haskell.GHC.ExactPrint.Parsers -#if MIN_VERSION_ghc(9,2,0) import           Data.Either.Extra                       (eitherToMaybe) import           GHC.Parser.Annotation-#else-import           Control.Monad                           (foldM)-import qualified Data.Map.Strict                         as Map-import           Language.Haskell.GHC.ExactPrint.Types   hiding (GhcPs)-import           Language.Haskell.GHC.ExactPrint.Utils   (rs)-import           Language.LSP.Protocol.Types             (Range)-#endif  makeEditText :: Monad m => ParsedModule -> DynFlags -> AddMinimalMethodsParams -> MaybeT m (T.Text, T.Text) -- addMethodDecls :: ParsedSource -> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> Range -> Bool -> TransformT Identity (Located HsModule)-#if MIN_VERSION_ghc(9,2,0) makeEditText pm df AddMinimalMethodsParams{..} = do     mDecls <- MaybeT . pure $ traverse (makeMethodDecl df) methodGroup     let ps = makeDeltaAst $ pm_parsed_source pm@@ -73,49 +63,3 @@         let dp = deltaPos 1 defaultIndent         in L (noAnnSrcSpanDP (getLoc l) dp <> l) e -#else--makeEditText pm df AddMinimalMethodsParams{..} = do-    (unzip -> (mAnns, mDecls)) <- MaybeT . pure $ traverse (makeMethodDecl df) methodGroup-    let ps = pm_parsed_source pm-        anns = relativiseApiAnns ps (pm_annotations pm)-        old = T.pack $ exactPrint ps anns-        (ps', (anns', _), _) = runTransform (mergeAnns (mergeAnnList mAnns) anns) (addMethodDecls ps mDecls range withSig)-        new = T.pack $ exactPrint ps' anns'-    pure (old, new)--makeMethodDecl :: DynFlags -> (T.Text, T.Text) -> Maybe (Anns, (LHsDecl GhcPs, LHsDecl GhcPs))-makeMethodDecl df (mName, sig) = do-    (nameAnn, name) <- case parseDecl df (T.unpack mName) . T.unpack $ toMethodName mName <> " = _" of-        Right (ann, d) -> Just (setPrecedingLines d 1 defaultIndent ann, d)-        Left _         -> Nothing-    (sigAnn, sig) <- case parseDecl df (T.unpack sig) $ T.unpack sig of-        Right (ann, d) -> Just (setPrecedingLines d 1 defaultIndent ann, d)-        Left _         -> Nothing-    pure (mergeAnnList [nameAnn, sigAnn], (name, sig))--addMethodDecls ps mDecls range withSig = do-    d <- findInstDecl ps range-    newSpan <- uniqueSrcSpanT-    let decls = if withSig then concatMap (\(decl, sig) -> [sig, decl]) mDecls else map fst mDecls-        annKey = mkAnnKey d-        newAnnKey = AnnKey (rs newSpan) (CN "HsValBinds")-        addWhere mkds@(Map.lookup annKey -> Just ann) = Map.insert newAnnKey ann2 mkds2-            where-                ann1 = ann-                        { annsDP = annsDP ann ++ [(G AnnWhere, DP (0, 1))]-                        , annCapturedSpan = Just newAnnKey-                        , annSortKey = Just (fmap (rs . getLoc) decls)-                        }-                mkds2 = Map.insert annKey ann1 mkds-                ann2 = annNone-                        { annEntryDelta = DP (1, defaultIndent)-                        }-        addWhere _ = panic "Ide.Plugin.Class.addMethodPlaceholder"-    modifyAnnsT addWhere-    modifyAnnsT (captureOrderAnnKey newAnnKey decls)-    foldM (insertAfter d) ps (reverse decls)--findInstDecl :: ParsedSource -> Range -> Transform (LHsDecl GhcPs)-findInstDecl ps range = head . filter (inRange range . getLoc) <$> hsDecls ps-#endif