Skip to content

Commit ed1dc68

Browse files
committed
Evaluate completion providers in parallel
1 parent 9e10a19 commit ed1dc68

File tree

1 file changed

+9
-17
lines changed
  • ghcide/src/Development/IDE/Plugin

1 file changed

+9
-17
lines changed

ghcide/src/Development/IDE/Plugin/HLS.hs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Development.Shake (Rules)
3434
import Ide.PluginUtils (getClientConfig, pluginEnabled, getPluginConfig, responseError, getProcessID)
3535
import Development.IDE.Types.Logger (logInfo)
3636
import Development.IDE.Core.Tracing
37+
import Control.Concurrent.Async (mapConcurrently)
3738

3839
-- ---------------------------------------------------------------------
3940

@@ -437,7 +438,7 @@ makeCompletions :: [(PluginId, CompletionProvider IdeState)]
437438
makeCompletions sps lf ideState params@(CompletionParams (TextDocumentIdentifier doc) pos _context _mt)
438439
= do
439440
mprefix <- getPrefixAtPos lf doc pos
440-
config <- getClientConfig lf
441+
maxCompletions <- maxCompletions <$> getClientConfig lf
441442

442443
let
443444
combine :: [CompletionResponseResult] -> CompletionResponseResult
@@ -450,37 +451,28 @@ makeCompletions sps lf ideState params@(CompletionParams (TextDocumentIdentifier
450451
go comp acc (CompletionList (CompletionListType comp' (List ls)) : rest) =
451452
go (comp && comp') (acc <> DList.fromList ls) rest
452453

453-
-- | Process a list of completion providers until we reach a max number of results
454454
makeAction ::
455-
Int ->
456-
[(PluginId, CompletionProvider IdeState)] ->
457-
IO [Either ResponseError CompletionResponseResult]
458-
makeAction 0 _ = return []
459-
makeAction _ [] = return []
460-
makeAction limit ((pid, p) : rest) = do
455+
(PluginId, CompletionProvider IdeState) ->
456+
IO (Either ResponseError CompletionResponseResult)
457+
makeAction (pid, p) = do
461458
pluginConfig <- getPluginConfig lf pid
462-
results <- if pluginEnabled pluginConfig plcCompletionOn
459+
if pluginEnabled pluginConfig plcCompletionOn
463460
then otTracedProvider pid "completions" $ p lf ideState params
464461
else return $ Right $ Completions $ List []
465-
case results of
466-
Right resp -> do
467-
let (limit', results') = consumeCompletionResponse limit resp
468-
(Right results' :) <$> makeAction limit' rest
469-
Left err ->
470-
(Left err :) <$> makeAction limit rest
471462

472463
case mprefix of
473464
Nothing -> return $ Right $ Completions $ List []
474465
Just _prefix -> do
475-
mhs <- makeAction (maxCompletions config) sps
466+
mhs <- mapConcurrently makeAction sps
476467
case rights mhs of
477468
[] -> return $ Left $ responseError $ T.pack $ show $ lefts mhs
478-
hs -> return $ Right $ combine hs
469+
hs -> return $ Right $ snd $ consumeCompletionResponse maxCompletions $ combine hs
479470

480471
-- | Crops a completion response. Returns the final number of completions and the cropped response
481472
consumeCompletionResponse :: Int -> CompletionResponseResult -> (Int, CompletionResponseResult)
482473
consumeCompletionResponse limit it@(CompletionList (CompletionListType _ (List xx))) =
483474
case splitAt limit xx of
475+
(_, []) -> (limit - length xx, it)
484476
(xx', _) -> (0, CompletionList (CompletionListType False (List xx')))
485477
consumeCompletionResponse n (Completions (List xx)) =
486478
consumeCompletionResponse n (CompletionList (CompletionListType False (List xx)))

0 commit comments

Comments
 (0)