Skip to content

Commit d6a9b72

Browse files
committed
Fix pattern synonym, add tests
1 parent bc24187 commit d6a9b72

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

ghcide/src/Development/IDE/Plugin/TypeLenses.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Development.IDE.Plugin.TypeLenses
66
)
77
where
88

9+
import ConLike (ConLike (PatSynCon))
910
import Control.Applicative ((<|>))
1011
import Control.Monad.IO.Class
1112
import Data.Aeson.Types (Value (..), toJSON)
@@ -94,29 +95,30 @@ commandHandler _ideState wedit = do
9495
return $ Right Null
9596

9697
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 {..}}
9899
| _message
99100
=~ ("(Top-level binding|Polymorphic local binding|Pattern synonym) with no type signature" :: T.Text),
100101
Just bindings <- mBindings,
101102
Just TcModuleResult {tmrTypechecked = TcGblEnv {tcg_type_env, tcg_rn_decls, tcg_rdr_env}} <- mTmr,
102103
localScope <- getFuzzyScope bindings _start _end,
103104
Just group <- tcg_rn_decls,
104105
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)),
106109
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,
108112
startOfLine <- Position (_line _start) startCharacter,
109113
beforeLine <- Range startOfLine startOfLine,
110114
title <- if isQuickFix then "add signature: " <> signature else signature,
111115
action <- TextEdit beforeLine $ signature <> "\n" <> T.replicate startCharacter " " =
112116
[(title, [action])]
113117
| 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
120122

121123
getFirstIdAtLine :: Int -> HsGroup GhcRn -> Maybe Name
122124
getFirstIdAtLine line = something (mkQ Nothing f)

ghcide/test/exe/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,8 @@ addSigLensesTests = let
31833183
, sigSession enableWarnings "a `haha` b = a b" "haha :: (t1 -> t2) -> t1 -> t2"
31843184
, sigSession enableWarnings "pattern Some a = Just a" "pattern Some :: a -> Maybe a"
31853185
, sigSession enableWarnings "qualifiedSigTest= C.realPart" "qualifiedSigTest :: C.Complex a -> a"
3186+
, sigSession enableWarnings "head = 233" "head :: Integer"
3187+
, sigSession enableWarnings "a *.* b = a b" "(*.*) :: (t1 -> t2) -> t1 -> t2"
31863188
]
31873189
| (title, enableWarnings) <-
31883190
[("with warnings enabled", True)

haskell-language-server.cabal

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,52 +105,52 @@ flag all-formatters
105105

106106
flag class
107107
description: Enable class plugin
108-
default: True
108+
default: False
109109
manual: False
110110

111111
flag haddockComments
112112
description: Enable haddockComments plugin
113-
default: True
113+
default: False
114114
manual: False
115115

116116
flag eval
117117
description: Enable eval plugin
118-
default: True
118+
default: False
119119
manual: False
120120

121121
flag importLens
122122
description: Enable importLens plugin
123-
default: True
123+
default: False
124124
manual: False
125125

126126
flag retrie
127127
description: Enable retrie plugin
128-
default: True
128+
default: False
129129
manual: False
130130

131131
flag tactic
132132
description: Enable tactic plugin
133-
default: True
133+
default: False
134134
manual: False
135135

136136
flag hlint
137137
description: Enable hlint plugin
138-
default: True
138+
default: False
139139
manual: False
140140

141141
flag moduleName
142142
description: Enable moduleName plugin
143-
default: True
143+
default: False
144144
manual: True
145145

146146
flag pragmas
147147
description: Enable pragmas plugin
148-
default: True
148+
default: False
149149
manual: True
150150

151151
flag splice
152152
description: Enable splice plugin
153-
default: True
153+
default: False
154154
manual: False
155155

156156
-- formatters

0 commit comments

Comments
 (0)