Skip to content

Commit f43df42

Browse files
gasparattilaJuly541
authored andcommitted
Add associated type families to local completions (haskell#2987)
Co-authored-by: Lei Zhu <[email protected]>
1 parent 87081b0 commit f43df42

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Diff for: ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,13 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
462462
ValD _ PatBind{pat_lhs} ->
463463
[mkComp id CiVariable Nothing
464464
| VarPat _ id <- listify (\(_ :: Pat GhcPs) -> True) pat_lhs]
465-
TyClD _ ClassDecl{tcdLName, tcdSigs} ->
465+
TyClD _ ClassDecl{tcdLName, tcdSigs, tcdATs} ->
466466
mkComp tcdLName CiInterface (Just $ showForSnippet tcdLName) :
467467
[ mkComp id CiFunction (Just $ showForSnippet typ)
468468
| L _ (ClassOpSig _ _ ids typ) <- tcdSigs
469-
, id <- ids]
469+
, id <- ids] ++
470+
[ mkComp fdLName CiStruct (Just $ showForSnippet fdLName)
471+
| L _ (FamilyDecl{fdLName}) <- tcdATs]
470472
TyClD _ x ->
471473
let generalCompls = [mkComp id cl (Just $ showForSnippet $ tyClDeclLName x)
472474
| id <- listify (\(_ :: LIdP GhcPs) -> True) x

Diff for: test/functional/Completion.hs

+10
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ tests = testGroup "completions" [
147147
item ^. label @?= "liftA"
148148
item ^. kind @?= Just CiFunction
149149
item ^. detail @?= Just "Control.Applicative"
150+
151+
, testCase "completes locally defined associated type family" $ runSession hlsCommand fullCaps "test/testdata/completion" $ do
152+
doc <- openDoc "AssociatedTypeFamily.hs" "haskell"
153+
154+
compls <- getCompletions doc (Position 5 20)
155+
item <- getCompletionByLabel "Fam" compls
156+
liftIO $ do
157+
item ^. label @?= "Fam"
158+
item ^. kind @?= Just CiStruct
159+
150160
, contextTests
151161
, snippetTests
152162
]

Diff for: test/testdata/completion/AssociatedTypeFamily.hs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE TypeFamilies #-}
2+
module AssociatedTypeFamily () where
3+
4+
class C a where
5+
type Fam a
6+
7+
x :: C a => a -> Fam a
8+
x = undefined

0 commit comments

Comments
 (0)