From 6bf719d6ead7fe669db6b5b7addc4649fcfff30f Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 20 Sep 2021 19:00:17 +0200 Subject: [PATCH] Return completions lazily for massive savings (#2217) --- .../src/Development/IDE/Plugin/Completions/Logic.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index fbf66ab3662..3510429a905 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -151,7 +151,7 @@ showModName = T.pack . moduleNameString -- Nothing Nothing Nothing Nothing (Just insertText) (Just Snippet) -- Nothing Nothing Nothing Nothing Nothing -mkCompl :: PluginId -> IdeOptions -> CompItem -> IO CompletionItem +mkCompl :: PluginId -> IdeOptions -> CompItem -> CompletionItem mkCompl pId IdeOptions {..} @@ -165,7 +165,7 @@ mkCompl docs, additionalTextEdits } = do - mbCommand <- mkAdditionalEditsCommand pId `traverse` additionalTextEdits + let mbCommand = mkAdditionalEditsCommand pId `fmap` additionalTextEdits let ci = CompletionItem {_label = label, _kind = kind, @@ -184,7 +184,7 @@ mkCompl _commitCharacters = Nothing, _command = mbCommand, _xdata = Nothing} - return $ removeSnippetsWhen (isJust isInfix) ci + removeSnippetsWhen (isJust isInfix) ci where kind = Just compKind docs' = imported : spanDocToMarkdown docs @@ -196,8 +196,8 @@ mkCompl MarkupContent MkMarkdown $ T.intercalate sectionSeparator docs' -mkAdditionalEditsCommand :: PluginId -> ExtendImport -> IO Command -mkAdditionalEditsCommand pId edits = pure $ +mkAdditionalEditsCommand :: PluginId -> ExtendImport -> Command +mkAdditionalEditsCommand pId edits = mkLspCommand pId (CommandId extendImportCommandId) "extend import" (Just [toJSON edits]) mkNameCompItem :: Uri -> Maybe T.Text -> OccName -> ModuleName -> Maybe Type -> Maybe Backtick -> SpanDoc -> Maybe (LImportDecl GhcPs) -> CompItem @@ -616,7 +616,7 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu | otherwise -> do -- assumes that nubOrdBy is stable let uniqueFiltCompls = nubOrdBy uniqueCompl filtCompls - compls <- mapM (mkCompl plId ideOpts) uniqueFiltCompls + let compls = map (mkCompl plId ideOpts) uniqueFiltCompls return $ filtModNameCompls ++ filtKeywordCompls ++ map (toggleSnippets caps config) compls