Skip to content

Commit c276978

Browse files
committed
Extract the block command handler to an HLS plugin
Previously defined together with the type lenses command handler
1 parent 704b21d commit c276978

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

ghcide/exe/Main.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ main = do
8888

8989
dir <- IO.getCurrentDirectory
9090

91-
let hlsPlugins = pluginDescToIdePlugins
91+
let hlsPlugins = pluginDescToIdePlugins $
9292
[ GhcIde.descriptor "ghcide"
93-
, TypeLenses.descriptor "type-lenses" ]
93+
, TypeLenses.descriptor "type-lenses"
94+
] ++
95+
[ Test.blockCommandDescriptor "block-command" | argsTesting]
9496

9597
pid <- T.pack . show <$> getProcessID
9698
let hlsPlugin = asGhcIdePlugin hlsPlugins

ghcide/src/Development/IDE/Plugin/CodeAction.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module Development.IDE.Plugin.CodeAction
1313
, rulePackageExports
1414

1515
-- * For testing
16-
, blockCommandId
1716
, matchRegExMultipleImports
1817
) where
1918

@@ -57,9 +56,6 @@ import Control.Concurrent.Extra (readVar)
5756
import Development.IDE.GHC.Util (printRdrName)
5857
import Ide.PluginUtils (subRange)
5958

60-
-- | a command that blocks forever. Used for testing
61-
blockCommandId :: T.Text
62-
blockCommandId = "ghcide.command.block"
6359
-- | Generate code actions.
6460
codeAction
6561
:: LSP.LspFuncs c

ghcide/src/Development/IDE/Plugin/Test.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Development.IDE.Plugin.Test
55
( TestRequest(..)
66
, WaitForIdeRuleResult(..)
77
, plugin
8+
, blockCommandDescriptor
9+
, blockCommandId
810
) where
911

1012
import Control.Monad.STM
@@ -32,6 +34,9 @@ import Data.Bifunctor
3234
import Data.Text (pack, Text)
3335
import Data.String
3436
import Development.IDE.Types.Location (fromUri)
37+
import Control.Concurrent (threadDelay)
38+
import Ide.Types
39+
import qualified Language.Haskell.LSP.Core as LSP
3540

3641
data TestRequest
3742
= BlockSeconds Seconds -- ^ :: Null
@@ -104,3 +109,20 @@ parseAction "gethieast" fp = Right . isJust <$> use GetHieAst fp
104109
parseAction "getDependencies" fp = Right . isJust <$> use GetDependencies fp
105110
parseAction "getFileContents" fp = Right . isJust <$> use GetFileContents fp
106111
parseAction other _ = return $ Left $ "Cannot parse ide rule: " <> pack (original other)
112+
113+
-- | a command that blocks forever. Used for testing
114+
blockCommandId :: Text
115+
blockCommandId = "ghcide.command.block"
116+
117+
blockCommandDescriptor :: PluginId -> PluginDescriptor state
118+
blockCommandDescriptor plId = (defaultPluginDescriptor plId) {
119+
pluginCommands = [PluginCommand (CommandId blockCommandId) "blocks forever" blockCommandHandler]
120+
}
121+
122+
blockCommandHandler :: CommandFunction state ExecuteCommandParams
123+
blockCommandHandler lsp _ideState _params
124+
= do
125+
LSP.sendFunc lsp $ NotCustomServer $
126+
NotificationMessage "2.0" (CustomServerMethod "ghcide/blocking/command") Null
127+
threadDelay maxBound
128+
return (Right Null, Nothing)

ghcide/test/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ import Test.Tasty.Ingredients.Rerun
6060
import Test.Tasty.HUnit
6161
import Test.Tasty.QuickCheck
6262
import System.Time.Extra
63-
import Development.IDE.Plugin.Test (WaitForIdeRuleResult(..), TestRequest(BlockSeconds,GetInterfaceFilesDir))
6463
import Development.IDE.Plugin.CodeAction (matchRegExMultipleImports)
64+
import Development.IDE.Plugin.Test (TestRequest (BlockSeconds, GetInterfaceFilesDir), WaitForIdeRuleResult (..), blockCommandId)
6565
import Control.Monad.Extra (whenJust)
6666
import qualified Language.Haskell.LSP.Types.Lens as L
6767
import Control.Lens ((^.))

0 commit comments

Comments
 (0)