Skip to content

Break down ghcide functionality in HLS plugins #1257

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

Merged
merged 8 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Extract the block command handler to an HLS plugin
Previously defined together with the type lenses command handler
  • Loading branch information
pepeiborra committed Jan 24, 2021
commit c27697899896535c4967144aea46d1483202a8ea
6 changes: 4 additions & 2 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ main = do

dir <- IO.getCurrentDirectory

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

pid <- T.pack . show <$> getProcessID
let hlsPlugin = asGhcIdePlugin hlsPlugins
Expand Down
4 changes: 0 additions & 4 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Development.IDE.Plugin.CodeAction
, rulePackageExports

-- * For testing
, blockCommandId
, matchRegExMultipleImports
) where

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

-- | a command that blocks forever. Used for testing
blockCommandId :: T.Text
blockCommandId = "ghcide.command.block"
-- | Generate code actions.
codeAction
:: LSP.LspFuncs c
Expand Down
22 changes: 22 additions & 0 deletions ghcide/src/Development/IDE/Plugin/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Development.IDE.Plugin.Test
( TestRequest(..)
, WaitForIdeRuleResult(..)
, plugin
, blockCommandDescriptor
, blockCommandId
) where

import Control.Monad.STM
Expand Down Expand Up @@ -32,6 +34,9 @@ import Data.Bifunctor
import Data.Text (pack, Text)
import Data.String
import Development.IDE.Types.Location (fromUri)
import Control.Concurrent (threadDelay)
import Ide.Types
import qualified Language.Haskell.LSP.Core as LSP

data TestRequest
= BlockSeconds Seconds -- ^ :: Null
Expand Down Expand Up @@ -104,3 +109,20 @@ parseAction "gethieast" fp = Right . isJust <$> use GetHieAst fp
parseAction "getDependencies" fp = Right . isJust <$> use GetDependencies fp
parseAction "getFileContents" fp = Right . isJust <$> use GetFileContents fp
parseAction other _ = return $ Left $ "Cannot parse ide rule: " <> pack (original other)

-- | a command that blocks forever. Used for testing
blockCommandId :: Text
blockCommandId = "ghcide.command.block"

blockCommandDescriptor :: PluginId -> PluginDescriptor state
blockCommandDescriptor plId = (defaultPluginDescriptor plId) {
pluginCommands = [PluginCommand (CommandId blockCommandId) "blocks forever" blockCommandHandler]
}

blockCommandHandler :: CommandFunction state ExecuteCommandParams
blockCommandHandler lsp _ideState _params
= do
LSP.sendFunc lsp $ NotCustomServer $
NotificationMessage "2.0" (CustomServerMethod "ghcide/blocking/command") Null
threadDelay maxBound
return (Right Null, Nothing)
2 changes: 1 addition & 1 deletion ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ import Test.Tasty.Ingredients.Rerun
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck
import System.Time.Extra
import Development.IDE.Plugin.Test (WaitForIdeRuleResult(..), TestRequest(BlockSeconds,GetInterfaceFilesDir))
import Development.IDE.Plugin.CodeAction (matchRegExMultipleImports)
import Development.IDE.Plugin.Test (TestRequest (BlockSeconds, GetInterfaceFilesDir), WaitForIdeRuleResult (..), blockCommandId)
import Control.Monad.Extra (whenJust)
import qualified Language.Haskell.LSP.Types.Lens as L
import Control.Lens ((^.))
Expand Down