Skip to content

Commit

Permalink
Deduplicate HLS plugins
Browse files Browse the repository at this point in the history
Use a smart constructor to prevent duplicated plugins. We cannot use a
set since order matters
  • Loading branch information
pepeiborra committed Aug 17, 2022
1 parent 92f4bd4 commit 3098524
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions hls-plugin-api/src/Ide/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand All @@ -20,6 +21,30 @@
{-# LANGUAGE ViewPatterns #-}

module Ide.Types
( PluginDescriptor(..), defaultPluginDescriptor, defaultCabalPluginDescriptor
, IdeCommand(..)
, IdeMethod(..)
, IdeNotification(..)
, IdePlugins(IdePlugins, ipMap)
, DynFlagsModifications(..)
, ConfigDescriptor(..), defaultConfigDescriptor, configForPlugin, pluginEnabledConfig
, CustomConfig(..), mkCustomConfig
, FallbackCodeActionParams(..)
, FormattingType(..), FormattingMethod, FormattingHandler, mkFormattingHandlers
, HasTracing(..)
, PluginCommand(..), CommandId(..), CommandFunction, mkLspCommand, mkLspCmdId
, PluginId(..)
, PluginHandler(..), mkPluginHandler
, PluginHandlers(..)
, PluginMethod(..)
, PluginMethodHandler
, PluginNotificationHandler(..), mkPluginNotificationHandler
, PluginNotificationHandlers(..)
, PluginRequestMethod(..)
, getProcessID, getPid
, installSigUsr1Handler
, responseError
)
where

#ifdef mingw32_HOST_OS
Expand All @@ -36,6 +61,7 @@ import Data.Dependent.Map (DMap)
import qualified Data.Dependent.Map as DMap
import qualified Data.DList as DList
import Data.GADT.Compare
import Data.List.Extra (nubOrdOn)
import Data.List.NonEmpty (NonEmpty (..), toList)
import qualified Data.Map as Map
import Data.Maybe
Expand Down Expand Up @@ -76,9 +102,19 @@ import Text.Regex.TDFA.Text ()

-- ---------------------------------------------------------------------

newtype IdePlugins ideState = IdePlugins
{ ipMap :: [(PluginId, PluginDescriptor ideState)]}
deriving newtype (Monoid, Semigroup)
newtype IdePlugins ideState = IdePlugins_
{ ipMap_ :: [(PluginId, PluginDescriptor ideState)]}
deriving newtype Monoid

-- | Smart constructor that deduplicates plugins
pattern IdePlugins :: [(PluginId, PluginDescriptor ideState)] -> IdePlugins ideState
pattern IdePlugins{ipMap} <- IdePlugins_ ipMap
where
IdePlugins ipMap = IdePlugins_{ipMap_ = nubOrdOn fst ipMap}
{-# COMPLETE IdePlugins #-}

instance Semigroup (IdePlugins s) where
IdePlugins a <> IdePlugins b = IdePlugins(a <> b)

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

0 comments on commit 3098524

Please sign in to comment.