Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions hie-plugin-api/Haskell/Ide/Engine/PluginDescriptor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Haskell.Ide.Engine.MonadTypes

pluginDescToIdePlugins :: [(PluginId,PluginDescriptor)] -> IdePlugins
pluginDescToIdePlugins = IdePlugins . foldr (uncurry Map.insert . f) Map.empty
where f = fmap pluginCommands
where f = fmap (\x -> (pluginCommands x, pluginCodeActionProvider x))

type DynamicJSON = CD.ConstrainedDynamic ToJSON

Expand All @@ -48,7 +48,7 @@ runPluginCommand p com arg = do
case Map.lookup p m of
Nothing -> return $
IdeResultFail $ IdeError UnknownPlugin ("Plugin " <> p <> " doesn't exist") Null
Just xs -> case find ((com ==) . commandName) xs of
Just (xs, _) -> case find ((com ==) . commandName) xs of
Nothing -> return $ IdeResultFail $
IdeError UnknownCommand ("Command " <> com <> " isn't defined for plugin " <> p <> ". Legal commands are: " <> T.pack(show $ map commandName xs)) Null
Just (PluginCommand _ _ (CmdSync f)) -> case fromJSON arg of
Expand Down
27 changes: 21 additions & 6 deletions hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module Haskell.Ide.Engine.PluginsIdeMonads
, CommandFunc(..)
, PluginDescriptor(..)
, PluginCommand(..)
, CodeActionProvider
, noCodeActions
, IdePlugins(..)
-- * The IDE monad
, IdeGhcM
Expand Down Expand Up @@ -69,7 +71,9 @@ import Haskell.Ide.Engine.MultiThreadState
import Haskell.Ide.Engine.GhcModuleCache

import Language.Haskell.LSP.Types.Capabilities
import Language.Haskell.LSP.Types (Diagnostic (..),
import Language.Haskell.LSP.Types (CodeAction(..),
CodeActionContext(..),
Diagnostic (..),
DiagnosticSeverity (..),
List (..),
Location (..),
Expand All @@ -79,6 +83,7 @@ import Language.Haskell.LSP.Types (Diagnostic (..),
TextDocumentIdentifier (..),
TextDocumentPositionParams (..),
Uri (..),
VersionedTextDocumentIdentifier(..),
WorkspaceEdit (..),
filePathToUri,
uriToFilePath)
Expand All @@ -95,22 +100,32 @@ data PluginCommand = forall a b. (FromJSON a, ToJSON b, Typeable b) =>
, commandFunc :: CommandFunc a b
}

type CodeActionProvider = VersionedTextDocumentIdentifier
-> Maybe FilePath -- ^ Project root directory
-> Range
-> CodeActionContext
-> IdeM (IdeResponse [CodeAction])

data PluginDescriptor =
PluginDescriptor { pluginName :: T.Text
, pluginDesc :: T.Text
, pluginCommands :: [PluginCommand]
} deriving (Show,Generic)
, pluginCodeActionProvider :: CodeActionProvider
} deriving (Generic)

instance Show PluginCommand where
show (PluginCommand name _ _) = "PluginCommand { name = " ++ T.unpack name ++ " }"

-- | a Description of the available commands stored in IdeGhcM
noCodeActions :: CodeActionProvider
noCodeActions _ _ _ _ = return $ IdeResponseOk []

-- | a Description of the available commands and code action providers stored in IdeGhcM
newtype IdePlugins = IdePlugins
{ ipMap :: Map.Map PluginId [PluginCommand]
} deriving (Show,Generic)
{ ipMap :: Map.Map PluginId ([PluginCommand], CodeActionProvider)
} deriving (Generic)

instance ToJSON IdePlugins where
toJSON (IdePlugins m) = toJSON $ (fmap . fmap) (\x -> (commandName x, commandDesc x)) m
toJSON (IdePlugins m) = toJSON $ fmap (\x -> (commandName x, commandDesc x)) <$> fmap fst m

-- ---------------------------------------------------------------------

Expand Down
Loading