Skip to content

Commit 01b5cf7

Browse files
committed
[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
1 parent 61cb9a5 commit 01b5cf7

File tree

2 files changed

+357
-6
lines changed

2 files changed

+357
-6
lines changed

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,10 @@ SwiftDocumentSemanticInfo::takeSemanticTokens(
786786
});
787787

788788
std::vector<SwiftSemanticToken>::iterator ReplaceEnd;
789-
if (Upd->getLength() == 0) {
789+
if (ReplaceBegin == SemaToks.end()) {
790790
ReplaceEnd = ReplaceBegin;
791+
} else if (Upd->getLength() == 0) {
792+
ReplaceEnd = ReplaceBegin + 1;
791793
} else {
792794
ReplaceEnd = std::upper_bound(ReplaceBegin, SemaToks.end(),
793795
Upd->getByteOffset() + Upd->getLength(),

0 commit comments

Comments
 (0)