hls-refine-imports-plugin 1.0.1.0 → 1.0.2.0
raw patch · 3 files changed
+22/−13 lines, 3 filesdep ~ghcidedep ~hls-explicit-imports-plugindep ~hls-plugin-apinew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghcide, hls-explicit-imports-plugin, hls-plugin-api
API changes (from Hackage documentation)
+ Ide.Plugin.RefineImports: LogShake :: Log -> Log
+ Ide.Plugin.RefineImports: instance GHC.Show.Show Ide.Plugin.RefineImports.Log
+ Ide.Plugin.RefineImports: instance Prettyprinter.Internal.Pretty Ide.Plugin.RefineImports.Log
+ Ide.Plugin.RefineImports: newtype Log
- Ide.Plugin.RefineImports: descriptor :: PluginId -> PluginDescriptor IdeState
+ Ide.Plugin.RefineImports: descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
Files
- hls-refine-imports-plugin.cabal +4/−4
- src/Ide/Plugin/RefineImports.hs +17/−8
- test/Main.hs +1/−1
hls-refine-imports-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: hls-refine-imports-plugin-version: 1.0.1.0+version: 1.0.2.0 synopsis: Refine imports plugin for Haskell Language Server description: Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -24,10 +24,10 @@ , containers , deepseq , ghc- , ghcide ^>=1.6- , hls-explicit-imports-plugin ^>=1.0.0.1+ , ghcide ^>=1.7+ , hls-explicit-imports-plugin ^>=1.1 , hls-graph- , hls-plugin-api ^>=1.3+ , hls-plugin-api ^>=1.4 , lsp , text , unordered-containers
src/Ide/Plugin/RefineImports.hs view
@@ -2,12 +2,13 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DuplicateRecordFields #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} -module Ide.Plugin.RefineImports (descriptor) where+module Ide.Plugin.RefineImports (descriptor, Log(..)) where import Control.Arrow (Arrow (second)) import Control.DeepSeq (rwhnf)@@ -37,7 +38,9 @@ RealSrcSpan(..), getLoc, ieName, noLoc, tcg_exports, unLoc) -}+import qualified Development.IDE.Core.Shake as Shake import Development.IDE.Graph.Classes+import qualified Development.IDE.Types.Logger as Logger import GHC.Generics (Generic) import Ide.Plugin.ExplicitImports (extractMinimalImports, within)@@ -46,11 +49,17 @@ import Language.LSP.Server import Language.LSP.Types +newtype Log = LogShake Shake.Log deriving Show++instance Pretty Log where+ pretty = \case+ LogShake log -> pretty log+ -- | plugin declaration-descriptor :: PluginId -> PluginDescriptor IdeState-descriptor plId = (defaultPluginDescriptor plId)+descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState+descriptor recorder plId = (defaultPluginDescriptor plId) { pluginCommands = [refineImportCommand]- , pluginRules = refineImportsRule+ , pluginRules = refineImportsRule recorder , pluginHandlers = mconcat [ -- This plugin provides code lenses mkPluginHandler STextDocumentCodeLens lensProvider@@ -163,8 +172,8 @@ instance Show RefineImportsResult where show _ = "<refineImportsResult>" instance NFData RefineImportsResult where rnf = rwhnf -refineImportsRule :: Rules ()-refineImportsRule = define $ \RefineImports nfp -> do+refineImportsRule :: Recorder (WithPriority Log) -> Rules ()+refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineImports nfp -> do -- Get the typechecking artifacts from the module tmr <- use TypeCheck nfp -- We also need a GHC session with all the dependencies@@ -223,7 +232,7 @@ let res = [ (i, Just . T.intercalate "\n"- . map (T.pack . prettyPrint . constructImport i)+ . map (printOutputable . constructImport i) . Map.toList $ filteredInnerImports) -- for every minimal imports@@ -242,7 +251,7 @@ -- Check if a name is exposed by AvailInfo (the available information of a module) containsAvail :: LIE GhcRn -> AvailInfo -> Bool containsAvail name avail =- any (\an -> prettyPrint an == (prettyPrint . ieName . unLoc $ name))+ any (\an -> printOutputable an == (printOutputable . ieName . unLoc $ name)) $ availNamesWithSelectors avail --------------------------------------------------------------------------------
test/Main.hs view
@@ -24,7 +24,7 @@ ] refineImportsPlugin :: PluginDescriptor IdeState-refineImportsPlugin = RefineImports.descriptor "refineImports"+refineImportsPlugin = RefineImports.descriptor mempty "refineImports" -- code action tests