Skip to content

Add contiguous scope modifier #1835

Open
@AndreasArvidsson

Description

@AndreasArvidsson

Could be used for example targeting multiple contiguous line comments.

"comment slurp comments fine"

// foo
// bar

Potential solution

I was thinking that this could be implemented around the existing scope handlers similar to how the every modifier works and just join scopes/targets based on leading and trailing delimiter ranges.

  1. Get all scopes
const scopes = scopeHandler.generateScopes(...);
  1. Iterate scopes and join contiguous targets
const leadingRange = leadingTarget.trailingDelimiterRange ?? leadingTarget.contentRange;
const trailingRange = trailingTarget.leadingDelimiterRange ?? trailingTarget.contentRange;
if (leadingRange.intersects(trailingRange) != null) {
    newContentRange = leadingTarget.contentRange.union(trailingTarget.contentRange);
}

Thinks to discuss

  • One problem is that most leading and trailing delimiter ranges doesn't contain the eol. Eg with comment the leading range would end with the previous line and the trailing range would start with the next line. We could of course say that that is valid for merging, but it would probably make "take slurp tokens" join all tokens in the file and therefore take the entire file.
  • How do we handle nested scopes?
  • Do we want to support "every slurp <scope>"?

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions