Skip to content

[IDE] Range info for accessor decl #17900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2018
Merged

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jul 12, 2018

Revised version of #17239.

Attributes on explicit accessor decl may have attributes. Only when the range contains those attributes (but not attributes on PatternBindingDecl), the range-info should report SingleDecl.

CC: @jrose-apple , @nkcsgexi

@rintaro
Copy link
Member Author

rintaro commented Jul 12, 2018

@swift-ci Please smoke test

lib/AST/Decl.cpp Outdated
continue;

SourceLoc AttrStartLoc = Attr->getRangeWithAt().Start;
if (getASTContext().SourceMgr.isBeforeInBuffer(VarLoc, AttrStartLoc))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& getASTContext().SourceMgr.isBeforeInBuffer(AttrStartLoc, Range.Start)

@rintaro rintaro force-pushed the rdar41073182-2 branch 3 times, most recently from ff704d7 to a58f570 Compare July 12, 2018 17:04
@rintaro
Copy link
Member Author

rintaro commented Jul 12, 2018

@swift-ci Please smoke test

subscript(idx: Int) -> Int {
@available(*, unavailable)
get { return 0 }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably have a test case with multiple attributes on the same accessor, just in case. (The code looks correct for that already, but still.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

lib/AST/Decl.cpp Outdated
SourceLoc AttrStartLoc = Attr->getRangeWithAt().Start;
if (getASTContext().SourceMgr.isBeforeInBuffer(VarLoc, AttrStartLoc) &&
getASTContext().SourceMgr.isBeforeInBuffer(AttrStartLoc, Range.Start))
Range.Start = AttrStartLoc;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use SourceRange::widen to avoid the second check. Slightly simpler.

Attributes on explicit accessor decl may have attributes. Only when the
range contains those attributes, the range-info should report
`SingleDecl`.
@rintaro
Copy link
Member Author

rintaro commented Jul 13, 2018

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Jul 13, 2018

@jrose-apple Mind approving this?

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, didn't realize you were waiting on me. Yes, this looks good.

@rintaro rintaro merged commit 50d93e2 into swiftlang:master Jul 13, 2018
@rintaro
Copy link
Member Author

rintaro commented Jul 13, 2018

Thank you!

@rintaro rintaro deleted the rdar41073182-2 branch July 13, 2018 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants