Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show lenses for TH generated instances #3531

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions plugins/hls-class-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions plugins/hls-class-plugin/test/testdata/TH.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{-# LANGUAGE TemplateHaskell #-}

module TH where

import THDef

gen ''Bool True
gen ''Char 'a'
12 changes: 12 additions & 0 deletions plugins/hls-class-plugin/test/testdata/THDef.hs
Original file line number Diff line number Diff line change
@@ -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 |]
2 changes: 1 addition & 1 deletion plugins/hls-class-plugin/test/testdata/hie.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cradle:
direct:
arguments: [-XHaskell2010, QualifiedA]
arguments: [-XHaskell2010, QualifiedA, THDef]