@@ -119,7 +119,11 @@ data PluginDescriptor (ideState :: *) =
119119 , pluginNotificationHandlers :: PluginNotificationHandlers ideState
120120 , pluginModifyDynflags :: DynFlagsModifications
121121 , 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 '.'.
123127 }
124128
125129-- | An existential wrapper of 'Properties'
@@ -165,7 +169,14 @@ defaultConfigDescriptor = ConfigDescriptor True False (mkCustomConfig emptyPrope
165169class HasTracing (MessageParams m ) => PluginMethod (k :: MethodType ) (m :: Method FromClient k ) where
166170
167171 -- | 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
169180
170181 default pluginEnabled :: (HasTextDocument (MessageParams m ) doc , HasUri doc Uri )
171182 => SMethod m -> MessageParams m -> PluginDescriptor c -> Config -> Bool
@@ -220,6 +231,9 @@ instance PluginRequestMethod TextDocumentCodeAction where
220231 , Just caKind <- ca ^. kind = any (\ k -> k `codeActionKindSubsumes` caKind) allowed
221232 | otherwise = False
222233
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.
223237pluginResponsible :: Uri -> PluginDescriptor c -> Bool
224238pluginResponsible uri pluginDesc
225239 | Just fp <- mfp
@@ -307,8 +321,9 @@ instance PluginMethod Request TextDocumentPrepareCallHierarchy where
307321 pid = pluginId pluginDesc
308322
309323instance PluginMethod Request TextDocumentSelectionRange where
310- pluginEnabled _ _ pluginDesc conf = pluginEnabledConfig plcSelectionRangeOn pid conf
324+ pluginEnabled _ msgParams pluginDesc conf = pluginResponsible uri pluginDesc && pluginEnabledConfig plcSelectionRangeOn pid conf
311325 where
326+ uri = msgParams ^. J. textDocument . J. uri
312327 pid = pluginId pluginDesc
313328
314329instance PluginMethod Request CallHierarchyIncomingCalls where
@@ -399,7 +414,7 @@ instance PluginRequestMethod TextDocumentCompletion where
399414 consumeCompletionResponse n (InR (CompletionList isCompleteResponse (List xx)))
400415
401416instance PluginRequestMethod TextDocumentFormatting where
402- combineResponses _ _ _ _ x = sconcat x
417+ combineResponses _ _ _ _ (x :| _) = x
403418
404419instance PluginRequestMethod TextDocumentRangeFormatting where
405420 combineResponses _ _ _ _ (x :| _) = x
0 commit comments