-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand Selection in comments for Scala 2 (#6109)
* wip * ok * test * wip * test * address reviews * use common SelectionRangeUtils * test * Update mtags/src/main/scala-2/scala/meta/internal/pc/SelectionRangeProvider.scala Co-authored-by: Katarzyna Marek <[email protected]> --------- Co-authored-by: Katarzyna Marek <[email protected]>
- Loading branch information
1 parent
0887abd
commit 08bcf0d
Showing
4 changed files
with
85 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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
34 changes: 34 additions & 0 deletions
34
mtags/src/main/scala/scala/meta/internal/pc/SelectionRangeUtils.scala
This file contains 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,34 @@ | ||
package scala.meta.internal.pc | ||
|
||
import scala.meta.tokens.Token | ||
import scala.meta.tokens.Token.Comment | ||
|
||
object SelectionRangeUtils { | ||
|
||
/** | ||
* common part for scala 2/3 for selection expansion in comment | ||
* | ||
* @param tokenList | ||
* @param cursorStart | ||
* @param offsetStart | ||
* @return | ||
*/ | ||
def commentRangesFromTokens( | ||
tokenList: List[Token], | ||
cursorStart: Int, | ||
offsetStart: Int | ||
): List[(Int, Int)] = { | ||
val cursorStartShifted = cursorStart - offsetStart | ||
|
||
tokenList | ||
.collect { case x: Comment => | ||
(x.start, x.end, x.pos) | ||
} | ||
.collect { | ||
case (commentStart, commentEnd, _) | ||
if commentStart <= cursorStartShifted && cursorStartShifted <= commentEnd => | ||
(commentStart + offsetStart, commentEnd + offsetStart) | ||
|
||
} | ||
} | ||
} |
This file contains 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