@@ -6,6 +6,7 @@ module Development.IDE.Plugin.TypeLenses
6
6
)
7
7
where
8
8
9
+ import ConLike (ConLike (PatSynCon ))
9
10
import Control.Applicative ((<|>) )
10
11
import Control.Monad.IO.Class
11
12
import Data.Aeson.Types (Value (.. ), toJSON )
@@ -94,29 +95,30 @@ commandHandler _ideState wedit = do
94
95
return $ Right Null
95
96
96
97
suggestSignature :: Bool -> Maybe TcModuleResult -> Maybe Bindings -> Diagnostic -> [(T. Text , [TextEdit ])]
97
- suggestSignature isQuickFix mTmr mBindings Diagnostic {_message, _range = _range @ Range {.. }}
98
+ suggestSignature isQuickFix mTmr mBindings Diagnostic {_message, _range = Range {.. }}
98
99
| _message
99
100
=~ (" (Top-level binding|Polymorphic local binding|Pattern synonym) with no type signature" :: T. Text ),
100
101
Just bindings <- mBindings,
101
102
Just TcModuleResult {tmrTypechecked = TcGblEnv {tcg_type_env, tcg_rn_decls, tcg_rdr_env}} <- mTmr,
102
103
localScope <- getFuzzyScope bindings _start _end,
103
104
Just group <- tcg_rn_decls,
104
105
Just name <- getFirstIdAtLine (succ $ _line _start) group,
105
- Just ty <- (lookupTypeEnv tcg_type_env name >>= safeTyThingType) <|> (find (\ (x, _) -> x == name) localScope >>= snd ),
106
+ Just (isPatSyn, ty) <-
107
+ (lookupTypeEnv tcg_type_env name >>= \ x -> (isTyThingPatSyn x,) <$> safeTyThingType x)
108
+ <|> ((False ,) <$> (find (\ (x, _) -> x == name) localScope >>= snd )),
106
109
tyMsg <- showSDocForUser unsafeGlobalDynFlags (mkPrintUnqualified unsafeGlobalDynFlags tcg_rdr_env) $ pprSigmaType ty,
107
- signature <- T. pack $ printName name <> " :: " <> tyMsg,
110
+ signature <- T. pack $ (if isPatSyn then " pattern " else " " ) <> printName name <> " :: " <> tyMsg,
111
+ startCharacter <- if " local binding" `T.isInfixOf` _message then _character _start else 0 ,
108
112
startOfLine <- Position (_line _start) startCharacter,
109
113
beforeLine <- Range startOfLine startOfLine,
110
114
title <- if isQuickFix then " add signature: " <> signature else signature,
111
115
action <- TextEdit beforeLine $ signature <> " \n " <> T. replicate startCharacter " " =
112
116
[(title, [action])]
113
117
| otherwise = []
114
- where
115
- startCharacter
116
- | " Polymorphic local binding" `T.isPrefixOf` _message =
117
- _character _start
118
- | otherwise =
119
- 0
118
+
119
+ isTyThingPatSyn :: TyThing -> Bool
120
+ isTyThingPatSyn (AConLike (PatSynCon _)) = True
121
+ isTyThingPatSyn _ = False
120
122
121
123
getFirstIdAtLine :: Int -> HsGroup GhcRn -> Maybe Name
122
124
getFirstIdAtLine line = something (mkQ Nothing f)
0 commit comments