Skip to content

Commit 375db1c

Browse files
committed
Merge master
2 parents 22fab55 + e398907 commit 375db1c

File tree

11 files changed

+45
-20
lines changed

11 files changed

+45
-20
lines changed

plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ minDefToMethodGroups range sigs = go
202202
where
203203
go (Var mn) = [[ (T.pack . occNameString . occName $ mn, bindRendered sig)
204204
| sig <- sigs
205-
, inRange range (getSrcSpan (bindName sig))
205+
, inRange range (getSrcSpan $ bindName sig)
206206
, printOutputable mn == T.drop (T.length bindingPrefix) (printOutputable (bindName sig))
207207
]]
208208
go (Or ms) = concatMap (go . unLoc) ms

plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ codeLens state plId CodeLensParams{..} = do
8686
-- Existed signatures' name
8787
sigNames = concat $ mapMaybe (\(L _ r) -> getSigName r) cid_sigs
8888
toBindInfo (L l (L l' _)) = BindInfo
89-
(getLoc l) -- bindSpan
90-
(getLoc l') -- bindNameSpan
89+
(locA l) -- bindSpan
90+
(locA l') -- bindNameSpan
9191
in toBindInfo <$> filter (\(L _ name) -> unLoc name `notElem` sigNames) bindNames
9292
getBindSpanWithoutSig _ = []
9393

plugins/hls-class-plugin/src/Ide/Plugin/Class/ExactPrint.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,5 @@ addMethodDecls ps mDecls range withSig = do
118118
foldM (insertAfter d) ps (reverse decls)
119119

120120
findInstDecl :: ParsedSource -> Range -> Transform (LHsDecl GhcPs)
121-
findInstDecl ps range = head . filter (inRange range) <$> hsDecls ps
121+
findInstDecl ps range = head . filter (inRange range . getLoc) <$> hsDecls ps
122122
#endif

plugins/hls-class-plugin/src/Ide/Plugin/Class/Types.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,20 @@ rules recorder = do
9999
(_, maybe [] catMaybes -> instanceBinds) <-
100100
initTcWithGbl hsc gblEnv ghostSpan $ traverse bindToSig binds
101101
pure $ Just $ InstanceBindTypeSigsResult instanceBinds
102+
where
103+
rdrEnv = tcg_rdr_env gblEnv
104+
showDoc ty = showSDocForUser' hsc (mkPrintUnqualifiedDefault hsc rdrEnv) (pprSigmaType ty)
105+
106+
bindToSig id = do
107+
let name = idName id
108+
whenMaybe (isBindingName name) $ do
109+
env <- tcInitTidyEnv
110+
let (_, ty) = tidyOpenType env (idType id)
111+
pure $ InstanceBindTypeSig name
112+
(prettyBindingNameString (printOutputable name) <> " :: " <> T.pack (showDoc ty))
113+
Nothing
102114
instanceBindType _ _ = pure Nothing
103115

104-
bindToSig id = do
105-
let name = idName id
106-
whenMaybe (isBindingName name) $ do
107-
env <- tcInitTidyEnv
108-
let (_, ty) = tidyOpenType env (idType id)
109-
pure $ InstanceBindTypeSig name
110-
(prettyBindingNameString (printOutputable name) <> " :: " <> printOutputable (pprSigmaType ty))
111-
Nothing
112-
113116
properties :: Properties
114117
'[ 'PropertyKey "typelensOn" 'TBoolean]
115118
properties = emptyProperties

plugins/hls-class-plugin/src/Ide/Plugin/Class/Utils.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ isBindingName :: Name -> Bool
2525
isBindingName name = isPrefixOf bindingPrefix $ occNameString $ nameOccName name
2626

2727
-- | Check if some `HasSrcSpan` value in the given range
28-
inRange :: HasSrcSpan a => Range -> a -> Bool
29-
inRange range s = maybe False (subRange range) (srcSpanToRange (getLoc s))
28+
inRange :: Range -> SrcSpan -> Bool
29+
inRange range s = maybe False (subRange range) (srcSpanToRange s)
3030

3131
ghostSpan :: RealSrcSpan
3232
ghostSpan = realSrcLocSpan $ mkRealSrcLoc (fsLit "<haskell-language-sever>") 1 1

plugins/hls-class-plugin/test/Main.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ codeActionTests recorder = testGroup
7070
, goldenWithClass recorder "Creates a placeholder for other two methods" "T6" "2" $ \(_:_:ghAction:_) -> do
7171
executeCodeAction ghAction
7272
, onlyRunForGhcVersions [GHC92] "Only ghc-9.2 enabled GHC2021 implicitly" $
73-
goldenWithClass recorder "Don't insert pragma with GHC2021" "T15" "" $ \(_:eqWithSig:_) -> do
73+
goldenWithClass recorder "Don't insert pragma with GHC2021" "T16" "" $ \(_:eqWithSig:_) -> do
7474
executeCodeAction eqWithSig
7575
, goldenWithClass recorder "Insert pragma if not exist" "T7" "" $ \(_:eqWithSig:_) -> do
7676
executeCodeAction eqWithSig
@@ -107,6 +107,7 @@ codeLensTests recorder = testGroup
107107
, goldenCodeLens recorder "Don't insert pragma while existing" "T13" 0
108108
, onlyRunForGhcVersions [GHC92] "Only ghc-9.2 enabled GHC2021 implicitly" $
109109
goldenCodeLens recorder "Don't insert pragma while GHC2021 enabled" "T14" 0
110+
, goldenCodeLens recorder "Qualified name" "T15" 0
110111
]
111112

112113
_CACodeAction :: Prism' (Command |? CodeAction) CodeAction
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-# LANGUAGE InstanceSigs #-}
2+
module T15 where
3+
import qualified T15A
4+
5+
class F a where
6+
f :: a
7+
8+
instance F T15A.A where
9+
f :: T15A.A
10+
f = undefined
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{-# LANGUAGE GHC2021#-}
21
module T15 where
2+
import qualified T15A
33

4-
data A
5-
instance Eq A
4+
class F a where
5+
f :: a
6+
7+
instance F T15A.A where
8+
f = undefined
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module T15A where
2+
3+
data A
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE GHC2021#-}
2+
module T16 where
3+
4+
data A
5+
instance Eq A
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
cradle:
22
direct:
3-
arguments: [-XHaskell2010]
3+
arguments: [-XHaskell2010, T15A]

0 commit comments

Comments
 (0)