Skip to content

Commit

Permalink
Use CiInterface/SkInterface for typeclass symbols (#1592)
Browse files Browse the repository at this point in the history
* Use CiInterface instead of CiClass for completion items

* Use SkInterface instead of SkClass for typeclass symbols

* Fix SkClass icon for type family symbol

* Use SkFunction for type families

Co-authored-by: Junyoung/Clare Jang <[email protected]>
  • Loading branch information
fwcd and Ailrun authored Mar 19, 2021
1 parent b3cf33f commit aad6401
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ghcide/src/Development/IDE/LSP/Outline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ documentSymbolForDecl (L (RealSrcSpan l) (TyClD _ FamDecl { tcdFam = FamilyDecl
t -> " " <> t
)
, _detail = Just $ pprText fdInfo
, _kind = SkClass
, _kind = SkFunction
}
documentSymbolForDecl (L (RealSrcSpan l) (TyClD _ ClassDecl { tcdLName = L _ name, tcdSigs, tcdTyVars }))
= Just (defDocumentSymbol l :: DocumentSymbol)
Expand All @@ -78,7 +78,7 @@ documentSymbolForDecl (L (RealSrcSpan l) (TyClD _ ClassDecl { tcdLName = L _ nam
"" -> ""
t -> " " <> t
)
, _kind = SkClass
, _kind = SkInterface
, _detail = Just "class"
, _children =
Just $ List
Expand Down
6 changes: 3 additions & 3 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ occNameToComKind ty oc
| isTcOcc oc = case ty of
Just t
| "Constraint" `T.isSuffixOf` t
-> CiClass
-> CiInterface
_ -> CiStruct
| isDataOcc oc = CiConstructor
| otherwise = CiVariable
Expand Down Expand Up @@ -406,7 +406,7 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
[mkComp id CiVariable Nothing
| VarPat _ id <- listify (\(_ :: Pat GhcPs) -> True) pat_lhs]
TyClD _ ClassDecl{tcdLName, tcdSigs} ->
mkComp tcdLName CiClass Nothing :
mkComp tcdLName CiInterface Nothing :
[ mkComp id CiFunction (Just $ ppr typ)
| L _ (TypeSig _ ids typ) <- tcdSigs
, id <- ids]
Expand All @@ -428,7 +428,7 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
]

mkComp n ctyp ty =
CI ctyp pn (Right thisModName) ty pn Nothing doc (ctyp `elem` [CiStruct, CiClass]) Nothing
CI ctyp pn (Right thisModName) ty pn Nothing doc (ctyp `elem` [CiStruct, CiInterface]) Nothing
where
pn = ppr n
doc = SpanDocText (getDocumentation [pm] n) (SpanDocUris Nothing Nothing)
Expand Down
14 changes: 7 additions & 7 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3768,7 +3768,7 @@ topLevelCompletionTests = [
"class"
["bar :: Xx", "xxx = ()", "-- | haddock", "class Xxx a"]
(Position 0 9)
[("Xxx", CiClass, "Xxx", False, True, Nothing)],
[("Xxx", CiInterface, "Xxx", False, True, Nothing)],
completionTest
"records"
["data Person = Person { _personName:: String, _personAge:: Int}", "bar = Person { _pers }" ]
Expand Down Expand Up @@ -3862,7 +3862,7 @@ nonLocalCompletionTests =
"type"
["{-# OPTIONS_GHC -Wall #-}", "module A () where", "f :: Bo", "f = True"]
(Position 2 7)
[ ("Bounded", CiClass, "Bounded ${1:*}", True, True, Nothing),
[ ("Bounded", CiInterface, "Bounded ${1:*}", True, True, Nothing),
("Bool", CiStruct, "Bool ", True, True, Nothing)
],
completionTest
Expand Down Expand Up @@ -4163,7 +4163,7 @@ outlineTests = testGroup
let source = T.unlines ["{-# language TypeFamilies #-}", "type family A"]
docId <- createDoc "A.hs" "haskell" source
symbols <- getDocumentSymbols docId
liftIO $ symbols @?= Left [docSymbolD "A" "type family" SkClass (R 1 0 1 13)]
liftIO $ symbols @?= Left [docSymbolD "A" "type family" SkFunction (R 1 0 1 13)]
, testSessionWait "type family instance " $ do
let source = T.unlines
[ "{-# language TypeFamilies #-}"
Expand All @@ -4173,14 +4173,14 @@ outlineTests = testGroup
docId <- createDoc "A.hs" "haskell" source
symbols <- getDocumentSymbols docId
liftIO $ symbols @?= Left
[ docSymbolD "A a" "type family" SkClass (R 1 0 1 15)
[ docSymbolD "A a" "type family" SkFunction (R 1 0 1 15)
, docSymbol "A ()" SkInterface (R 2 0 2 23)
]
, testSessionWait "data family" $ do
let source = T.unlines ["{-# language TypeFamilies #-}", "data family A"]
docId <- createDoc "A.hs" "haskell" source
symbols <- getDocumentSymbols docId
liftIO $ symbols @?= Left [docSymbolD "A" "data family" SkClass (R 1 0 1 11)]
liftIO $ symbols @?= Left [docSymbolD "A" "data family" SkFunction (R 1 0 1 11)]
, testSessionWait "data family instance " $ do
let source = T.unlines
[ "{-# language TypeFamilies #-}"
Expand All @@ -4190,7 +4190,7 @@ outlineTests = testGroup
docId <- createDoc "A.hs" "haskell" source
symbols <- getDocumentSymbols docId
liftIO $ symbols @?= Left
[ docSymbolD "A a" "data family" SkClass (R 1 0 1 11)
[ docSymbolD "A a" "data family" SkFunction (R 1 0 1 11)
, docSymbol "A ()" SkInterface (R 2 0 2 25)
]
, testSessionWait "constant" $ do
Expand Down Expand Up @@ -4304,7 +4304,7 @@ outlineTests = testGroup
(Just $ List cc)
classSymbol name loc cc = DocumentSymbol name
(Just "class")
SkClass
SkInterface
Nothing
loc
loc
Expand Down

0 comments on commit aad6401

Please sign in to comment.