@@ -55,6 +55,8 @@ import qualified Language.LSP.Protocol.Lens as JL
5555import qualified Language.LSP.Protocol.Message as LSP
5656import Language.LSP.Protocol.Types
5757import qualified Language.LSP.VFS as VFS
58+ import qualified Text.Fuzzy.Levenshtein as Fuzzy
59+ import qualified Text.Fuzzy.Parallel as Fuzzy
5860import Text.Regex.TDFA
5961
6062data Log
@@ -234,7 +236,9 @@ fieldSuggestCodeAction recorder ide _ (CodeActionParams _ _ (TextDocumentIdentif
234236 fakeLspCursorPosition = Position lineNr (col + fromIntegral (T. length fieldName))
235237 lspPrefixInfo = Ghcide. getCompletionPrefixFromRope fakeLspCursorPosition fileContents
236238 cabalPrefixInfo = Completions. getCabalPrefixInfo fp lspPrefixInfo
237- completions <- liftIO $ computeCompletionsAt recorder ide cabalPrefixInfo fp cabalFields
239+ completions <- liftIO $ computeCompletionsAt recorder ide cabalPrefixInfo fp cabalFields $
240+ Fuzzy. Matcher $
241+ Fuzzy. levenshteinScored Fuzzy. defChunkSize
238242 let completionTexts = fmap (^. JL. label) completions
239243 pure $ FieldSuggest. fieldErrorAction uri fieldName completionTexts _range
240244
@@ -365,12 +369,21 @@ completion recorder ide _ complParams = do
365369 Just (fields, _) -> do
366370 let lspPrefInfo = Ghcide. getCompletionPrefixFromRope position cnts
367371 cabalPrefInfo = Completions. getCabalPrefixInfo path lspPrefInfo
368- let res = computeCompletionsAt recorder ide cabalPrefInfo path fields
372+ res = computeCompletionsAt recorder ide cabalPrefInfo path fields $
373+ Fuzzy. Matcher $
374+ Fuzzy. simpleFilter Fuzzy. defChunkSize Fuzzy. defMaxResults
369375 liftIO $ fmap InL res
370376 Nothing -> pure . InR $ InR Null
371377
372- computeCompletionsAt :: Recorder (WithPriority Log ) -> IdeState -> Types. CabalPrefixInfo -> FilePath -> [Syntax. Field Syntax. Position ] -> IO [CompletionItem ]
373- computeCompletionsAt recorder ide prefInfo fp fields = do
378+ computeCompletionsAt
379+ :: Recorder (WithPriority Log )
380+ -> IdeState
381+ -> Types. CabalPrefixInfo
382+ -> FilePath
383+ -> [Syntax. Field Syntax. Position ]
384+ -> Fuzzy. Matcher T. Text
385+ -> IO [CompletionItem ]
386+ computeCompletionsAt recorder ide prefInfo fp fields matcher = do
374387 runMaybeT (context fields) >>= \ case
375388 Nothing -> pure []
376389 Just ctx -> do
@@ -390,6 +403,7 @@ computeCompletionsAt recorder ide prefInfo fp fields = do
390403 case fst ctx of
391404 Types. Stanza _ name -> name
392405 _ -> Nothing
406+ , matcher = matcher
393407 }
394408 completions <- completer completerRecorder completerData
395409 pure completions
0 commit comments