[IDE] Range info for accessor decl.

Attributes on explicit accessor decl may have attributes. Only when the
range contains those attributes, the range-info should report
`SingleDecl`.
This commit is contained in:
Rintaro Ishizaki
2018-07-12 19:28:38 +09:00
parent 274114d4a2
commit 20a1e5db23
2 changed files with 86 additions and 4 deletions

View File

@@ -376,12 +376,32 @@ case DeclKind::ID: return cast<ID##Decl>(this)->getSourceRange();
SourceRange Decl::getSourceRangeIncludingAttrs() const {
auto Range = getSourceRange();
// Attributes on AccessorDecl are syntactically belong to PatternBindingDecl.
if (isa<AccessorDecl>(this) || isa<VarDecl>(this))
// Attributes on AccessorDecl may syntactically belong to PatternBindingDecl.
// e.g. 'override'.
if (auto *AD = dyn_cast<AccessorDecl>(this)) {
// If this is implicit getter, accessor range should not include attributes.
if (!AD->getAccessorKeywordLoc().isValid())
return Range;
// Otherwise, include attributes directly attached to the accessor.
SourceLoc VarLoc = AD->getStorage()->getStartLoc();
for (auto Attr : getAttrs()) {
if (!Attr->getRange().isValid())
continue;
SourceLoc AttrStartLoc = Attr->getRangeWithAt().Start;
if (getASTContext().SourceMgr.isBeforeInBuffer(VarLoc, AttrStartLoc))
Range.widen(AttrStartLoc);
}
return Range;
}
// Attributes on VarDecl syntactically belong to PatternBindingDecl.
if (isa<VarDecl>(this))
return Range;
// Attributes on PatternBindingDecls are attached to VarDecls in AST.
if (const PatternBindingDecl *PBD = dyn_cast<PatternBindingDecl>(this)) {
if (auto *PBD = dyn_cast<PatternBindingDecl>(this)) {
for (auto Entry : PBD->getPatternList())
Entry.getPattern()->forEachVariable([&](VarDecl *VD) {
for (auto Attr : VD->getAttrs())