Skip to content

Add associated type families to local completions #2987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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