Skip to content

Commit c9e22b7

Browse files
committed
Limit completions to top 20
We are overwhelming the LSP client by sending 100s of completions after the first character. Instead, let's send 20 at a time and refresh for more when the user types another word
1 parent 4b0e456 commit c9e22b7

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,19 @@ getCompletionsLSP lsp ide
145145
(Just pfix', _) -> do
146146
let clientCaps = clientCapabilities $ shakeExtras ide
147147
snippets <- WithSnippets . completionSnippetsOn <$> getClientConfig lsp
148-
Completions . List <$> getCompletions ideOpts cci' parsedMod bindMap pfix' clientCaps snippets
148+
allCompletions <- getCompletions ideOpts cci' parsedMod bindMap pfix' clientCaps snippets
149+
let topCompletions = List $ take 20 allCompletions
150+
isComplete = allCompletions `longerThan` 20
151+
pure $ CompletionList (CompletionListType isComplete topCompletions)
149152
_ -> return (Completions $ List [])
150153
_ -> return (Completions $ List [])
151154
_ -> return (Completions $ List [])
152155

156+
longerThan :: [a] -> Int -> Bool
157+
longerThan [] _ = False
158+
longerThan _ 0 = True
159+
longerThan (_ : aa) n = longerThan aa (n -1)
160+
153161
setHandlersCompletion :: PartialHandlers Config
154162
setHandlersCompletion = PartialHandlers $ \WithMessage{..} x -> return x{
155163
LSP.completionHandler = withResponse RspCompletion getCompletionsLSP

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,11 @@ getCompletions ideOpts CC { allModNamesAsNS, unqualCompls, qualCompls, importabl
565565
= filtPragmaCompls (pragmaSuffix fullLine)
566566
| otherwise
567567
= let uniqueFiltCompls = nubOrdOn insertText filtCompls
568-
in filtModNameCompls ++ map (toggleSnippets caps withSnippets
569-
. mkCompl ideOpts . stripAutoGenerated) uniqueFiltCompls
570-
++ filtKeywordCompls
568+
in filtModNameCompls
569+
++ filtKeywordCompls
570+
++ map ( toggleSnippets caps withSnippets
571+
. mkCompl ideOpts . stripAutoGenerated
572+
) uniqueFiltCompls
571573
return result
572574

573575

0 commit comments

Comments
 (0)