Those who might not be directly concerned about Scala 2.13.x might also still be interested in reviewing the above PR since I am effectively specifying how Action should be interpreted given a position:
def applyChange(code: String, a: CodeAction): String = {
val change = a.edit.changes.head
val head =
if (change.position.isRange) code.take(change.position.start)
else code.take(change.position.point)
// end is inclusive, so you have to drop one more character here
val tail =
if (change.position.isRange) code.drop(change.position.end + 1)
else code.drop(change.position.point)
head + change.newText + tail
}
In other words, given a string "abc"
, we need to come up with an agreed upon TextEdit(???, "???")
to turn it into:
"abdc"
"ac"
for Scala. In Scala 2 at least, the position is end-inclusive, unlike LSP range right?