-
-
Notifications
You must be signed in to change notification settings - Fork 88
Simplify default iteration scopes; file scopeHandler #1075
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
AndreasArvidsson
merged 13 commits into
main
from
pokey/simplify-default-iteration-scopes-file-scopehandler
Oct 24, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3dc83b6
Started migrating scope stages into handlers
AndreasArvidsson f54b690
cleanup
AndreasArvidsson 7bb5a14
more clean up
AndreasArvidsson 9aa68a0
Tweaks
pokey e287681
Simplify default iteration scopes; file scopeHandler
pokey 3758d21
Restore "every file" test
pokey c287fb7
Tweak
pokey cc72cb9
More tweaks
pokey 3bf34e5
More simplification
pokey 8085ed9
cleanup
pokey bbb927e
Disallow undefined iterationScopeType
pokey 448a636
tweak
pokey 4820271
Update src/processTargets/modifiers/scopeHandlers/DocumentScopeHandle…
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/processTargets/modifiers/scopeHandlers/DocumentScopeHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Position, Range, TextEditor } from "vscode"; | ||
import { Direction, ScopeType } from "../../../typings/targetDescriptor.types"; | ||
import { getDocumentRange } from "../../../util/rangeUtils"; | ||
import { DocumentTarget } from "../../targets"; | ||
import { OutOfRangeError } from "../targetSequenceUtils"; | ||
import NotHierarchicalScopeError from "./NotHierarchicalScopeError"; | ||
import { TargetScope } from "./scope.types"; | ||
import { ScopeHandler } from "./scopeHandler.types"; | ||
|
||
export default class DocumentScopeHandler implements ScopeHandler { | ||
public readonly scopeType = { type: "document" } as const; | ||
public readonly iterationScopeType = { type: "document" } as const; | ||
|
||
constructor(_scopeType: ScopeType, _languageId: string) { | ||
// Empty | ||
} | ||
|
||
getScopesTouchingPosition( | ||
editor: TextEditor, | ||
_position: Position, | ||
ancestorIndex: number = 0 | ||
): TargetScope[] { | ||
if (ancestorIndex !== 0) { | ||
throw new NotHierarchicalScopeError(this.scopeType); | ||
} | ||
|
||
return [getDocumentScope(editor)]; | ||
} | ||
|
||
getScopesOverlappingRange(editor: TextEditor, _range: Range): TargetScope[] { | ||
return [getDocumentScope(editor)]; | ||
} | ||
|
||
getScopeRelativeToPosition( | ||
_editor: TextEditor, | ||
_position: Position, | ||
_offset: number, | ||
_direction: Direction | ||
): TargetScope { | ||
// NB: offset will always be greater than or equal to 1, so this will be an | ||
// error | ||
throw new OutOfRangeError(); | ||
} | ||
} | ||
|
||
function getDocumentScope(editor: TextEditor): TargetScope { | ||
const contentRange = getDocumentRange(editor.document); | ||
|
||
return { | ||
editor, | ||
domain: contentRange, | ||
getTarget: (isReversed) => | ||
new DocumentTarget({ | ||
editor, | ||
isReversed, | ||
contentRange, | ||
}), | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that iteration scope of document is document, so we get "every file" for free, if for whatever reason someone wants to do that 🤔