@@ -151,6 +151,12 @@ mkExtCompl label =
151
151
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
152
152
Nothing Nothing Nothing Nothing Nothing
153
153
154
+ mkPragmaCompl :: T. Text -> T. Text -> J. CompletionItem
155
+ mkPragmaCompl label insertText =
156
+ J. CompletionItem label (Just J. CiKeyword ) Nothing
157
+ Nothing Nothing Nothing Nothing Nothing (Just insertText) (Just J. Snippet )
158
+ Nothing Nothing Nothing Nothing Nothing
159
+
154
160
safeTyThingId :: TyThing -> Maybe Id
155
161
safeTyThingId (AnId i) = Just i
156
162
safeTyThingId (AConLike (RealDataCon dc)) = Just $ dataConWrapId dc
@@ -309,53 +315,95 @@ newtype WithSnippets = WithSnippets Bool
309
315
310
316
-- | Returns the cached completions for the given module and position.
311
317
getCompletions :: Uri -> PosPrefixInfo -> WithSnippets -> IdeM (IdeResult [J. CompletionItem ])
312
- getCompletions uri prefixInfo (WithSnippets withSnippets) = pluginGetFile " getCompletions: " uri $ \ file -> do
313
- supportsSnippets <- fromMaybe False <$> asks (^? J. textDocument
314
- . _Just . J. completion
315
- . _Just . J. completionItem
316
- . _Just . J. snippetSupport
317
- . _Just)
318
- let toggleSnippets x
319
- | withSnippets && supportsSnippets = x
320
- | otherwise = x { J. _insertTextFormat = Just J. PlainText
321
- , J. _insertText = Nothing }
322
-
323
- PosPrefixInfo {fullLine, prefixModule, prefixText} = prefixInfo
324
- debugm $ " got prefix" ++ show (prefixModule, prefixText)
325
- let enteredQual = if T. null prefixModule then " " else prefixModule <> " ."
326
- fullPrefix = enteredQual <> prefixText
327
- ifCachedModuleAndData file (IdeResultOk [] ) $ \ _ _ CC { allModNamesAsNS, unqualCompls, qualCompls, importableModules, cachedExtensions } ->
328
- let
329
- filtModNameCompls = map mkModCompl
330
- $ mapMaybe (T. stripPrefix enteredQual)
331
- $ Fuzzy. simpleFilter fullPrefix allModNamesAsNS
332
-
333
- filtCompls = Fuzzy. filterBy label prefixText compls
334
- where
335
- compls = if T. null prefixModule
336
- then unqualCompls
337
- else Map. findWithDefault [] prefixModule qualCompls
338
-
339
- mkImportCompl label = (J. detail ?~ label)
340
- . mkModCompl
341
- $ fromMaybe " " (T. stripPrefix enteredQual label)
342
-
343
- filtListWith f list = [ f label
344
- | label <- Fuzzy. simpleFilter fullPrefix list
345
- , enteredQual `T.isPrefixOf` label
346
- ]
347
-
348
- filtImportCompls = filtListWith mkImportCompl importableModules
349
- filtExtensionCompls = filtListWith mkExtCompl cachedExtensions
350
-
351
- result
352
- | " import " `T.isPrefixOf` fullLine =
353
- filtImportCompls
354
- | " {-# language" `T.isPrefixOf` T. toLower fullLine =
355
- filtExtensionCompls
356
- | otherwise =
357
- filtModNameCompls ++ map (toggleSnippets . mkCompl) filtCompls
358
- in return $ IdeResultOk result
318
+ getCompletions uri prefixInfo (WithSnippets withSnippets) =
319
+ pluginGetFile " getCompletions: " uri $ \ file -> do
320
+ supportsSnippets <- fromMaybe False <$> asks
321
+ (^? J. textDocument
322
+ . _Just
323
+ . J. completion
324
+ . _Just
325
+ . J. completionItem
326
+ . _Just
327
+ . J. snippetSupport
328
+ . _Just
329
+ )
330
+ let toggleSnippets x
331
+ | withSnippets && supportsSnippets = x
332
+ | otherwise = x { J. _insertTextFormat = Just J. PlainText
333
+ , J. _insertText = Nothing
334
+ }
335
+
336
+ PosPrefixInfo { fullLine, prefixModule, prefixText } = prefixInfo
337
+ debugm $ " got prefix" ++ show (prefixModule, prefixText)
338
+ let enteredQual = if T. null prefixModule then " " else prefixModule <> " ."
339
+ fullPrefix = enteredQual <> prefixText
340
+ ifCachedModuleAndData file (IdeResultOk [] )
341
+ $ \ _ _ CC { allModNamesAsNS, unqualCompls, qualCompls, importableModules, cachedExtensions } ->
342
+ let
343
+ filtModNameCompls =
344
+ map mkModCompl
345
+ $ mapMaybe (T. stripPrefix enteredQual)
346
+ $ Fuzzy. simpleFilter fullPrefix allModNamesAsNS
347
+
348
+ filtCompls = Fuzzy. filterBy label prefixText compls
349
+ where
350
+ compls = if T. null prefixModule
351
+ then unqualCompls
352
+ else Map. findWithDefault [] prefixModule qualCompls
353
+
354
+ mkImportCompl label = (J. detail ?~ label) . mkModCompl $ fromMaybe
355
+ " "
356
+ (T. stripPrefix enteredQual label)
357
+
358
+ filtListWith f list =
359
+ [ f label
360
+ | label <- Fuzzy. simpleFilter fullPrefix list
361
+ , enteredQual `T.isPrefixOf` label
362
+ ]
363
+
364
+ filtListWithSnippet f list suffix =
365
+ [ toggleSnippets (f label (snippet <> suffix))
366
+ | (snippet, label) <- list
367
+ , Fuzzy. test fullPrefix label
368
+ ]
369
+
370
+ filtImportCompls = filtListWith mkImportCompl importableModules
371
+ filtPragmaCompls = filtListWithSnippet mkPragmaCompl validPragmas
372
+ filtOptsCompls = filtListWith mkExtCompl
373
+
374
+ result
375
+ | " import " `T.isPrefixOf` fullLine
376
+ = filtImportCompls
377
+ | " {-# language" `T.isPrefixOf` T. toLower fullLine
378
+ = filtOptsCompls cachedExtensions
379
+ | " {-# options_ghc" `T.isPrefixOf` T. toLower fullLine
380
+ = filtOptsCompls (map T. pack $ GHC. flagsForCompletion False )
381
+ | " {-# " `T.isPrefixOf` fullLine
382
+ = filtPragmaCompls (pragmaSuffix fullLine)
383
+ | otherwise
384
+ = filtModNameCompls ++ map (toggleSnippets . mkCompl) filtCompls
385
+ in
386
+ return $ IdeResultOk result
387
+ where
388
+ validPragmas :: [(T. Text , T. Text )]
389
+ validPragmas =
390
+ [ (" LANGUAGE ${1:extension}" , " LANGUAGE" )
391
+ , (" OPTIONS_GHC -${1:option}" , " OPTIONS_GHC" )
392
+ , (" INLINE ${1:function}" , " INLINE" )
393
+ , (" NOINLINE ${1:function}" , " NOINLINE" )
394
+ , (" INLINABLE ${1:function}" , " INLINABLE" )
395
+ , (" WARNING ${1:message}" , " WARNING" )
396
+ , (" DEPRECATED ${1:message}" , " DEPRECATED" )
397
+ , (" ANN ${1:annotation}" , " ANN" )
398
+ , (" RULES" , " RULES" )
399
+ , (" SPECIALIZE ${1:function}" , " SPECIALIZE" )
400
+ , (" SPECIALIZE INLINE ${1:function}" , " SPECIALIZE INLINE" )
401
+ ]
402
+
403
+ pragmaSuffix :: T. Text -> T. Text
404
+ pragmaSuffix fullLine
405
+ | " }" `T.isSuffixOf` fullLine = mempty
406
+ | otherwise = " #-}"
359
407
-- ---------------------------------------------------------------------
360
408
361
409
getTypeForName :: Name -> IdeM (Maybe Type )
0 commit comments