Skip to content

Commit 6200a4c

Browse files
committed
Turn maxCompletions into config
1 parent 646a691 commit 6200a4c

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Development.IDE.Plugin.Completions
66
(
77
plugin
88
, getCompletionsLSP
9-
, maxCompletions
109
) where
1110

1211
import Language.Haskell.LSP.Messages
@@ -31,7 +30,7 @@ import Development.IDE.GHC.Util
3130
import Development.IDE.LSP.Server
3231
import TcRnDriver (tcRnImportDecls)
3332
import Data.Maybe
34-
import Ide.Plugin.Config (Config(completionSnippetsOn))
33+
import Ide.Plugin.Config (Config (completionSnippetsOn, maxCompletions))
3534
import Ide.PluginUtils (getClientConfig)
3635

3736
#if defined(GHC_LIB)
@@ -116,13 +115,6 @@ data NonLocalCompletions = NonLocalCompletions
116115
instance Hashable NonLocalCompletions
117116
instance NFData NonLocalCompletions
118117
instance Binary NonLocalCompletions
119-
120-
-- | 40 may seem conservative but note that most editors limit how many completions
121-
-- are displayed in the screen, and most users rarely scroll.
122-
-- For instance, VSCode only shows 12 completions in its popup, and Emacs has a similar limit.
123-
maxCompletions :: Int
124-
maxCompletions = 40
125-
126118
-- | Generate code actions.
127119
getCompletionsLSP
128120
:: LSP.LspFuncs Config
@@ -151,9 +143,10 @@ getCompletionsLSP lsp ide
151143
-> return (Completions $ List [])
152144
(Just pfix', _) -> do
153145
let clientCaps = clientCapabilities $ shakeExtras ide
154-
snippets <- WithSnippets . completionSnippetsOn <$> getClientConfig lsp
146+
config <- getClientConfig lsp
147+
let snippets = WithSnippets . completionSnippetsOn $ config
155148
allCompletions <- getCompletions ideOpts cci' parsedMod bindMap pfix' clientCaps snippets
156-
let (topCompletions, rest) = splitAt maxCompletions allCompletions
149+
let (topCompletions, rest) = splitAt (maxCompletions config) allCompletions
157150
pure $ CompletionList (CompletionListType (null rest) (List topCompletions))
158151
_ -> return (Completions $ List [])
159152
_ -> return (Completions $ List [])

ghcide/test/exe/Main.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import Development.IDE.Plugin.Test (WaitForIdeRuleResult(..), TestRequest(BlockS
6464
import Control.Monad.Extra (whenJust)
6565
import qualified Language.Haskell.LSP.Types.Lens as L
6666
import Control.Lens ((^.))
67-
import Development.IDE.Plugin.Completions (maxCompletions)
6867

6968
main :: IO ()
7069
main = do
@@ -3224,7 +3223,7 @@ otherCompletionTests = [
32243223
]
32253224
_ <- waitForDiagnostics
32263225
compls <- getCompletions doc (Position 3 13)
3227-
liftIO $ length compls @?= maxCompletions
3226+
liftIO $ length compls @?= maxCompletions def
32283227
]
32293228

32303229
highlightTests :: TestTree

hls-plugin-api/src/Ide/Plugin/Config.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ data Config =
6969
, completionSnippetsOn :: !Bool
7070
, formatOnImportOn :: !Bool
7171
, formattingProvider :: !T.Text
72+
, maxCompletions :: !Int
7273
, plugins :: !(Map.Map T.Text PluginConfig)
7374
} deriving (Show,Eq)
7475

@@ -87,6 +88,7 @@ instance Default Config where
8788
, formattingProvider = "ormolu"
8889
-- , formattingProvider = "floskell"
8990
-- , formattingProvider = "stylish-haskell"
91+
, maxCompletions = 40
9092
, plugins = Map.empty
9193
}
9294

@@ -107,6 +109,7 @@ instance A.FromJSON Config where
107109
<*> o .:? "completionSnippetsOn" .!= completionSnippetsOn def
108110
<*> o .:? "formatOnImportOn" .!= formatOnImportOn def
109111
<*> o .:? "formattingProvider" .!= formattingProvider def
112+
<*> o .:? "maxCompletions" .!= maxCompletions def
110113
<*> o .:? "plugin" .!= plugins def
111114

112115
-- 2017-10-09 23:22:00.710515298 [ThreadId 11] - ---> {"jsonrpc":"2.0","method":"workspace/didChangeConfiguration","params":{"settings":{"haskell":{"maxNumberOfProblems":100,"hlintOn":true}}}}

0 commit comments

Comments
 (0)