Skip to content

Commit e398907

Browse files
committed
Qualified name
1 parent 80d9861 commit e398907

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import qualified Language.LSP.Types.Lens as J
3636
addMethodPlaceholders :: PluginId -> CommandFunction IdeState AddMinimalMethodsParams
3737
addMethodPlaceholders plId state param@AddMinimalMethodsParams{..} = do
3838
caps <- getClientCapabilities
39-
response $ do
39+
pluginResponse $ do
4040
nfp <- getNormalizedFilePath plId uri
4141
pm <- handleMaybeM "Unable to GetParsedModule"
4242
$ liftIO
@@ -77,7 +77,7 @@ addMethodPlaceholders plId state param@AddMinimalMethodsParams{..} = do
7777
-- This implementation is ad-hoc in a sense that the diagnostic detection mechanism is
7878
-- sensitive to the format of diagnostic messages from GHC.
7979
codeAction :: PluginMethodHandler IdeState TextDocumentCodeAction
80-
codeAction state plId (CodeActionParams _ _ docId _ context) = response $ do
80+
codeAction state plId (CodeActionParams _ _ docId _ context) = pluginResponse $ do
8181
nfp <- getNormalizedFilePath plId uri
8282
actions <- join <$> mapM (mkActions nfp) methodDiags
8383
pure $ List actions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import qualified Language.LSP.Types.Lens as J
2525
codeLens :: PluginMethodHandler IdeState TextDocumentCodeLens
2626
codeLens state plId CodeLensParams{..} = do
2727
enabled <- enableTypeLens <$> getCompletionsConfig plId
28-
if not enabled then pure $ pure $ List [] else response $ do
28+
if not enabled then pure $ pure $ List [] else pluginResponse $ do
2929
nfp <- getNormalizedFilePath plId uri
3030
tmr <- handleMaybeM "Unable to typecheak"
3131
$ liftIO

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,20 @@ rules recorder = do
9393
(_, maybe [] catMaybes -> instanceBinds) <-
9494
initTcWithGbl hsc gblEnv ghostSpan $ traverse bindToSig binds
9595
pure $ Just $ InstanceBindTypeSigsResult instanceBinds
96+
where
97+
rdrEnv = tcg_rdr_env gblEnv
98+
showDoc ty = showSDocForUser' hsc (mkPrintUnqualifiedDefault hsc rdrEnv) (pprSigmaType ty)
99+
100+
bindToSig id = do
101+
let name = idName id
102+
whenMaybe (isBindingName name) $ do
103+
env <- tcInitTidyEnv
104+
let (_, ty) = tidyOpenType env (idType id)
105+
pure $ InstanceBindTypeSig name
106+
(prettyBindingNameString (printOutputable name) <> " :: " <> T.pack (showDoc ty))
107+
Nothing
96108
instanceBindType _ _ = pure Nothing
97109

98-
bindToSig id = do
99-
let name = idName id
100-
whenMaybe (isBindingName name) $ do
101-
env <- tcInitTidyEnv
102-
let (_, ty) = tidyOpenType env (idType id)
103-
pure $ InstanceBindTypeSig name
104-
(prettyBindingNameString (printOutputable name) <> " :: " <> printOutputable (pprSigmaType ty))
105-
Nothing
106-
107110
properties :: Properties
108111
'[ 'PropertyKey "typelensOn" 'TBoolean]
109112
properties = emptyProperties

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ codeLensTests = testGroup
9898
, goldenCodeLens "Don't insert pragma while existing" "T13" 0
9999
, onlyRunForGhcVersions [GHC92] "Only ghc-9.2 enabled GHC2021 implicitly" $
100100
goldenCodeLens "Don't insert pragma while GHC2021 enabled" "T14" 0
101+
, goldenCodeLens "Qualified name" "T15" 0
101102
]
102103

103104
_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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module T15 where
2+
import qualified T15A
3+
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: 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)