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

Commit d5730fb

Browse files
authored
Merge pull request #632 from Bubba/pid-commands
Use just plain process IDs instead of UUIDs to unique commands
2 parents c5f6236 + 218c07a commit d5730fb

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

haskell-ide-engine.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,11 @@ library
7171
, mtl
7272
, optparse-simple >= 0.0.3
7373
, process
74-
, random
7574
, sorted-list >= 0.2.1.0
7675
, stm
7776
, tagsoup
7877
, text
7978
, transformers
80-
, uuid
8179
, vector
8280
, yaml
8381
, yi-rope

src/Haskell/Ide/Engine/Transport/LspStdio.hs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import qualified Data.Set as S
3939
import qualified Data.SortedList as SL
4040
import qualified Data.Text as T
4141
import Data.Text.Encoding
42-
import Data.UUID
4342
import qualified Data.Vector as V
4443
import qualified GhcModCore as GM
4544
import qualified GhcMod.Monad.Types as GM
@@ -67,7 +66,6 @@ import qualified Language.Haskell.LSP.Types as J
6766
import qualified Language.Haskell.LSP.Utility as U
6867
import System.Exit
6968
import qualified System.Log.Logger as L
70-
import System.Random
7169
import qualified Yi.Rope as Yi
7270

7371
import Name
@@ -99,8 +97,7 @@ run
9997
-> IO Int
10098
run dispatcherProc cin _origDir captureFp = flip E.catches handlers $ do
10199

102-
-- TODO: Figure out how to test with random seeds
103-
commandUUIDs <- getCommandUUIDs
100+
commandMap <- getCommandMap
104101

105102
rin <- atomically newTChan :: IO (TChan ReactorInput)
106103

@@ -113,7 +110,7 @@ run dispatcherProc cin _origDir captureFp = flip E.catches handlers $ do
113110
, wipReqsTVar = wipTVar
114111
, docVersionTVar = versionTVar
115112
}
116-
let reactorFunc = flip runReaderT lf $ reactor dispatcherEnv cin rin commandUUIDs
113+
let reactorFunc = flip runReaderT lf $ reactor dispatcherEnv cin rin commandMap
117114

118115
let errorHandler :: ErrorHandler
119116
errorHandler lid code e =
@@ -128,17 +125,17 @@ run dispatcherProc cin _origDir captureFp = flip E.catches handlers $ do
128125
return Nothing
129126

130127
flip E.finally finalProc $ do
131-
CTRL.run (getConfig, dp) (hieHandlers rin) (hieOptions (BM.elems commandUUIDs)) captureFp
128+
CTRL.run (getConfig, dp) (hieHandlers rin) (hieOptions (BM.elems commandMap)) captureFp
132129
where
133130
handlers = [E.Handler ioExcept, E.Handler someExcept]
134131
finalProc = L.removeAllHandlers
135132
ioExcept (e :: E.IOException) = print e >> return 1
136133
someExcept (e :: E.SomeException) = print e >> return 1
137-
getCommandUUIDs = do
138-
uuid <- toText . fst . random . mkStdGen <$> getProcessID
139-
let commands = ["hare:demote", "applyrefact:applyOne"]
140-
uuids = map (T.append uuid . T.append ":") commands
141-
return $ BM.fromList (zip commands uuids)
134+
getCommandMap = do
135+
pid <- T.pack . show <$> getProcessID
136+
let cmds = ["hare:demote", "applyrefact:applyOne"]
137+
newCmds = map (T.append pid . T.append ":") cmds
138+
return $ BM.fromList (zip cmds newCmds)
142139

143140
-- ---------------------------------------------------------------------
144141

@@ -346,7 +343,7 @@ sendErrorLog msg = reactorSend' (`Core.sendErrorLogS` msg)
346343
-- to stitch replies and requests together from the two asynchronous sides: lsp
347344
-- server and hie dispatcher
348345
reactor :: forall void. DispatcherEnv -> TChan (PluginRequest R) -> TChan ReactorInput -> BM.Bimap T.Text T.Text -> R void
349-
reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs = do
346+
reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandMap = do
350347
let
351348
makeRequest req@(GReq _ _ Nothing (Just lid) _ _) = liftIO $ atomically $ do
352349
modifyTVar wipTVar (S.insert lid)
@@ -399,7 +396,7 @@ reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs =
399396
let
400397
options = J.object ["documentSelector" .= J.object [ "language" .= J.String "haskell"]]
401398
registrationsList =
402-
[ J.Registration (commandUUIDs BM.! "hare:demote") J.WorkspaceExecuteCommand (Just options)
399+
[ J.Registration (commandMap BM.! "hare:demote") J.WorkspaceExecuteCommand (Just options)
403400
]
404401
let registrations = J.RegistrationParams (J.List registrationsList)
405402

@@ -585,7 +582,7 @@ reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs =
585582
title :: T.Text
586583
title = "Apply hint:" <> head (T.lines m)
587584
-- NOTE: the cmd needs to be registered via the InitializeResponse message. See hieOptions above
588-
cmd = commandUUIDs BM.! "applyrefact:applyOne"
585+
cmd = commandMap BM.! "applyrefact:applyOne"
589586
-- need 'file', 'start_pos' and hint title (to distinguish between alternative suggestions at the same location)
590587
args = J.Array $ V.singleton $ J.toJSON $ ApplyRefact.AOP doc start code
591588
cmdparams = Just args
@@ -603,7 +600,7 @@ reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs =
603600
let params = req ^. J.params
604601
command' = params ^. J.command
605602
-- if this is a UUID then use the mapping for it
606-
command = fromMaybe command' (BM.lookupR command' commandUUIDs)
603+
command = fromMaybe command' (BM.lookupR command' commandMap)
607604
margs = params ^. J.arguments
608605

609606
liftIO $ U.logs $ "ExecuteCommand mapped command " ++ show command' ++ " to " ++ show command

0 commit comments

Comments
 (0)