diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index 1a2cb5304b..2269cb3914 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -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 diff --git a/test/functional/Completion.hs b/test/functional/Completion.hs index 76a661bd8f..820f25ce95 100644 --- a/test/functional/Completion.hs +++ b/test/functional/Completion.hs @@ -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 ] diff --git a/test/testdata/completion/AssociatedTypeFamily.hs b/test/testdata/completion/AssociatedTypeFamily.hs new file mode 100644 index 0000000000..f50c1e20cf --- /dev/null +++ b/test/testdata/completion/AssociatedTypeFamily.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE TypeFamilies #-} +module AssociatedTypeFamily () where + +class C a where + type Fam a + +x :: C a => a -> Fam a +x = undefined