Skip to content

Commit

Permalink
Add associated type families to local completions (#2987)
Browse files Browse the repository at this point in the history
Co-authored-by: Lei Zhu <[email protected]>
  • Loading branch information
gasparattila and July541 authored Jun 28, 2022
1 parent 771d8f4 commit c3c73cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,13 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
ValD _ PatBind{pat_lhs} ->
[mkComp id CiVariable Nothing
| VarPat _ id <- listify (\(_ :: Pat GhcPs) -> True) pat_lhs]
TyClD _ ClassDecl{tcdLName, tcdSigs} ->
TyClD _ ClassDecl{tcdLName, tcdSigs, tcdATs} ->
mkComp tcdLName CiInterface (Just $ showForSnippet tcdLName) :
[ mkComp id CiFunction (Just $ showForSnippet typ)
| L _ (ClassOpSig _ _ ids typ) <- tcdSigs
, id <- ids]
, id <- ids] ++
[ mkComp fdLName CiStruct (Just $ showForSnippet fdLName)
| L _ (FamilyDecl{fdLName}) <- tcdATs]
TyClD _ x ->
let generalCompls = [mkComp id cl (Just $ showForSnippet $ tyClDeclLName x)
| id <- listify (\(_ :: LIdP GhcPs) -> True) x
Expand Down
10 changes: 10 additions & 0 deletions test/functional/Completion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ tests = testGroup "completions" [
item ^. label @?= "liftA"
item ^. kind @?= Just CiFunction
item ^. detail @?= Just "Control.Applicative"

, testCase "completes locally defined associated type family" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
doc <- openDoc "AssociatedTypeFamily.hs" "haskell"

compls <- getCompletions doc (Position 5 20)
item <- getCompletionByLabel "Fam" compls
liftIO $ do
item ^. label @?= "Fam"
item ^. kind @?= Just CiStruct

, contextTests
, snippetTests
]
Expand Down
8 changes: 8 additions & 0 deletions test/testdata/completion/AssociatedTypeFamily.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# LANGUAGE TypeFamilies #-}
module AssociatedTypeFamily () where

class C a where
type Fam a

x :: C a => a -> Fam a
x = undefined

0 comments on commit c3c73cf

Please sign in to comment.