Skip to content

Add factories for stages and scope handlers #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2023

Conversation

pokey
Copy link
Member

@pokey pokey commented Apr 7, 2023

Checklist

@@ -33,7 +36,12 @@ export function createCursorlessEngine(

const testCaseRecorder = new TestCaseRecorder(hatTokenMap);

const actions = new Actions(snippets, rangeUpdater);
const scopeHandlerFactory = new ScopeHandlerFactoryImpl();
Copy link
Member Author

@pokey pokey Apr 7, 2023

Choose a reason for hiding this comment

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

@AndreasArvidsson notice how the scopeHandlerFactory is instantiated at the composition root, so there's no "deep drilling". Anything that a scope handler needs to do its job just gets passed one level through the factory to the scope handler that needs it. The decoupling actually results in shallower hierarchies, because the code that uses scope handlers isn't responsible for giving them their dependencies. It also makes testing easier, because we could just pass in a fake scope handler factory to a modifier. Tbh it would be a bit cleaner if we could just pass in a scope handler directly to a modifier, but the problem is that we might need a different scope handler per target, so it is useful for the modifier to be able to construct the scope handler on the fly

Note that this line is the primary motivator for prioritising this PR: it allows me to easily pass in the tree-sitter parser to the TreeSitterScopeHandler I'm creating in #629

@@ -0,0 +1,134 @@
import {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we want to move these factories into the composition root; one could argue they're really part of the composition root, but otoh there's something nice about having them close to all the things they instantiate. Idk wdyt @auscompgeek @AndreasArvidsson ?

@pokey pokey force-pushed the pokey/add-factories-for-stages-and-scope-handlers branch from abfe350 to 056a3f6 Compare April 7, 2023 17:52
constructor(
private modifierStageFactory: ModifierStageFactory,
private markStageFactory: MarkStageFactory,
private context: ProcessedTargetsContext,
Copy link
Member Author

Choose a reason for hiding this comment

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

Notice that putting these functions onto a class allows us to avoid passing the context around so much by just making it a member variable. We'll eventually split up / remove the context altogether, but leaving that for later

@pokey pokey force-pushed the pokey/add-factories-for-stages-and-scope-handlers branch 3 times, most recently from 4dcc6c5 to 6f058e4 Compare April 7, 2023 18:09
@pokey pokey force-pushed the pokey/package-composition-roots branch from 0532bc6 to c65c10f Compare April 11, 2023 20:26
@pokey pokey force-pushed the pokey/add-factories-for-stages-and-scope-handlers branch 3 times, most recently from aadc709 to dc292ba Compare April 12, 2023 20:45
@pokey pokey force-pushed the pokey/package-composition-roots branch from e485803 to 20ae7c4 Compare April 12, 2023 20:45
@pokey pokey force-pushed the pokey/add-factories-for-stages-and-scope-handlers branch 2 times, most recently from 56b18c8 to 81d75f9 Compare April 13, 2023 21:02
@pokey pokey force-pushed the pokey/package-composition-roots branch from 1472b7c to 4d08e4a Compare April 13, 2023 21:02
Base automatically changed from pokey/package-composition-roots to main April 14, 2023 12:46
@pokey pokey force-pushed the pokey/add-factories-for-stages-and-scope-handlers branch from 81d75f9 to b4d99c1 Compare April 14, 2023 14:14
@pokey pokey marked this pull request as ready for review April 14, 2023 14:15
@pokey pokey requested a review from AndreasArvidsson April 14, 2023 14:15
@pokey pokey enabled auto-merge April 14, 2023 22:04
@pokey pokey added this pull request to the merge queue Apr 16, 2023
Merged via the queue into main with commit 1e4af50 Apr 16, 2023
@pokey pokey deleted the pokey/add-factories-for-stages-and-scope-handlers branch April 16, 2023 09:19
pokey added a commit that referenced this pull request Apr 19, 2023
- Partially addresses #616
- Partially addresses
#436
- Depends on #1396

## Todo
- [x] **[DISCUSS]** What to do about fallback `iterationScope`? That's
the only thing that is a regression here.
- [x] File issues for FIXMEs
- [x] File issue for defining iteration scopes. Can probably reuse most
of the code from the regular scope handler other than creating the
target
- [x] File issue to add unit tests for scope handlers
- [x] File issue to add some Python scope types where multiple can end
at the same point (due to lack of closing brackets)
- [x] Add test that checks no scope types are duplicated between legacy
and new definition, or file issue to add test
- [x] File PR for my 7783da6 (Add support for domain, leading, trailing,
interior) #1427
- [x] Look through comments on this thread for anything worth filing /
doing
- [x] Open as new PR?
- [x] Remove extraneous test cases
- [x] Double check
#629 (comment);
a lot of those tests we already have for the generic modifier code
- [x] Make sure changes to parse-tree-extension are shipped
- [x] Close #785 if
we fix that
- [x] Comment on #484 saying the process has started and providing link
to example
- [x] Close #797 if
we fix that

---------

Co-authored-by: Pokey Rule <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants