Skip to content

Commit

Permalink
Remove unused config (#3107)
Browse files Browse the repository at this point in the history
  • Loading branch information
July541 authored Aug 16, 2022
1 parent e55004a commit 92f4bd4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 68 deletions.
2 changes: 0 additions & 2 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ descriptor recorder plId = (defaultPluginDescriptor plId)
, pluginRules = rules recorder
, pluginHandlers = mkPluginHandler STextDocumentCodeAction (codeAction recorder)
<> mkPluginHandler STextDocumentCodeLens codeLens
, pluginConfigDescriptor =
defaultConfigDescriptor { configCustomConfig = mkCustomConfig properties }
}

commands :: PluginId -> [PluginCommand IdeState]
Expand Down
68 changes: 33 additions & 35 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class/CodeLens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,39 @@ import Language.LSP.Types
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 pluginResponse $ do
nfp <- getNormalizedFilePath plId uri
tmr <- handleMaybeM "Unable to typecheck"
$ liftIO
$ runAction "classplugin.TypeCheck" state
$ use TypeCheck nfp

-- All instance binds
InstanceBindTypeSigsResult allBinds <-
handleMaybeM "Unable to get InstanceBindTypeSigsResult"
$ liftIO
$ runAction "classplugin.GetInstanceBindTypeSigs" state
$ use GetInstanceBindTypeSigs nfp

pragmaInsertion <- insertPragmaIfNotPresent state nfp InstanceSigs

let (hsGroup, _, _, _) = tmrRenamed tmr
tycls = hs_tyclds hsGroup
-- declared instance methods without signatures
bindInfos = [ bind
| instds <- map group_instds tycls -- class instance decls
, instd <- instds
, inst <- maybeToList $ getClsInstD (unLoc instd)
, bind <- getBindSpanWithoutSig inst
]
targetSigs = matchBind bindInfos allBinds
makeLens (range, title) =
generateLens plId range title
$ workspaceEdit pragmaInsertion
$ makeEdit range title
codeLens = makeLens <$> mapMaybe getRangeWithSig targetSigs

pure $ List codeLens
codeLens state plId CodeLensParams{..} = pluginResponse $ do
nfp <- getNormalizedFilePath plId uri
tmr <- handleMaybeM "Unable to typecheck"
$ liftIO
$ runAction "classplugin.TypeCheck" state
$ use TypeCheck nfp

-- All instance binds
InstanceBindTypeSigsResult allBinds <-
handleMaybeM "Unable to get InstanceBindTypeSigsResult"
$ liftIO
$ runAction "classplugin.GetInstanceBindTypeSigs" state
$ use GetInstanceBindTypeSigs nfp

pragmaInsertion <- insertPragmaIfNotPresent state nfp InstanceSigs

let (hsGroup, _, _, _) = tmrRenamed tmr
tycls = hs_tyclds hsGroup
-- declared instance methods without signatures
bindInfos = [ bind
| instds <- map group_instds tycls -- class instance decls
, instd <- instds
, inst <- maybeToList $ getClsInstD (unLoc instd)
, bind <- getBindSpanWithoutSig inst
]
targetSigs = matchBind bindInfos allBinds
makeLens (range, title) =
generateLens plId range title
$ workspaceEdit pragmaInsertion
$ makeEdit range title
codeLens = makeLens <$> mapMaybe getRangeWithSig targetSigs

pure $ List codeLens
where
uri = _textDocument ^. J.uri

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

module Ide.Plugin.Class.ExactPrint where

import Control.Lens (Identity)
import Control.Monad.Trans.Maybe
import qualified Data.Text as T
import Development.IDE.GHC.Compat
Expand Down
21 changes: 0 additions & 21 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

Expand All @@ -20,11 +19,7 @@ import Development.IDE.GHC.Compat hiding ((<+>))
import Development.IDE.Graph.Classes
import GHC.Generics
import Ide.Plugin.Class.Utils
import Ide.Plugin.Config
import Ide.Plugin.Properties
import Ide.PluginUtils
import Ide.Types
import Language.LSP.Server

typeLensCommandId :: CommandId
typeLensCommandId = "classplugin.typelens"
Expand Down Expand Up @@ -112,19 +107,3 @@ rules recorder = do
(prettyBindingNameString (printOutputable name) <> " :: " <> T.pack (showDoc ty))
Nothing
instanceBindType _ _ = pure Nothing

properties :: Properties
'[ 'PropertyKey "typelensOn" 'TBoolean]
properties = emptyProperties
& defineBooleanProperty #typelensOn
"Enable type lens on instance methods"
True

getCompletionsConfig :: (MonadLsp Config m) => PluginId -> m ClassConfig
getCompletionsConfig plId =
ClassConfig
<$> usePropertyLsp #typelensOn plId properties

newtype ClassConfig = ClassConfig
{ enableTypeLens :: Bool
}
9 changes: 0 additions & 9 deletions plugins/hls-class-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,6 @@ codeLensTests recorder = testGroup
[ "(==) :: B -> B -> Bool"
, "(==) :: A -> A -> Bool"
]
, testCase "Should no lens if disabled" $ do
runSessionWithServer (classPlugin recorder) testDataDir $ do
sendConfigurationChanged
$ toJSON
$ def { Plugin.plugins = [("class", def { plcConfig = "typelensOn" .= False })] }
doc <- openDoc "CodeLensSimple.hs" "haskell"
lens <- getCodeLenses doc
let titles = map (^. J.title) $ mapMaybe (^. J.command) lens
liftIO $ titles @?= []
, goldenCodeLens recorder "Apply code lens" "CodeLensSimple" 1
, goldenCodeLens recorder "Apply code lens for local class" "LocalClassDefine" 0
, goldenCodeLens recorder "Apply code lens on the same line" "Inline" 0
Expand Down

0 comments on commit 92f4bd4

Please sign in to comment.