Skip to content

Commit 8a39c8d

Browse files
committed
[CodeCompletion Remember the replaced source range in SourceManager
1 parent c5a4af3 commit 8a39c8d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ class SourceManager {
3838
/// to speed up stats.
3939
mutable llvm::DenseMap<StringRef, llvm::vfs::Status> StatusCache;
4040

41+
struct ReplacedRangeType {
42+
SourceRange Original;
43+
SourceRange New;
44+
ReplacedRangeType() {}
45+
ReplacedRangeType(NoneType) {}
46+
ReplacedRangeType(SourceRange Original, SourceRange New)
47+
: Original(Original), New(New) {
48+
assert(Original.isValid() && New.isValid());
49+
}
50+
51+
explicit operator bool() const { return Original.isValid(); }
52+
};
53+
ReplacedRangeType ReplacedRange;
54+
4155
// \c #sourceLocation directive handling.
4256
struct VirtualFile {
4357
CharSourceRange Range;
@@ -89,6 +103,9 @@ class SourceManager {
89103

90104
SourceLoc getCodeCompletionLoc() const;
91105

106+
const ReplacedRangeType &getReplacedRange() const { return ReplacedRange; }
107+
void setReplacedRange(const ReplacedRangeType &val) { ReplacedRange = val; }
108+
92109
/// Returns true if \c LHS is before \c RHS in the source buffer.
93110
bool isBeforeInBuffer(SourceLoc LHS, SourceLoc RHS) const {
94111
return LHS.Value.getPointer() < RHS.Value.getPointer();

lib/IDE/CompletionInstance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
417417

418418
auto *AFD = cast<AbstractFunctionDecl>(DC);
419419
AFD->setBodyToBeReparsed(newBodyRange);
420+
SM.setReplacedRange({AFD->getOriginalBodySourceRange(), newBodyRange});
420421

421422
traceDC = AFD;
422423
break;

0 commit comments

Comments
 (0)