@@ -55,6 +55,8 @@ import qualified Language.LSP.Protocol.Lens as JL
55
55
import qualified Language.LSP.Protocol.Message as LSP
56
56
import Language.LSP.Protocol.Types
57
57
import qualified Language.LSP.VFS as VFS
58
+ import qualified Text.Fuzzy.Levenshtein as Fuzzy
59
+ import qualified Text.Fuzzy.Parallel as Fuzzy
58
60
import Text.Regex.TDFA
59
61
60
62
data Log
@@ -234,7 +236,9 @@ fieldSuggestCodeAction recorder ide _ (CodeActionParams _ _ (TextDocumentIdentif
234
236
fakeLspCursorPosition = Position lineNr (col + fromIntegral (T. length fieldName))
235
237
lspPrefixInfo = Ghcide. getCompletionPrefixFromRope fakeLspCursorPosition fileContents
236
238
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
238
242
let completionTexts = fmap (^. JL. label) completions
239
243
pure $ FieldSuggest. fieldErrorAction uri fieldName completionTexts _range
240
244
@@ -365,12 +369,21 @@ completion recorder ide _ complParams = do
365
369
Just (fields, _) -> do
366
370
let lspPrefInfo = Ghcide. getCompletionPrefixFromRope position cnts
367
371
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
369
375
liftIO $ fmap InL res
370
376
Nothing -> pure . InR $ InR Null
371
377
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
374
387
runMaybeT (context fields) >>= \ case
375
388
Nothing -> pure []
376
389
Just ctx -> do
@@ -390,6 +403,7 @@ computeCompletionsAt recorder ide prefInfo fp fields = do
390
403
case fst ctx of
391
404
Types. Stanza _ name -> name
392
405
_ -> Nothing
406
+ , matcher = matcher
393
407
}
394
408
completions <- completer completerRecorder completerData
395
409
pure completions
0 commit comments