Skip to content

Commit b7cb765

Browse files
authored
Don't show lenses for TH generated instances (#3531)
1 parent 014c8f9 commit b7cb765

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ codeLens state plId CodeLensParams{..} = pluginResponse $ do
9090
getBindSpanWithoutSig ClsInstDecl{..} =
9191
let bindNames = mapMaybe go (bagToList cid_binds)
9292
go (L l bind) = case bind of
93-
FunBind{..} -> Just $ L l fun_id
93+
FunBind{..}
94+
-- `Generated` tagged for Template Haskell,
95+
-- here we filter out nonsence generated bindings
96+
-- that are nonsense for displaying code lenses.
97+
--
98+
-- See https://github.com/haskell/haskell-language-server/issues/3319
99+
| not $ isGenerated (mg_origin fun_matches)
100+
-> Just $ L l fun_id
94101
_ -> Nothing
95102
-- Existed signatures' name
96103
sigNames = concat $ mapMaybe (\(L _ r) -> getSigName r) cid_sigs

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ codeLensTests = testGroup
8888
[ "(==) :: B -> B -> Bool"
8989
, "(==) :: A -> A -> Bool"
9090
]
91+
, testCase "No lens for TH" $ do
92+
runSessionWithServer classPlugin testDataDir $ do
93+
doc <- openDoc "TH.hs" "haskell"
94+
lens <- getCodeLenses doc
95+
liftIO $ length lens @?= 0
9196
, goldenCodeLens "Apply code lens" "CodeLensSimple" 1
9297
, goldenCodeLens "Apply code lens for local class" "LocalClassDefine" 0
9398
, goldenCodeLens "Apply code lens on the same line" "Inline" 0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
module TH where
4+
5+
import THDef
6+
7+
gen ''Bool True
8+
gen ''Char 'a'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
module THDef where
4+
5+
import Language.Haskell.TH
6+
import Language.Haskell.TH.Syntax
7+
8+
class F a where
9+
f :: a
10+
11+
gen :: Lift t => Name -> t -> Q [Dec]
12+
gen ty v = [d| instance F $(conT ty) where f = v |]
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, QualifiedA]
3+
arguments: [-XHaskell2010, QualifiedA, THDef]

0 commit comments

Comments
 (0)