@@ -119,7 +119,11 @@ data PluginDescriptor (ideState :: *) =
119
119
, pluginNotificationHandlers :: PluginNotificationHandlers ideState
120
120
, pluginModifyDynflags :: DynFlagsModifications
121
121
, pluginCli :: Maybe (ParserInfo (IdeCommand ideState ))
122
- , pluginFileType :: [T. Text ]
122
+ , pluginFileType :: [T. Text ]
123
+ -- ^ File extension of the files the plugin is responsible for.
124
+ -- The plugin is only allowed to handle files with these extensions
125
+ -- When writing handlers, etc. for this plugin it can be assumed that all handled files are of this type.
126
+ -- The file extension must have a leading '.'.
123
127
}
124
128
125
129
-- | An existential wrapper of 'Properties'
@@ -165,7 +169,14 @@ defaultConfigDescriptor = ConfigDescriptor True False (mkCustomConfig emptyPrope
165
169
class HasTracing (MessageParams m ) => PluginMethod (k :: MethodType ) (m :: Method FromClient k ) where
166
170
167
171
-- | Parse the configuration to check if this plugin is enabled
168
- pluginEnabled :: SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
172
+ pluginEnabled
173
+ :: SMethod m
174
+ -> MessageParams m
175
+ -- ^ Whether a plugin is enabled might depend on the message parameters
176
+ -- eg 'pluginFileType' specifies what file extension a plugin is allowed to handle
177
+ -> PluginDescriptor c
178
+ -> Config
179
+ -> Bool
169
180
170
181
default pluginEnabled :: (HasTextDocument (MessageParams m ) doc , HasUri doc Uri )
171
182
=> SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
@@ -220,6 +231,9 @@ instance PluginRequestMethod TextDocumentCodeAction where
220
231
, Just caKind <- ca ^. kind = any (\ k -> k `codeActionKindSubsumes` caKind) allowed
221
232
| otherwise = False
222
233
234
+ -- | Check whether the given plugin descriptor is responsible for the file with the given path.
235
+ -- Compares the file extension of the file at the given path with the file extension
236
+ -- the plugin is responsible for.
223
237
pluginResponsible :: Uri -> PluginDescriptor c -> Bool
224
238
pluginResponsible uri pluginDesc
225
239
| Just fp <- mfp
@@ -307,8 +321,9 @@ instance PluginMethod Request TextDocumentPrepareCallHierarchy where
307
321
pid = pluginId pluginDesc
308
322
309
323
instance PluginMethod Request TextDocumentSelectionRange where
310
- pluginEnabled _ _ pluginDesc conf = pluginEnabledConfig plcSelectionRangeOn pid conf
324
+ pluginEnabled _ msgParams pluginDesc conf = pluginResponsible uri pluginDesc && pluginEnabledConfig plcSelectionRangeOn pid conf
311
325
where
326
+ uri = msgParams ^. J. textDocument . J. uri
312
327
pid = pluginId pluginDesc
313
328
314
329
instance PluginMethod Request CallHierarchyIncomingCalls where
@@ -399,7 +414,7 @@ instance PluginRequestMethod TextDocumentCompletion where
399
414
consumeCompletionResponse n (InR (CompletionList isCompleteResponse (List xx)))
400
415
401
416
instance PluginRequestMethod TextDocumentFormatting where
402
- combineResponses _ _ _ _ x = sconcat x
417
+ combineResponses _ _ _ _ (x :| _) = x
403
418
404
419
instance PluginRequestMethod TextDocumentRangeFormatting where
405
420
combineResponses _ _ _ _ (x :| _) = x
0 commit comments