mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user