Skip to content

Commit d2e83d8

Browse files
committed
Move lookupPluginId to IdePlugins
1 parent a2769a9 commit d2e83d8

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ import GHC.Plugins (Depth (AllTheWay),
5757
renderWithContext,
5858
sdocStyle)
5959
#endif
60-
import Ide.PluginUtils (mkLspCommand, lookupPluginId)
60+
import Ide.PluginUtils (mkLspCommand)
6161
import Ide.Types (CommandId (..),
62-
IdePlugins, PluginId)
62+
IdePlugins(..), PluginId)
6363
import Language.LSP.Types
6464
import Language.LSP.Types.Capabilities
6565
import qualified Language.LSP.VFS as VFS
@@ -665,7 +665,7 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
665665
-- assumes that nubOrdBy is stable
666666
let uniqueFiltCompls = nubOrdBy (uniqueCompl `on` snd . Fuzzy.original) filtCompls
667667
let compls = (fmap.fmap.fmap) (mkCompl pId ideOpts) uniqueFiltCompls
668-
pId = lookupPluginId (CommandId extendImportCommandId) plugins
668+
pId = lookupCommandProvider plugins (CommandId extendImportCommandId)
669669
return $
670670
(fmap.fmap) snd $
671671
sortBy (compare `on` lexicographicOrdering) $

ghcide/src/Development/IDE/Plugin/HLS.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ logAndReturnError recorder errCode msg = do
8686

8787
-- | Map a set of plugins to the underlying ghcide engine.
8888
asGhcIdePlugin :: Recorder (WithPriority Log) -> IdePlugins IdeState -> Plugin Config
89-
asGhcIdePlugin recorder (IdePlugins ls) =
89+
asGhcIdePlugin recorder (IdePlugins ls _) =
9090
mkPlugin rulesPlugins HLS.pluginRules <>
9191
mkPlugin (executeCommandPlugins recorder) HLS.pluginCommands <>
9292
mkPlugin (extensiblePlugins recorder) id <>

hls-plugin-api/src/Ide/PluginUtils.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ module Ide.PluginUtils
3232
handleMaybe,
3333
handleMaybeM,
3434
throwPluginError,
35-
lookupPluginId
3635
)
3736
where
3837

@@ -162,10 +161,11 @@ clientSupportsDocumentChanges caps =
162161

163162
pluginDescToIdePlugins :: [PluginDescriptor ideState] -> IdePlugins ideState
164163
pluginDescToIdePlugins plugins =
165-
IdePlugins $ map (\p -> (pluginId p, p)) $ nubOrdOn pluginId plugins
164+
IdePlugins xs (lookupPluginId xs)
165+
where xs = map (\p -> (pluginId p, p)) $ nubOrdOn pluginId plugins
166166

167167
idePluginsToPluginDesc :: IdePlugins ideState -> [PluginDescriptor ideState]
168-
idePluginsToPluginDesc (IdePlugins pp) = map snd pp
168+
idePluginsToPluginDesc (IdePlugins pp _) = map snd pp
169169

170170
-- ---------------------------------------------------------------------
171171
-- | Returns the current client configuration. It is not wise to permanently
@@ -228,7 +228,7 @@ positionInRange p (Range sp ep) = sp <= p && p < ep -- Range's end position is e
228228
-- ---------------------------------------------------------------------
229229

230230
allLspCmdIds' :: T.Text -> IdePlugins ideState -> [T.Text]
231-
allLspCmdIds' pid (IdePlugins ls) = mkPlugin (allLspCmdIds pid) (Just . pluginCommands)
231+
allLspCmdIds' pid (IdePlugins ls _) = mkPlugin (allLspCmdIds pid) (Just . pluginCommands)
232232
where
233233
justs (p, Just x) = [(p, x)]
234234
justs (_, Nothing) = []
@@ -245,8 +245,8 @@ allLspCmdIds pid commands = concatMap go commands
245245

246246

247247
-- | Lookup the plugin that exposes a particular command
248-
lookupPluginId :: CommandId -> IdePlugins a -> Maybe PluginId
249-
lookupPluginId cmd (IdePlugins ls) = fst <$> find go ls
248+
lookupPluginId :: [(PluginId, PluginDescriptor a)] -> CommandId -> Maybe PluginId
249+
lookupPluginId ls cmd = fst <$> find go ls
250250
where
251251
go (_, desc) = cmd `elem` map commandId (pluginCommands desc)
252252

hls-plugin-api/src/Ide/Types.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,20 @@ import Options.Applicative (ParserInfo)
7373
import System.FilePath
7474
import System.IO.Unsafe
7575
import Text.Regex.TDFA.Text ()
76+
import Control.Applicative ((<|>))
7677

7778
-- ---------------------------------------------------------------------
7879

79-
newtype IdePlugins ideState = IdePlugins
80-
{ ipMap :: [(PluginId, PluginDescriptor ideState)]}
81-
deriving newtype (Monoid, Semigroup)
80+
data IdePlugins ideState = IdePlugins
81+
{ ipMap :: [(PluginId, PluginDescriptor ideState)]
82+
, lookupCommandProvider :: CommandId -> Maybe PluginId
83+
}
84+
85+
instance Semigroup (IdePlugins a) where
86+
(IdePlugins a f) <> (IdePlugins b g) = IdePlugins (a ++ b) (\x -> f x <|> g x)
87+
88+
instance Monoid (IdePlugins a) where
89+
mempty = IdePlugins [] (const Nothing)
8290

8391
-- | Hooks for modifying the 'DynFlags' at different times of the compilation
8492
-- process. Plugins can install a 'DynFlagsModifications' via

0 commit comments

Comments
 (0)