@@ -39,16 +39,15 @@ using namespace ast_scope;
39
39
40
40
static SourceLoc getLocAfterExtendedNominal (const ExtensionDecl *);
41
41
42
- // / Retrieve the character-based source range for the given source range.
43
- static SourceRange getCharSourceRange (
44
- SourceManager &sourceMgr, SourceRange range
45
- ){
46
- range.End = Lexer::getLocForEndOfToken (sourceMgr, range.End );
47
- return range;
48
- }
49
-
50
42
void ASTScopeImpl::checkSourceRangeBeforeAddingChild (ASTScopeImpl *child,
51
43
const ASTContext &ctx) const {
44
+ // Ignore attributes on extensions, currently they exist outside of the
45
+ // extension's source range due to the way we've setup the scope for
46
+ // extension binding.
47
+ // FIXME: We ought to fix the source range for extension scopes.
48
+ if (isa<ExtensionScope>(this ) && child->isDeclAttribute ())
49
+ return ;
50
+
52
51
// Ignore debugger bindings - they're a special mix of user code and implicit
53
52
// wrapper code that is too difficult to check for consistency.
54
53
if (auto d = getDeclIfAny ().getPtrOrNull ())
@@ -60,14 +59,14 @@ void ASTScopeImpl::checkSourceRangeBeforeAddingChild(ASTScopeImpl *child,
60
59
61
60
auto range = getCharSourceRangeOfScope (sourceMgr);
62
61
63
- std::function<bool (SourceRange)> containedInParent;
64
- containedInParent = [&](SourceRange childCharRange) {
62
+ auto containedInParent = [&](SourceRange childCharRange) {
65
63
// HACK: For code completion. Handle replaced range.
64
+ // Note that the replaced SourceRanges here are already disguised
65
+ // CharSourceRanges, we don't need to adjust them. We use `rangeContains`
66
+ // since we're only interested in comparing within a single buffer.
66
67
for (const auto &pair : sourceMgr.getReplacedRanges ()) {
67
- auto originalRange = getCharSourceRange (sourceMgr, pair.first );
68
- auto newRange = getCharSourceRange (sourceMgr, pair.second );
69
- if (sourceMgr.encloses (range, originalRange) &&
70
- sourceMgr.encloses (newRange, childCharRange))
68
+ if (sourceMgr.rangeContains (range, pair.first ) &&
69
+ sourceMgr.rangeContains (pair.second , childCharRange))
71
70
return true ;
72
71
}
73
72
0 commit comments