diff --git a/plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs b/plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs index 3f7facf668..03c2f11824 100644 --- a/plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs +++ b/plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs @@ -90,7 +90,14 @@ codeLens state plId CodeLensParams{..} = pluginResponse $ do getBindSpanWithoutSig ClsInstDecl{..} = let bindNames = mapMaybe go (bagToList cid_binds) go (L l bind) = case bind of - FunBind{..} -> Just $ L l fun_id + FunBind{..} + -- `Generated` tagged for Template Haskell, + -- here we filter out nonsence generated bindings + -- that are nonsense for displaying code lenses. + -- + -- See https://github.com/haskell/haskell-language-server/issues/3319 + | not $ isGenerated (mg_origin fun_matches) + -> Just $ L l fun_id _ -> Nothing -- Existed signatures' name sigNames = concat $ mapMaybe (\(L _ r) -> getSigName r) cid_sigs diff --git a/plugins/hls-class-plugin/test/Main.hs b/plugins/hls-class-plugin/test/Main.hs index 091a7c0fe4..c8d0dd3d3c 100644 --- a/plugins/hls-class-plugin/test/Main.hs +++ b/plugins/hls-class-plugin/test/Main.hs @@ -88,6 +88,11 @@ codeLensTests = testGroup [ "(==) :: B -> B -> Bool" , "(==) :: A -> A -> Bool" ] + , testCase "No lens for TH" $ do + runSessionWithServer classPlugin testDataDir $ do + doc <- openDoc "TH.hs" "haskell" + lens <- getCodeLenses doc + liftIO $ length lens @?= 0 , goldenCodeLens "Apply code lens" "CodeLensSimple" 1 , goldenCodeLens "Apply code lens for local class" "LocalClassDefine" 0 , goldenCodeLens "Apply code lens on the same line" "Inline" 0 diff --git a/plugins/hls-class-plugin/test/testdata/TH.hs b/plugins/hls-class-plugin/test/testdata/TH.hs new file mode 100644 index 0000000000..c6728db1ce --- /dev/null +++ b/plugins/hls-class-plugin/test/testdata/TH.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE TemplateHaskell #-} + +module TH where + +import THDef + +gen ''Bool True +gen ''Char 'a' diff --git a/plugins/hls-class-plugin/test/testdata/THDef.hs b/plugins/hls-class-plugin/test/testdata/THDef.hs new file mode 100644 index 0000000000..9a4cfcc37f --- /dev/null +++ b/plugins/hls-class-plugin/test/testdata/THDef.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE TemplateHaskell #-} + +module THDef where + +import Language.Haskell.TH +import Language.Haskell.TH.Syntax + +class F a where + f :: a + +gen :: Lift t => Name -> t -> Q [Dec] +gen ty v = [d| instance F $(conT ty) where f = v |] diff --git a/plugins/hls-class-plugin/test/testdata/hie.yaml b/plugins/hls-class-plugin/test/testdata/hie.yaml index 6ac87dc800..8a26fe70c7 100644 --- a/plugins/hls-class-plugin/test/testdata/hie.yaml +++ b/plugins/hls-class-plugin/test/testdata/hie.yaml @@ -1,3 +1,3 @@ cradle: direct: - arguments: [-XHaskell2010, QualifiedA] + arguments: [-XHaskell2010, QualifiedA, THDef]