Skip to content

Commit c3c73cf

Browse files
Add associated type families to local completions (#2987)
Co-authored-by: Lei Zhu <julytreee@gmail.com>
1 parent 771d8f4 commit c3c73cf

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 4 additions & 2 deletions
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

test/functional/Completion.hs

Lines changed: 10 additions & 0 deletions
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
]
Lines changed: 8 additions & 0 deletions
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)