@@ -24,8 +24,8 @@ module Haskell.Ide.Engine.PluginsIdeMonads
2424 , allLspCmdIds 
2525 , mkLspCmdId 
2626 --  * Plugins
27-  , PluginId 
28-  , CommandName 
27+  , PluginId ( .. ) 
28+  , CommandId ( .. ) 
2929 , PluginDescriptor (.. )
3030 , pluginDescToIdePlugins 
3131 , PluginCommand (.. )
@@ -105,6 +105,7 @@ import UnliftIO
105105import  Control.Applicative 
106106
107107import  Data.Aeson  hiding  (defaultOptions )
108+ import  Data.Coerce 
108109import  qualified  Data.ConstrainedDynamic  as  CD 
109110import  Data.Default 
110111import  qualified  Data.List  as  List 
@@ -113,6 +114,7 @@ import qualified Data.Map as Map
113114import  Data.Maybe 
114115import  Data.Monoid  ( (<>)  )
115116import  qualified  Data.Set  as  S 
117+ import  Data.String 
116118import  qualified  Data.Text  as  T 
117119import  Data.Typeable  ( TypeRep 
118120 , Typeable 
@@ -175,7 +177,7 @@ instance HasPidCache IO where
175177instance  HasPidCache  m  =>  HasPidCache  (IdeResultT  m ) where 
176178 getPidCache =  lift getPidCache
177179
178- mkLspCommand  ::  HasPidCache  m  =>  PluginId  ->  CommandName  ->  T. Text->  Maybe Value ] ->  m  Command 
180+ mkLspCommand  ::  HasPidCache  m  =>  PluginId  ->  CommandId  ->  T. Text->  Maybe Value ] ->  m  Command 
179181mkLspCommand plid cn title args' =  do 
180182 cmdId <-  mkLspCmdId plid cn
181183 let  args =  List  <$>  args'
@@ -184,12 +186,12 @@ mkLspCommand plid cn title args' = do
184186allLspCmdIds  ::  HasPidCache  m  =>  IdePlugins  ->  m  [T. Text
185187allLspCmdIds (IdePlugins  m) =  concat  <$>  mapM  go (Map. toList (pluginCommands <$>  m))
186188 where 
187-  go (plid, cmds) =  mapM  (mkLspCmdId plid .  commandName ) cmds
189+  go (plid, cmds) =  mapM  (mkLspCmdId plid .  commandId ) cmds
188190
189- mkLspCmdId  ::  HasPidCache  m  =>  PluginId  ->  CommandName  ->  m  T. Text
190- mkLspCmdId plid cn  =  do 
191+ mkLspCmdId  ::  HasPidCache  m  =>  PluginId  ->  CommandId  ->  m  T. Text
192+ mkLspCmdId plid cid  =  do 
191193 pid <-  T. pack .  show  <$>  getPidCache
192-  return  $  pid <>  " :" <>  plid <>  " :" <>  cn 
194+  return  $  pid <>  " :" <>  coerce  plid <>  " :" <>  coerce cid 
193195
194196--  ---------------------------------------------------------------------
195197--  Plugins
@@ -260,6 +262,11 @@ type FormattingProvider = T.Text -- ^ Text to format
260262 ->  FormattingOptions  --  ^  Options for the formatter 
261263 ->  IdeM  (IdeResult  [TextEdit ]) --  ^  Result of the formatting or the unchanged text. 
262264
265+ newtype  PluginId  =  PluginId  T. Text
266+  deriving  (Show , Read , Eq , Ord )
267+ instance  IsString  PluginId  where 
268+  fromString =  PluginId  .  T. pack
269+ 
263270data  PluginDescriptor  = 
264271 PluginDescriptor  {  pluginId  ::  PluginId 
265272 , pluginCommands  ::  [PluginCommand ]
@@ -271,13 +278,15 @@ data PluginDescriptor =
271278 }  deriving  (Generic )
272279
273280instance  Show PluginCommand  where 
274-  show  (PluginCommand  name  _) =  " PluginCommand { name = " ++  T. unpack name  ++  "  }" 
281+  show  (PluginCommand  i  _) =  " PluginCommand { name = " ++  show  i  ++  "  }" 
275282
276- type  PluginId  =  T. Text
277- type  CommandName  =  T. Text
283+ newtype  CommandId  =  CommandId  T. Text
284+  deriving  (Show , Read , Eq , Ord )
285+ instance  IsString  CommandId  where 
286+  fromString =  CommandId  .  T. pack
278287
279288data  PluginCommand  =  forall  a  b .  (FromJSON  a , ToJSON  b , Typeable  b ) => 
280-  PluginCommand  {  commandName   ::  CommandName 
289+  PluginCommand  {  commandId   ::  CommandId 
281290 , commandFunc  ::  a  ->  IdeGhcM  (IdeResult  b )
282291 } 
283292
@@ -295,21 +304,21 @@ fromDynJSON = CD.fromDynamic
295304toDynJSON  ::  (Typeable  a , ToJSON  a ) =>  a  ->  DynamicJSON 
296305toDynJSON =  CD. toDyn
297306
298- --  |  Runs a plugin command given a PluginId, CommandName  and 
307+ --  |  Runs a plugin command given a PluginId, CommandId  and 
299308--  arguments in the form of a JSON object. 
300- runPluginCommand  ::  PluginId  ->  CommandName  ->  Value 
309+ runPluginCommand  ::  PluginId  ->  CommandId  ->  Value 
301310 ->  IdeGhcM  (IdeResult  DynamicJSON )
302311runPluginCommand p com arg =  do 
303312 IdePlugins  m <-  getPlugins
304313 case  Map. lookup  p m of 
305314 Nothing  ->  return  $ 
306-  IdeResultFail  $  IdeError  UnknownPlugin  (" Plugin " <>  p <>  "  doesn't exist" Null 
307-  Just  PluginDescriptor  { pluginCommands =  xs } ->  case  List. find ((com == ) .  commandName ) xs of 
315+  IdeResultFail  $  IdeError  UnknownPlugin  (" Plugin " <>  coerce  p <>  "  doesn't exist" Null 
316+  Just  PluginDescriptor  { pluginCommands =  xs } ->  case  List. find ((com == ) .  commandId ) xs of 
308317 Nothing  ->  return  $  IdeResultFail  $ 
309-  IdeError  UnknownCommand  (" Command " <>  com <>  "  isn't defined for plugin " <>  p <>  " . Legal commands are: " <>  T. pack(show  $  map  commandName  xs)) Null 
318+  IdeError  UnknownCommand  (" Command " <>  coerce  com <>  "  isn't defined for plugin " <>  coerce  p <>  " . Legal commands are: " <>  T. pack(show  $  map  commandId  xs)) Null 
310319 Just  (PluginCommand  _ f) ->  case  fromJSON arg of 
311320 Error  err ->  return  $  IdeResultFail  $ 
312-  IdeError  ParameterError  (" error while parsing args for " <>  com <>  "  in plugin " <>  p <>  " : " <>  T. pack err) Null 
321+  IdeError  ParameterError  (" error while parsing args for " <>  coerce  com <>  "  in plugin " <>  coerce  p <>  " : " <>  T. pack err) Null 
313322 Success  a ->  do 
314323 res <-  f a
315324 return  $  fmap  toDynJSON res
@@ -319,11 +328,6 @@ newtype IdePlugins = IdePlugins
319328 {  ipMap  ::  Map. MapPluginId  PluginDescriptor 
320329 }  deriving  (Generic )
321330
322- --  TODO:AZ this is a defective instance, do we actually need it?
323- --  Perhaps rather make a separate type explicitly for this purpose.
324- instance  ToJSON  IdePlugins  where 
325-  toJSON (IdePlugins  m) =  toJSON $  fmap  commandName <$>  fmap  pluginCommands m
326- 
327331--  |  For the diagnostic providers in the config, return a map of 
328332--  current enabled state, indexed by the plugin id. 
329333getDiagnosticProvidersConfig  ::  Config  ->  Map. MapPluginId  Bool 
0 commit comments