git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Ensure type class members can be completed in psci

Descend into type class declarations when searching for declarations to use for completion, so that type class member functions appear in the results.

commitaa36eb6b5037eab2cc712572d928fb753714874b authorHarry Garrood <harry@garrood.me> dateWed 29 Jul 2015, 13:27 (11 years ago) parentfb399dd
1 file changed+9−6
psci/Completion.hs+9−6
psci/Completion.hs+9−6
@@ -6,6 +6,7 @@ import Data.Char (isUpper)
66import Data.Function (on)
77import Data.Traversable (traverse)
88
9+import Control.Arrow (second)
910import Control.Applicative ((<$>), (<*>))
1011import Control.Monad.Trans.Reader (asks, runReaderT, ReaderT)
1112import Control.Monad.Trans.State.Strict
@@ -196,13 +197,15 @@ typeDecls = mapMaybe getTypeName . filter P.isDataDecl . P.exportedDeclarations
196197 getTypeName _ = Nothing
197198
198199identNames :: P.Module -> [(N.Ident, P.Declaration)]
199−identNames = nubOnFst . mapMaybe getDeclName . P.exportedDeclarations
200+identNames = nubOnFst . concatMap getDeclNames . P.exportedDeclarations
200201 where
201− getDeclName :: P.Declaration -> Maybe (P.Ident, P.Declaration)
202− getDeclName d@(P.ValueDeclaration ident _ _ _) = Just (ident, d)
203− getDeclName d@(P.ExternDeclaration ident _) = Just (ident, d)
204− getDeclName (P.PositionedDeclaration _ _ d) = getDeclName d
205− getDeclName _ = Nothing
202+ getDeclNames :: P.Declaration -> [(P.Ident, P.Declaration)]
203+ getDeclNames d@(P.ValueDeclaration ident _ _ _) = [(ident, d)]
204+ getDeclNames d@(P.TypeDeclaration ident _ ) = [(ident, d)]
205+ getDeclNames d@(P.ExternDeclaration ident _) = [(ident, d)]
206+ getDeclNames d@(P.TypeClassDeclaration _ _ _ ds) = map (second (const d)) $ concatMap getDeclNames ds
207+ getDeclNames (P.PositionedDeclaration _ _ d) = getDeclNames d
208+ getDeclNames _ = []
206209
207210dctorNames :: P.Module -> [(N.ProperName, P.Declaration)]
208211dctorNames = nubOnFst . concatMap go . P.exportedDeclarations