Skip to content

[IDE] Skip more nodes in CursorInfo’s NodeFinder #62479

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
37 changes: 36 additions & 1 deletion lib/IDE/CursorInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,17 @@ class NodeFinder : ASTWalker {
return Range.contains(LocToResolve);
}

PreWalkResult<ArgumentList *>
walkToArgumentListPre(ArgumentList *ArgList) override {
if (!rangeContainsLocToResolve(ArgList->getSourceRange())) {
return Action::SkipChildren(ArgList);
}
return Action::Continue(ArgList);
}

PreWalkAction walkToDeclPre(Decl *D) override {
if (!rangeContainsLocToResolve(D->getSourceRangeIncludingAttrs())) {
return PreWalkAction::SkipChildren;
return Action::SkipChildren();
}

if (auto *newDC = dyn_cast<DeclContext>(D)) {
Expand Down Expand Up @@ -182,6 +190,10 @@ class NodeFinder : ASTWalker {
}
}

if (!rangeContainsLocToResolve(E->getSourceRange())) {
return Action::SkipChildren(E);
}

return Action::Continue(E);
}

Expand All @@ -193,6 +205,20 @@ class NodeFinder : ASTWalker {
return Action::Continue(E);
}

PreWalkAction walkToParameterListPre(ParameterList *PL) override {
if (!rangeContainsLocToResolve(PL->getSourceRange())) {
return Action::SkipChildren();
}
return Action::Continue();
}

PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
if (!rangeContainsLocToResolve(P->getSourceRange())) {
return Action::SkipChildren(P);
}
return Action::Continue(P);
}

PreWalkResult<Stmt *> walkToStmtPre(Stmt *S) override {
if (auto CondStmt = dyn_cast<LabeledConditionalStmt>(S)) {
for (auto ShorthandShadow :
Expand All @@ -201,8 +227,17 @@ class NodeFinder : ASTWalker {
ShorthandShadowedDecls[ShorthandShadow.first] = ShorthandShadow.second;
}
}

if (!rangeContainsLocToResolve(S->getSourceRange())) {
return Action::SkipChildren(S);
}

return Action::Continue(S);
}

PreWalkAction walkToTypeReprPre(TypeRepr *T) override {
return Action::SkipChildren();
}
};

// MARK: - CursorInfoDoneParsingCallback
Expand Down