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

Refactor DispatcherEnv our of the Reactor #864

Merged
merged 14 commits into from
Oct 29, 2018
Merged

Conversation

lorenzo
Copy link
Collaborator

@lorenzo lorenzo commented Oct 9, 2018

This introduces a new Scheduler module that that takes much of the code previously in the Dispatcher and removes the channel interface between the reactor and the dispatcher. Instead, explicitly calls to the Scheduler are made to queue requests.

closes #835

@lorenzo lorenzo requested review from lukel97 and alanz October 9, 2018 13:49
Copy link
Collaborator

@lukel97 lukel97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type signatures inside LspStdio are looking a lot nicer now!

{ cancelReqsTVar = cancelTVar
, wipReqsTVar = wipTVar
, docVersionTVar = versionTVar
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting rid of this is great

@lorenzo
Copy link
Collaborator Author

lorenzo commented Oct 14, 2018

@alanz are you ok with merging this?

@alanz
Copy link
Collaborator

alanz commented Oct 14, 2018

I would like to take a proper look, when I can concentrate. It may be a few days.

@alanz
Copy link
Collaborator

alanz commented Oct 26, 2018

@lorenzo is this up to date? I want to start looking at it.

@lorenzo
Copy link
Collaborator Author

lorenzo commented Oct 26, 2018

Yes, it is up to date, a few commits behind, but nothing relevant in master that would affect this @alanz

else do
pin <- atomically newTChan
lspStdioTransport (dispatcherP pin plugins' ghcModOptions) pin origDir plugins' (optCaptureFile opts)
scheduler <- newScheduler plugins' ghcModOptions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could be moved out of the if statement, it is in both legs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is possible since scheduler is parameterised for a different base monad on each leg, so the type of scheduler can only be determined after choosing what leg of the if to follow

liftIO $ Scheduler.sendRequest sc (Just (uri, ver)) req

-- | Marks a s requests as cencelled by its LspId
cancelRequest :: (MonadIO m, MonadReader REnv m) => J.LspId -> m ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect these functions (all the ones that do asks scheduler to move to the Scheduler module.
Would that make sense?

Copy link
Collaborator Author

@lorenzo lorenzo Oct 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like would make sense to you?

-- In Scheduler.hs
class Monad m => HasScheduler m where
    getScheduler :: m Scheduler

-- In Reactor.hs
instance Monad m => HasScheduler (MonadReader REnv m) where
   getScheduler = asks scheduler


-- In Scheduler.hs
cancelRequest :: (MonadIO m, HasScheduler m) => J.LspId -> m ()
cancelRequest lId = do
     scheduler <- getScheduler
     ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I suspect the only constraint we really need is that the asks call succeeds.

To me it is about putting all the stuff related to scheduling in one place, so we can look at it holistically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that look?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And looking more closely, that is exactly what you proposed. Sorry.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanz I moved the implementation of those functions to the Scheduler module. Decided to keep the same functions in the Reactor module in order to provide some more specific type signatures. Using the generic function from Scheduler in LspStdio required adding many annoying type hints. In my opinion this version looks cleaner.

-- | Marks a s requests as cencelled by its LspId
cancelRequest :: (MonadIO m, MonadReader REnv m) => J.LspId -> m ()
cancelRequest lid =
liftIO . flip Scheduler.cancelRequest lid =<< asks scheduler
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only function that I could not generalise, I kept getting type errors in the Scheduler module.

@alanz
Copy link
Collaborator

alanz commented Oct 28, 2018

LGTM, thanks. I reckon we can merge when the CI passes

@lorenzo
Copy link
Collaborator Author

lorenzo commented Oct 29, 2018

I'll merge now, tests passed for circle-ci

@lorenzo lorenzo merged commit e3f3428 into master Oct 29, 2018
@lorenzo lorenzo deleted the refactor-dispatcher branch October 29, 2018 16:48
@alanz alanz added this to the prehistory milestone Feb 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate dispatcher stuff away from LspStdio
3 participants