Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 0a347bb

Browse files
committed
Remove command descriptions
Also only needed by the JSON transport
1 parent 25e1f76 commit 0a347bb

File tree

11 files changed

+26
-29
lines changed

11 files changed

+26
-29
lines changed

hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs

+3-4
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,13 @@ data PluginDescriptor =
271271
} deriving (Generic)
272272

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

276276
type PluginId = T.Text
277277
type CommandName = T.Text
278278

279279
data PluginCommand = forall a b. (FromJSON a, ToJSON b, Typeable b) =>
280280
PluginCommand { commandName :: CommandName
281-
, commandDesc :: T.Text
282281
, commandFunc :: a -> IdeGhcM (IdeResult b)
283282
}
284283

@@ -308,7 +307,7 @@ runPluginCommand p com arg = do
308307
Just PluginDescriptor { pluginCommands = xs } -> case List.find ((com ==) . commandName) xs of
309308
Nothing -> return $ IdeResultFail $
310309
IdeError UnknownCommand ("Command " <> com <> " isn't defined for plugin " <> p <> ". Legal commands are: " <> T.pack(show $ map commandName xs)) Null
311-
Just (PluginCommand _ _ f) -> case fromJSON arg of
310+
Just (PluginCommand _ f) -> case fromJSON arg of
312311
Error err -> return $ IdeResultFail $
313312
IdeError ParameterError ("error while parsing args for " <> com <> " in plugin " <> p <> ": " <> T.pack err) Null
314313
Success a -> do
@@ -323,7 +322,7 @@ newtype IdePlugins = IdePlugins
323322
-- TODO:AZ this is a defective instance, do we actually need it?
324323
-- Perhaps rather make a separate type explicitly for this purpose.
325324
instance ToJSON IdePlugins where
326-
toJSON (IdePlugins m) = toJSON $ fmap (\x -> (commandName x, commandDesc x)) <$> fmap pluginCommands m
325+
toJSON (IdePlugins m) = toJSON $ fmap commandName <$> fmap pluginCommands m
327326

328327
-- | For the diagnostic providers in the config, return a map of
329328
-- current enabled state, indexed by the plugin id.

src/Haskell/Ide/Engine/Plugin/ApplyRefact.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ applyRefactDescriptor :: PluginId -> PluginDescriptor
4242
applyRefactDescriptor plId = PluginDescriptor
4343
{ pluginId = plId
4444
, pluginCommands =
45-
[ PluginCommand "applyOne" "Apply a single hint" applyOneCmd
46-
, PluginCommand "applyAll" "Apply all hints to the file" applyAllCmd
45+
[ PluginCommand "applyOne" applyOneCmd
46+
, PluginCommand "applyAll" applyAllCmd
4747
]
4848
, pluginCodeActionProvider = Just codeActionProvider
4949
, pluginDiagnosticProvider = Nothing

src/Haskell/Ide/Engine/Plugin/Example2.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ example2Descriptor :: PluginId -> PluginDescriptor
2323
example2Descriptor plId = PluginDescriptor
2424
{ pluginId = plId
2525
, pluginCommands =
26-
[ PluginCommand "sayHello" "say hello" sayHelloCmd
27-
, PluginCommand "sayHelloTo ""say hello to the passed in param" sayHelloToCmd
28-
, PluginCommand "todo" "Add a TODO marker" todoCmd
26+
[ PluginCommand "sayHello" sayHelloCmd
27+
, PluginCommand "sayHelloTo" sayHelloToCmd
28+
, PluginCommand "todo" todoCmd
2929
]
3030
, pluginCodeActionProvider = Just codeActionProvider
3131
, pluginDiagnosticProvider

src/Haskell/Ide/Engine/Plugin/Generic.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import PprTyThing
4343
genericDescriptor :: PluginId -> PluginDescriptor
4444
genericDescriptor plId = PluginDescriptor
4545
{ pluginId = plId
46-
, pluginCommands = [PluginCommand "type" "Get the type of the expression under (LINE,COL)" typeCmd]
46+
, pluginCommands = [PluginCommand "type" typeCmd]
4747
, pluginCodeActionProvider = Just codeActionProvider
4848
, pluginDiagnosticProvider = Nothing
4949
, pluginHoverProvider = Just hoverProvider

src/Haskell/Ide/Engine/Plugin/HfaAlign.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ hfaAlignDescriptor :: PluginId -> PluginDescriptor
2929
hfaAlignDescriptor plId = PluginDescriptor
3030
{ pluginId = plId
3131
, pluginCommands =
32-
[ PluginCommand "align" "Align = in active range" alignCmd
32+
[ PluginCommand "align" alignCmd
3333
]
3434
, pluginCodeActionProvider = Just codeActionProvider
3535
, pluginDiagnosticProvider = Nothing

src/Haskell/Ide/Engine/Plugin/HsImport.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import qualified Safe as S
3131
hsimportDescriptor :: PluginId -> PluginDescriptor
3232
hsimportDescriptor plId = PluginDescriptor
3333
{ pluginId = plId
34-
, pluginCommands = [PluginCommand "import" "Import a module" importModule]
34+
, pluginCommands = [PluginCommand "import" importModule]
3535
, pluginCodeActionProvider = Just codeActionProvider
3636
, pluginDiagnosticProvider = Nothing
3737
, pluginHoverProvider = Nothing

src/Haskell/Ide/Engine/Plugin/Package.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import qualified Data.Yaml as Y
5353
packageDescriptor :: T.Text -> PluginDescriptor
5454
packageDescriptor plId = PluginDescriptor
5555
{ pluginId = plId
56-
, pluginCommands = [PluginCommand "add" "Add a packge" addCmd]
56+
, pluginCommands = [PluginCommand "add" addCmd]
5757
, pluginCodeActionProvider = Just codeActionProvider
5858
, pluginDiagnosticProvider = Nothing
5959
, pluginHoverProvider = Nothing

src/Haskell/Ide/Engine/Plugin/Pragmas.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pragmasDescriptor :: PluginId -> PluginDescriptor
1919
pragmasDescriptor plId = PluginDescriptor
2020
{ pluginId = plId
2121
, pluginCommands =
22-
[ PluginCommand "addPragma" "add the given pragma" addPragmaCmd
22+
[ PluginCommand "addPragma" addPragmaCmd
2323
]
2424
, pluginCodeActionProvider = Just codeActionProvider
2525
, pluginDiagnosticProvider = Nothing

test/dispatcher/Main.hs

+9-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import qualified Data.Text as T
1313
import Data.Default
1414
import GHC ( TypecheckedModule )
1515
import GHC.Generics
16+
import Haskell.Ide.Engine.Ghc
1617
import Haskell.Ide.Engine.MonadTypes
1718
import Haskell.Ide.Engine.PluginUtils
1819
import Haskell.Ide.Engine.Scheduler
@@ -33,7 +34,6 @@ import System.IO
3334
import Haskell.Ide.Engine.Plugin.ApplyRefact
3435
import Haskell.Ide.Engine.Plugin.Example2
3536
-- import Haskell.Ide.Engine.Plugin.HaRe
36-
import Haskell.Ide.Engine.Plugin.Bios
3737
import Haskell.Ide.Engine.Plugin.Generic
3838

3939
{-# ANN module ("HLint: ignore Redundant do" :: String) #-}
@@ -64,7 +64,6 @@ plugins :: IdePlugins
6464
plugins = pluginDescToIdePlugins
6565
[applyRefactDescriptor "applyrefact"
6666
,example2Descriptor "eg2"
67-
,biosDescriptor "bios"
6867
]
6968

7069
startServer :: IO (Scheduler IO, TChan LogVal, ThreadId)
@@ -90,17 +89,17 @@ logToChan c t = atomically $ writeTChan c t
9089

9190
-- ---------------------------------------------------------------------
9291

93-
dispatchGhcRequest :: ToJSON a
92+
dispatchGhcRequest :: (Typeable a, ToJSON a)
9493
=> TrackingNumber -> Maybe Uri -> String -> Int
9594
-> Scheduler IO -> TChan LogVal
96-
-> PluginId -> CommandName -> a -> IO ()
97-
dispatchGhcRequest tn uri ctx n scheduler lc plugin com arg = do
95+
-> IdeGhcM (IdeResult a) -> IO ()
96+
dispatchGhcRequest tn uri ctx n scheduler lc f = do
9897
let
9998
logger :: RequestCallback IO DynamicJSON
10099
logger x = logToChan lc (ctx, Right x)
101100

102101
let req = GReq tn "plugin-command" uri Nothing (Just (IdInt n)) logger (toDynJSON (Nothing :: Maybe ())) $
103-
runPluginCommand plugin com (toJSON arg)
102+
fmap toDynJSON <$> f
104103
sendRequest scheduler req
105104

106105

@@ -163,7 +162,7 @@ funcSpec = describe "functional dispatch" $ do
163162
show rrr `shouldBe` "Nothing"
164163

165164
-- need to typecheck the module to trigger deferred response
166-
dispatchGhcRequest 2 (Just testUri) "req2" 2 scheduler logChan "bios" "check" (toJSON testUri)
165+
dispatchGhcRequest 2 (Just testUri) "req2" 2 scheduler logChan $ setTypecheckedModule testUri
167166

168167
-- And now we get the deferred response (once the module is loaded)
169168
("req1",Right res) <- atomically $ readTChan logChan
@@ -245,7 +244,7 @@ funcSpec = describe "functional dispatch" $ do
245244

246245
it "returns hints as diagnostics" $ do
247246

248-
dispatchGhcRequest 5 (Just testUri) "r5" 5 scheduler logChan "applyrefact" "lint" testUri
247+
dispatchGhcRequest 5 (Just testUri) "r5" 5 scheduler logChan $ lint testUri
249248

250249
hr5 <- atomically $ readTChan logChan
251250
unpackRes hr5 `shouldBe` ("r5",
@@ -275,7 +274,7 @@ funcSpec = describe "functional dispatch" $ do
275274
-- (Just $ H.singleton r6uri textEdits)
276275
-- Nothing
277276
-- ))
278-
dispatchGhcRequest 6 (Just testUri) "r6" 6 scheduler logChan "bios" "check" (toJSON testUri)
277+
dispatchGhcRequest 6 (Just testUri) "r6" 6 scheduler logChan $ setTypecheckedModule testUri
279278
hr6 <- atomically $ readTChan logChan
280279
unpackRes hr6 `shouldBe` ("r6",Nothing :: Maybe Int)
281280

@@ -285,7 +284,7 @@ funcSpec = describe "functional dispatch" $ do
285284

286285
dispatchIdeRequest 7 "req7" scheduler logChan (IdInt 7) $ findDef testFailUri (Position 1 2)
287286

288-
dispatchGhcRequest 8 (Just testUri) "req8" 8 scheduler logChan "bios" "check" (toJSON testFailUri)
287+
dispatchGhcRequest 8 (Just testUri) "req8" 8 scheduler logChan $ setTypecheckedModule testFailUri
289288

290289
hr7 <- atomically $ readTChan logChan
291290
unpackRes hr7 `shouldBe` ("req7", Just ([] :: [Location]))

test/unit/ExtensibleStateSpec.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ testDescriptor :: PluginId -> PluginDescriptor
3636
testDescriptor plId = PluginDescriptor
3737
{ pluginId = plId
3838
, pluginCommands = [
39-
PluginCommand "cmd1" "description" cmd1
40-
, PluginCommand "cmd2" "description" cmd2
39+
PluginCommand "cmd1" cmd1
40+
, PluginCommand "cmd2" cmd2
4141
]
4242
, pluginCodeActionProvider = Nothing
4343
, pluginDiagnosticProvider = Nothing

test/unit/GenericPluginSpec.hs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import qualified Data.Text as T
99
import Haskell.Ide.Engine.Ghc
1010
import Haskell.Ide.Engine.MonadTypes
1111
import Haskell.Ide.Engine.Plugin.Generic
12-
import Haskell.Ide.Engine.Plugin.Bios
1312
import Haskell.Ide.Engine.PluginUtils
1413
import Language.Haskell.LSP.Types (toNormalizedUri)
1514
import System.Directory
@@ -29,7 +28,7 @@ spec = do
2928
-- ---------------------------------------------------------------------
3029

3130
testPlugins :: IdePlugins
32-
testPlugins = pluginDescToIdePlugins [biosDescriptor "bios", genericDescriptor "generic" ]
31+
testPlugins = pluginDescToIdePlugins [genericDescriptor "generic" ]
3332

3433
-- ---------------------------------------------------------------------
3534

@@ -56,7 +55,7 @@ ghcmodSpec =
5655
"Variable not in scope: x"
5756
Nothing
5857

59-
testCommand testPlugins act "bios" "check" arg res
58+
runIGM testPlugins (setTypecheckedModule arg) `shouldReturn` res
6059

6160
-- ---------------------------------
6261

0 commit comments

Comments
 (0)