Class: NestedScopeHandler
processTargets/modifiers/scopeHandlers/NestedScopeHandler.NestedScopeHandler
This class can be used to define scope types that are most easily defined by
simply getting all scopes in an instance of a parent scope type and then
operating on those. A good example is regex-based scope types where the
regex can't cross line boundaries. In this case the
iterationScopeType will be line
, and we just return a list of all
regex matches to this base class and let it handle the rest.
Note that this base class only works for non-hierarchical scope types. In the future we may define a nested scope handler that supports hierarchical scope types.
Hierarchy
↳
NestedScopeHandler
Constructors
constructor
• new NestedScopeHandler(scopeType
, languageId
)
Parameters
Name | Type |
---|---|
scopeType | ScopeType |
languageId | string |
Overrides
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:56
Properties
_searchScopeHandler
• Private
_searchScopeHandler: undefined
| ScopeHandler
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:54
isHierarchical
• Protected
Readonly
isHierarchical: false
Indicates whether scopes are allowed to contain one another. If false
, we
can optimise the algorithm by making certain assumptions.
Overrides
BaseScopeHandler.isHierarchical
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:29
iterationScopeType
• Readonly
Abstract
iterationScopeType: ScopeType
The scope type of the default iteration scope of this scope type. This
scope type will be used when the input target has no explicit range (ie
Target.hasExplicitRange is false
).
Overrides
BaseScopeHandler.iterationScopeType
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:28
languageId
• Protected
languageId: string
scopeType
• Readonly
scopeType: ScopeType
The scope type handled by this scope handler
Inherited from
Accessors
searchScopeHandler
• Private
get
searchScopeHandler(): ScopeHandler
Returns
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:63
searchScopeType
• Protected
get
searchScopeType(): ScopeType
We expand to this scope type before looking for instances of the scope type
handled by this scope handler. In most cases the iteration scope will
suffice, but in some cases you want them to diverge. For example, you
might want the default iteration scope to be "file"
, but you don't need
to expand to the file just to find instances of the given scope type.
Returns
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:38
Methods
generateScopeCandidates
▸ Protected
generateScopeCandidates(editor
, position
, direction
, hints?
): Iterable
<TargetScope
>
Returns an iterable that yields scopes.
If your scope type is not hierarchical, and {@link direction} is
"forward"
, yield all scopes whose domain's
end is equal to or after position in document
order.
If your scope type is not hierarchical, and {@link direction} is
"backward"
, yield all scopes whose domain's
start is equal to or before position, in
reverse document order.
If your scope type is hierarchical, and {@link direction} is "forward"
,
walk forward starting at position (including position). Any time a
scope's domain ends or starts, yield that scope.
If multiple domains start or end at a particular point, break ties as
follows:
- First yield any scopes with empty domain.
- Then yield any scopes whose domains are ending, in reverse order of where they start.
- Then yield the scope with minimal domain that is starting. Any time you yield a scope, advance your position to the end of the scope, but when considering this new position, don't return this scope again.
If your scope type is hierarchical, and {@link direction} is
"backward"
, walk backward starting at position (including
position). Any time a scope's domain ends or
starts, yield that scope. If multiple domains start or end at a particular
point, break ties as follows:
- First yield any scopes with empty domain.
- Then yield any scopes whose domains are starting, in order of where they end.
- Then yield the scope with minimal domain that is ending. Any time you yield a scope, advance your position to the start of the scope, but when considering this new position, don't return this scope again.
Note that the {@link hints} argument can be ignored, but you are welcome to use it to improve performance. For example, knowing the ScopeIteratorRequirements.distalPosition can be useful if you need to query a list of scopes in bulk.
Some notes:
- Once you have yielded a scope, you do not need to yield any scopes contained by that scope.
- You can yield the same scope more than once if it makes your life easier
The only strict requirements are that
- you yield every scope that might meet the requirements
- you yield scopes in the correct order
Parameters
Name | Type |
---|---|
editor | TextEditor |
position | Position |
direction | Direction |
hints | undefined | ScopeIteratorRequirements |
Returns
Iterable
<TargetScope
>
Overrides
BaseScopeHandler.generateScopeCandidates
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:74
generateScopes
▸ generateScopes(editor
, position
, direction
, requirements?
): Iterable
<TargetScope
>
Returns an iterable of scopes meeting the requirements in {@link requirements}, yielded in a specific order. See generateScopeCandidates and compareTargetScopes for more on the order.
Parameters
Name | Type |
---|---|
editor | TextEditor |
position | Position |
direction | Direction |
requirements | undefined | ScopeIteratorRequirements |
Returns
Iterable
<TargetScope
>
Inherited from
BaseScopeHandler.generateScopes
Defined in
processTargets/modifiers/scopeHandlers/BaseScopeHandler.ts:94
generateScopesInSearchScope
▸ Protected
Abstract
generateScopesInSearchScope(direction
, searchScope
): Iterable
<TargetScope
>
This function is the only function that needs to be defined in the derived type. It should yield all child scope types in the given parent scope type, in the order specified in {@link direction}.
Parameters
Name | Type | Description |
---|---|---|
direction | Direction | - |
searchScope | TargetScope | An instance of the parent scope type from which to return all child target scopes |
Returns
Iterable
<TargetScope
>
Defined in
processTargets/modifiers/scopeHandlers/NestedScopeHandler.ts:49