[sourcekitd] Fix annotation range-shifting after edit

When performing an insertion (replacement length = 0) inside an existing
annotation, we were forming a closed range instead of a half-open range,
causing us to shift the effected token instead of throwing it out. There
were also no tests for this functionality, so add a bunch of annotations
tests.

One area thing that is not tested is what if there have been multiple
edits since the tokens were created. This is difficult to engineer,
because right now making an edit immediately removes the semantic tokens
and returns them. It could happen if the AST build takes longer than the
edits, but there is no way to guarantee that in the current API.

rdar://65748892
This commit is contained in:
Ben Langmuir
2020-07-20 16:56:49 -07:00
parent 61cb9a5f4f
commit 01b5cf7c6f
2 changed files with 357 additions and 6 deletions

View File

@@ -786,8 +786,10 @@ SwiftDocumentSemanticInfo::takeSemanticTokens(
});
std::vector<SwiftSemanticToken>::iterator ReplaceEnd;
if (Upd->getLength() == 0) {
if (ReplaceBegin == SemaToks.end()) {
ReplaceEnd = ReplaceBegin;
} else if (Upd->getLength() == 0) {
ReplaceEnd = ReplaceBegin + 1;
} else {
ReplaceEnd = std::upper_bound(ReplaceBegin, SemaToks.end(),
Upd->getByteOffset() + Upd->getLength(),