Skip to content

IDE: Expose a utility to collect argument label ranges from either tuple or paren exprs. NFC #8982

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
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ class SourceEditOutputConsumer : public SourceEditConsumer {
~SourceEditOutputConsumer();
void accept(SourceManager &SM, RegionType RegionType, ArrayRef<Replacement> Replacements) override;
};

// Get the ranges of argument labels from an Arg, either tuple or paren.
std::vector<CharSourceRange> getCallArgLabelRanges(SourceManager &SM, Expr *Arg);
} // namespace ide
} // namespace swift

Expand Down
24 changes: 24 additions & 0 deletions lib/IDE/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,27 @@ void swift::ide::getLocationInfo(const ValueDecl *VD,
DeclarationLoc, Filename);
}
}

std::vector<CharSourceRange> swift::ide::
getCallArgLabelRanges(SourceManager &SM, Expr *Arg) {
std::vector<CharSourceRange> Ranges;
if (TupleExpr *TE = dyn_cast<TupleExpr>(Arg)) {
size_t ElemIndex = 0;
for(Expr *Elem: TE->getElements()) {
SourceLoc LabelStart(Elem->getStartLoc());
SourceLoc LabelEnd(LabelStart);

auto NameIdentifier = TE->getElementName(ElemIndex);
if (!NameIdentifier.empty()) {
LabelStart = TE->getElementNameLoc(ElemIndex);
}
Ranges.push_back(CharSourceRange(SM, LabelStart, LabelEnd));
++ElemIndex;
}
} else if (ParenExpr *PE = dyn_cast<ParenExpr>(Arg)) {
if (PE->getSubExpr())
Ranges.push_back(CharSourceRange(PE->getSubExpr()->getStartLoc(), 0));
}

return Ranges;
}