Skip to content

Commit

Permalink
Qualified name
Browse files Browse the repository at this point in the history
  • Loading branch information
July541 committed Jun 5, 2022
1 parent 80d9861 commit e398907
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import qualified Language.LSP.Types.Lens as J
addMethodPlaceholders :: PluginId -> CommandFunction IdeState AddMinimalMethodsParams
addMethodPlaceholders plId state param@AddMinimalMethodsParams{..} = do
caps <- getClientCapabilities
response $ do
pluginResponse $ do
nfp <- getNormalizedFilePath plId uri
pm <- handleMaybeM "Unable to GetParsedModule"
$ liftIO
Expand Down Expand Up @@ -77,7 +77,7 @@ addMethodPlaceholders plId state param@AddMinimalMethodsParams{..} = do
-- This implementation is ad-hoc in a sense that the diagnostic detection mechanism is
-- sensitive to the format of diagnostic messages from GHC.
codeAction :: PluginMethodHandler IdeState TextDocumentCodeAction
codeAction state plId (CodeActionParams _ _ docId _ context) = response $ do
codeAction state plId (CodeActionParams _ _ docId _ context) = pluginResponse $ do
nfp <- getNormalizedFilePath plId uri
actions <- join <$> mapM (mkActions nfp) methodDiags
pure $ List actions
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import qualified Language.LSP.Types.Lens as J
codeLens :: PluginMethodHandler IdeState TextDocumentCodeLens
codeLens state plId CodeLensParams{..} = do
enabled <- enableTypeLens <$> getCompletionsConfig plId
if not enabled then pure $ pure $ List [] else response $ do
if not enabled then pure $ pure $ List [] else pluginResponse $ do
nfp <- getNormalizedFilePath plId uri
tmr <- handleMaybeM "Unable to typecheak"
$ liftIO
Expand Down
21 changes: 12 additions & 9 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,20 @@ rules recorder = do
(_, maybe [] catMaybes -> instanceBinds) <-
initTcWithGbl hsc gblEnv ghostSpan $ traverse bindToSig binds
pure $ Just $ InstanceBindTypeSigsResult instanceBinds
where
rdrEnv = tcg_rdr_env gblEnv
showDoc ty = showSDocForUser' hsc (mkPrintUnqualifiedDefault hsc rdrEnv) (pprSigmaType ty)

bindToSig id = do
let name = idName id
whenMaybe (isBindingName name) $ do
env <- tcInitTidyEnv
let (_, ty) = tidyOpenType env (idType id)
pure $ InstanceBindTypeSig name
(prettyBindingNameString (printOutputable name) <> " :: " <> T.pack (showDoc ty))
Nothing
instanceBindType _ _ = pure Nothing

bindToSig id = do
let name = idName id
whenMaybe (isBindingName name) $ do
env <- tcInitTidyEnv
let (_, ty) = tidyOpenType env (idType id)
pure $ InstanceBindTypeSig name
(prettyBindingNameString (printOutputable name) <> " :: " <> printOutputable (pprSigmaType ty))
Nothing

properties :: Properties
'[ 'PropertyKey "typelensOn" 'TBoolean]
properties = emptyProperties
Expand Down
1 change: 1 addition & 0 deletions plugins/hls-class-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ codeLensTests = testGroup
, goldenCodeLens "Don't insert pragma while existing" "T13" 0
, onlyRunForGhcVersions [GHC92] "Only ghc-9.2 enabled GHC2021 implicitly" $
goldenCodeLens "Don't insert pragma while GHC2021 enabled" "T14" 0
, goldenCodeLens "Qualified name" "T15" 0
]

_CACodeAction :: Prism' (Command |? CodeAction) CodeAction
Expand Down
10 changes: 10 additions & 0 deletions plugins/hls-class-plugin/test/testdata/T15.expected.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{-# LANGUAGE InstanceSigs #-}
module T15 where
import qualified T15A

class F a where
f :: a

instance F T15A.A where
f :: T15A.A
f = undefined
8 changes: 8 additions & 0 deletions plugins/hls-class-plugin/test/testdata/T15.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module T15 where
import qualified T15A

class F a where
f :: a

instance F T15A.A where
f = undefined
3 changes: 3 additions & 0 deletions plugins/hls-class-plugin/test/testdata/T15A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module T15A where

data A
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]
arguments: [-XHaskell2010, T15A]

0 comments on commit e398907

Please sign in to comment.