-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SourceKit] Add documentation range in structure (SR-2487) #11264
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,3 +247,13 @@ StringRef Decl::getBriefComment() const { | |
Context.setBriefComment(this, Result); | ||
return Result; | ||
} | ||
|
||
CharSourceRange RawComment::getCharSourceRange(const SourceManager &SM) { | ||
if (this->isEmpty()) { | ||
return CharSourceRange(); | ||
} | ||
|
||
auto Start = this->Comments.front().Range.getStart(); | ||
auto End = this->Comments.back().Range.getEnd(); | ||
return CharSourceRange(SM, Start, End); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually don't need return CharSourceRange(Start, (char*)End.getOpaquePointerValue() -
(char*)Start.getOpaquePointerValue()); |
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -418,6 +418,12 @@ CharSourceRange parameterNameRangeOfCallArg(const TupleExpr *TE, | |
return CharSourceRange(); | ||
} | ||
|
||
static void setDecl(SyntaxStructureNode &N, Decl *D, const SourceManager &SM) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, we don't need |
||
N.Dcl = D; | ||
N.Attrs = D->getAttrs(); | ||
N.DocRange = D->getRawComment().getCharSourceRange(SM); | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
bool SyntaxModelContext::walk(SyntaxModelWalker &Walker) { | ||
|
@@ -753,7 +759,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
} else { | ||
// Pass Function / Method structure node. | ||
SyntaxStructureNode SN; | ||
SN.Dcl = D; | ||
setDecl(SN, D, SM); | ||
const DeclContext *DC = AFD->getDeclContext(); | ||
if (DC->isTypeContext()) { | ||
if (FD && FD->isStatic()) { | ||
|
@@ -772,12 +778,11 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
AFD->getBodySourceRange()); | ||
SN.NameRange = charSourceRangeFromSourceRange(SM, | ||
AFD->getSignatureSourceRange()); | ||
SN.Attrs = AFD->getAttrs(); | ||
pushStructureNode(SN, AFD); | ||
} | ||
} else if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) { | ||
SyntaxStructureNode SN; | ||
SN.Dcl = D; | ||
setDecl(SN, D, SM); | ||
SN.Kind = syntaxStructureKindFromNominalTypeDecl(NTD); | ||
SN.Range = charSourceRangeFromSourceRange(SM, NTD->getSourceRange()); | ||
SN.BodyRange = innerCharSourceRangeFromSourceRange(SM, NTD->getBraces()); | ||
|
@@ -792,12 +797,11 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
SN.Elements.emplace_back(SyntaxStructureElementKind::TypeRef, TR); | ||
} | ||
|
||
SN.Attrs = NTD->getAttrs(); | ||
pushStructureNode(SN, NTD); | ||
|
||
} else if (auto *ED = dyn_cast<ExtensionDecl>(D)) { | ||
SyntaxStructureNode SN; | ||
SN.Dcl = D; | ||
setDecl(SN, D, SM); | ||
SN.Kind = SyntaxStructureKind::Extension; | ||
SN.Range = charSourceRangeFromSourceRange(SM, ED->getSourceRange()); | ||
SN.BodyRange = innerCharSourceRangeFromSourceRange(SM, ED->getBraces()); | ||
|
@@ -811,7 +815,6 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
SN.Elements.emplace_back(SyntaxStructureElementKind::TypeRef, TR); | ||
} | ||
|
||
SN.Attrs = ED->getAttrs(); | ||
pushStructureNode(SN, ED); | ||
|
||
} else if (auto *PD = dyn_cast<ParamDecl>(D)) { | ||
|
@@ -832,7 +835,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
const DeclContext *DC = VD->getDeclContext(); | ||
if (DC->isTypeContext() || DC->isModuleScopeContext()) { | ||
SyntaxStructureNode SN; | ||
SN.Dcl = D; | ||
setDecl(SN, D, SM); | ||
SourceRange SR; | ||
if (auto *PBD = VD->getParentPatternBinding()) | ||
SR = PBD->getSourceRange(); | ||
|
@@ -863,7 +866,6 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
} else { | ||
SN.Kind = SyntaxStructureKind::GlobalVariable; | ||
} | ||
SN.Attrs = VD->getAttrs(); | ||
pushStructureNode(SN, VD); | ||
} | ||
|
||
|
@@ -915,7 +917,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
|
||
} else if (auto *EnumCaseD = dyn_cast<EnumCaseDecl>(D)) { | ||
SyntaxStructureNode SN; | ||
SN.Dcl = D; | ||
setDecl(SN, D, SM); | ||
SN.Kind = SyntaxStructureKind::EnumCase; | ||
SN.Range = charSourceRangeFromSourceRange(SM, D->getSourceRange()); | ||
|
||
|
@@ -939,7 +941,7 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
if (EnumElemD->getName().empty()) | ||
continue; | ||
SyntaxStructureNode SN; | ||
SN.Dcl = EnumElemD; | ||
setDecl(SN, EnumElemD, SM); | ||
SN.Kind = SyntaxStructureKind::EnumElement; | ||
SN.Range = charSourceRangeFromSourceRange(SM, | ||
EnumElemD->getSourceRange()); | ||
|
@@ -956,23 +958,21 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { | |
} | ||
} else if (auto *TypeAliasD = dyn_cast<TypeAliasDecl>(D)) { | ||
SyntaxStructureNode SN; | ||
SN.Dcl = TypeAliasD; | ||
setDecl(SN, D, SM); | ||
SN.Kind = SyntaxStructureKind::TypeAlias; | ||
SN.Range = charSourceRangeFromSourceRange(SM, | ||
TypeAliasD->getSourceRange()); | ||
SN.NameRange = CharSourceRange(TypeAliasD->getNameLoc(), | ||
TypeAliasD->getName().getLength()); | ||
SN.Attrs = TypeAliasD->getAttrs(); | ||
pushStructureNode(SN, TypeAliasD); | ||
} else if (auto *SubscriptD = dyn_cast<SubscriptDecl>(D)) { | ||
SyntaxStructureNode SN; | ||
SN.Dcl = SubscriptD; | ||
setDecl(SN, D, SM); | ||
SN.Kind = SyntaxStructureKind::Subscript; | ||
SN.Range = charSourceRangeFromSourceRange(SM, | ||
SubscriptD->getSourceRange()); | ||
SN.BodyRange = innerCharSourceRangeFromSourceRange(SM, | ||
SubscriptD->getBracesRange()); | ||
SN.Attrs = SubscriptD->getAttrs(); | ||
pushStructureNode(SN, SubscriptD); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have an early return if
Start
is invalid? cause the doc comment may come from a deserialized module file.