@@ -147,7 +147,7 @@ executeCommandHandlers ecs = requestHandler SWorkspaceExecuteCommand execCmd
147
147
extensiblePlugins :: [(PluginId , PluginDescriptor IdeState )] -> Plugin Config
148
148
extensiblePlugins xs = mempty { P. pluginHandlers = handlers }
149
149
where
150
- getPluginDescriptor pid = fromJust $ lookup pid xs
150
+ getPluginDescriptor pid = lookup pid xs
151
151
IdeHandlers handlers' = foldMap bakePluginId xs
152
152
bakePluginId :: (PluginId , PluginDescriptor IdeState ) -> IdeHandlers
153
153
bakePluginId (pid,pluginDesc) = IdeHandlers $ DMap. map
@@ -159,20 +159,38 @@ extensiblePlugins xs = mempty { P.pluginHandlers = handlers }
159
159
(IdeMethod m :=> IdeHandler fs') <- DMap. assocs handlers'
160
160
pure $ requestHandler m $ \ ide params -> do
161
161
config <- Ide.PluginUtils. getClientConfig
162
- let fs = filter (\ (pid,_) -> pluginEnabled m params (getPluginDescriptor pid) config) fs'
163
- case nonEmpty fs of
164
- Nothing -> pure $ Left $ ResponseError InvalidRequest
165
- (" No plugin enabled for " <> T. pack (show m) <> " , available: " <> T. pack (show $ map fst fs))
162
+ -- for each pid, get plugin descriptor ([(Pid, Maybe PluginDesc)])
163
+ -- If plugin amiss, pure $ Left
164
+ -- zip fs' pluginDescs for pluginEnabled
165
+ let pluginInfo = map (\ (pid,_) -> (pid, getPluginDescriptor pid)) fs'
166
+ cleanPluginInfo <- go pluginInfo []
167
+ case cleanPluginInfo of
168
+ Left err -> pure $ Left err
169
+ Right pluginInfos -> do
170
+ let fs = map snd $ filter (\ ((_, desc), _) -> pluginEnabled m params desc config) (zip pluginInfos fs')
171
+ case nonEmpty fs of
172
+ Nothing -> pure $ Left $ ResponseError InvalidRequest
173
+ (" No plugin enabled for " <> T. pack (show m) <> " , available: " <> T. pack (show $ map fst fs))
174
+ Nothing
175
+ Just fs -> do
176
+ let msg e pid = " Exception in plugin " <> T. pack (show pid) <> " while processing " <> T. pack (show m) <> " : " <> T. pack (show e)
177
+ es <- runConcurrently msg (show m) fs ide params
178
+ let (errs,succs) = partitionEithers $ toList es
179
+ case nonEmpty succs of
180
+ Nothing -> pure $ Left $ combineErrors errs
181
+ Just xs -> do
182
+ caps <- LSP. getClientCapabilities
183
+ pure $ Right $ combineResponses m config caps params xs
184
+
185
+ go :: [(PluginId , Maybe (PluginDescriptor c ))] -> [(PluginId , PluginDescriptor c )] -> LSP. LspM Config (Either ResponseError [(PluginId , PluginDescriptor c )])
186
+ go ((pid, Nothing ): _) _ = pure $ Left $ ResponseError InvalidRequest
187
+ (" No plugindescriptor found for " <> pidT <> " , available: " )
166
188
Nothing
167
- Just fs -> do
168
- let msg e pid = " Exception in plugin " <> T. pack (show pid) <> " while processing " <> T. pack (show m) <> " : " <> T. pack (show e)
169
- es <- runConcurrently msg (show m) fs ide params
170
- let (errs,succs) = partitionEithers $ toList es
171
- case nonEmpty succs of
172
- Nothing -> pure $ Left $ combineErrors errs
173
- Just xs -> do
174
- caps <- LSP. getClientCapabilities
175
- pure $ Right $ combineResponses m config caps params xs
189
+ where
190
+ PluginId pidT = pid
191
+ go ((pid, Just desc): xs) ys = go xs (ys ++ [(pid, desc)])
192
+ go [] ys = pure $ Right ys
193
+
176
194
-- ---------------------------------------------------------------------
177
195
178
196
extensibleNotificationPlugins :: [(PluginId , PluginNotificationHandlers IdeState )] -> Plugin Config
0 commit comments