@@ -39,7 +39,6 @@ import qualified Data.Set as S
39
39
import qualified Data.SortedList as SL
40
40
import qualified Data.Text as T
41
41
import Data.Text.Encoding
42
- import Data.UUID
43
42
import qualified Data.Vector as V
44
43
import qualified GhcModCore as GM
45
44
import qualified GhcMod.Monad.Types as GM
@@ -67,7 +66,6 @@ import qualified Language.Haskell.LSP.Types as J
67
66
import qualified Language.Haskell.LSP.Utility as U
68
67
import System.Exit
69
68
import qualified System.Log.Logger as L
70
- import System.Random
71
69
import qualified Yi.Rope as Yi
72
70
73
71
import Name
99
97
-> IO Int
100
98
run dispatcherProc cin _origDir captureFp = flip E. catches handlers $ do
101
99
102
- -- TODO: Figure out how to test with random seeds
103
- commandUUIDs <- getCommandUUIDs
100
+ commandMap <- getCommandMap
104
101
105
102
rin <- atomically newTChan :: IO (TChan ReactorInput )
106
103
@@ -113,7 +110,7 @@ run dispatcherProc cin _origDir captureFp = flip E.catches handlers $ do
113
110
, wipReqsTVar = wipTVar
114
111
, docVersionTVar = versionTVar
115
112
}
116
- let reactorFunc = flip runReaderT lf $ reactor dispatcherEnv cin rin commandUUIDs
113
+ let reactorFunc = flip runReaderT lf $ reactor dispatcherEnv cin rin commandMap
117
114
118
115
let errorHandler :: ErrorHandler
119
116
errorHandler lid code e =
@@ -128,17 +125,17 @@ run dispatcherProc cin _origDir captureFp = flip E.catches handlers $ do
128
125
return Nothing
129
126
130
127
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
132
129
where
133
130
handlers = [E. Handler ioExcept, E. Handler someExcept]
134
131
finalProc = L. removeAllHandlers
135
132
ioExcept (e :: E. IOException ) = print e >> return 1
136
133
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 )
142
139
143
140
-- ---------------------------------------------------------------------
144
141
@@ -346,7 +343,7 @@ sendErrorLog msg = reactorSend' (`Core.sendErrorLogS` msg)
346
343
-- to stitch replies and requests together from the two asynchronous sides: lsp
347
344
-- server and hie dispatcher
348
345
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
350
347
let
351
348
makeRequest req@ (GReq _ _ Nothing (Just lid) _ _) = liftIO $ atomically $ do
352
349
modifyTVar wipTVar (S. insert lid)
@@ -399,7 +396,7 @@ reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs =
399
396
let
400
397
options = J. object [" documentSelector" .= J. object [ " language" .= J. String " haskell" ]]
401
398
registrationsList =
402
- [ J. Registration (commandUUIDs BM. ! " hare:demote" ) J. WorkspaceExecuteCommand (Just options)
399
+ [ J. Registration (commandMap BM. ! " hare:demote" ) J. WorkspaceExecuteCommand (Just options)
403
400
]
404
401
let registrations = J. RegistrationParams (J. List registrationsList)
405
402
@@ -585,7 +582,7 @@ reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs =
585
582
title :: T. Text
586
583
title = " Apply hint:" <> head (T. lines m)
587
584
-- 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"
589
586
-- need 'file', 'start_pos' and hint title (to distinguish between alternative suggestions at the same location)
590
587
args = J. Array $ V. singleton $ J. toJSON $ ApplyRefact. AOP doc start code
591
588
cmdparams = Just args
@@ -603,7 +600,7 @@ reactor (DispatcherEnv cancelReqTVar wipTVar versionTVar) cin inp commandUUIDs =
603
600
let params = req ^. J. params
604
601
command' = params ^. J. command
605
602
-- 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 )
607
604
margs = params ^. J. arguments
608
605
609
606
liftIO $ U. logs $ " ExecuteCommand mapped command " ++ show command' ++ " to " ++ show command
0 commit comments