Skip to content

Commit 396bd8d

Browse files
authored
Merge pull request #20323 from rintaro/ide-codecompletion-revert-ancestors_within_brace
[CodeCompletion] Revert: "Restrict ancestor search to brace"
2 parents df0de4d + 8d1dca8 commit 396bd8d

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5241,7 +5241,6 @@ namespace {
52415241
friend class CodeCompletionTypeContextAnalyzer;
52425242
Expr *ChildExpr;
52435243
llvm::function_ref<bool(ParentTy, ParentTy)> Predicate;
5244-
bool AncestorsWithinBrace;
52455244

52465245
bool arePositionsSame(Expr *E1, Expr *E2) {
52475246
return E1->getSourceRange().Start == E2->getSourceRange().Start &&
@@ -5250,15 +5249,9 @@ namespace {
52505249

52515250
public:
52525251
llvm::SmallVector<ParentTy, 5> Ancestors;
5253-
llvm::SmallVector<size_t, 1> FarthestAncestorIndex;
5254-
ParentTy ParentClosest;
5255-
ParentTy ParentFarthest;
52565252
ExprParentFinder(Expr* ChildExpr,
5257-
llvm::function_ref<bool(ParentTy, ParentTy)> Predicate,
5258-
bool AncestorsWithinBrace = false) :
5259-
ChildExpr(ChildExpr), Predicate(Predicate),
5260-
AncestorsWithinBrace(AncestorsWithinBrace),
5261-
FarthestAncestorIndex({0}) {}
5253+
llvm::function_ref<bool(ParentTy, ParentTy)> Predicate) :
5254+
ChildExpr(ChildExpr), Predicate(Predicate) {}
52625255

52635256
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
52645257
// Finish if we found the target. 'ChildExpr' might have been replaced
@@ -5270,13 +5263,6 @@ namespace {
52705263
Ancestors.push_back(E);
52715264
return { true, E };
52725265
}
5273-
if (E == ChildExpr || arePositionsSame(E, ChildExpr)) {
5274-
if (!Ancestors.empty()) {
5275-
ParentClosest = Ancestors.back();
5276-
ParentFarthest = Ancestors[FarthestAncestorIndex.back()];
5277-
}
5278-
return {false, nullptr};
5279-
}
52805266
return { true, E };
52815267
}
52825268

@@ -5289,14 +5275,10 @@ namespace {
52895275
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
52905276
if (Predicate(S, Parent))
52915277
Ancestors.push_back(S);
5292-
if (AncestorsWithinBrace && isa<BraceStmt>(S))
5293-
FarthestAncestorIndex.push_back(Ancestors.size());
52945278
return { true, S };
52955279
}
52965280

52975281
Stmt *walkToStmtPost(Stmt *S) override {
5298-
if (AncestorsWithinBrace && isa<BraceStmt>(S))
5299-
FarthestAncestorIndex.pop_back();
53005282
if (Predicate(S, Parent))
53015283
Ancestors.pop_back();
53025284
return S;
@@ -5338,8 +5320,7 @@ class CodeCompletionTypeContextAnalyzer {
53385320
ExprParentFinder Finder;
53395321

53405322
public:
5341-
CodeCompletionTypeContextAnalyzer(DeclContext *DC, Expr *ParsedExpr,
5342-
bool AncestorsWithinBrace = false) : DC(DC),
5323+
CodeCompletionTypeContextAnalyzer(DeclContext *DC, Expr *ParsedExpr) : DC(DC),
53435324
ParsedExpr(ParsedExpr), SM(DC->getASTContext().SourceMgr),
53445325
Context(DC->getASTContext()),
53455326
Finder(ParsedExpr, [](ASTWalker::ParentTy Node, ASTWalker::ParentTy Parent) {
@@ -5389,7 +5370,7 @@ class CodeCompletionTypeContextAnalyzer {
53895370
}
53905371
} else
53915372
return false;
5392-
}, /*AncestorsWithinBrace=*/AncestorsWithinBrace) {}
5373+
}) {}
53935374

53945375
void analyzeExpr(Expr *Parent, llvm::function_ref<void(Type)> Callback,
53955376
SmallVectorImpl<StringRef> &PossibleNames) {
@@ -5647,7 +5628,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
56475628
if (isa<BindOptionalExpr>(ParsedExpr) || isa<ForceValueExpr>(ParsedExpr))
56485629
Lookup.setIsUnwrappedOptional(true);
56495630

5650-
::CodeCompletionTypeContextAnalyzer TypeAnalyzer(CurDeclContext, ParsedExpr);
5631+
::CodeCompletionTypeContextAnalyzer TypeAnalyzer(CurDeclContext,
5632+
ParsedExpr);
56515633
llvm::SmallVector<Type, 2> PossibleTypes;
56525634
if (TypeAnalyzer.Analyze(PossibleTypes)) {
56535635
Lookup.setExpectedTypes(PossibleTypes);
@@ -5692,7 +5674,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
56925674
case CompletionKind::ForEachSequence:
56935675
case CompletionKind::PostfixExprBeginning: {
56945676
::CodeCompletionTypeContextAnalyzer Analyzer(CurDeclContext,
5695-
CodeCompleteTokenExpr);
5677+
CodeCompleteTokenExpr);
56965678
llvm::SmallVector<Type, 1> Types;
56975679
if (Analyzer.Analyze(Types)) {
56985680
Lookup.setExpectedTypes(Types);
@@ -5720,7 +5702,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
57205702
Lookup.setHaveLParen(true);
57215703

57225704
::CodeCompletionTypeContextAnalyzer TypeAnalyzer(CurDeclContext,
5723-
CodeCompleteTokenExpr);
5705+
CodeCompleteTokenExpr);
57245706
SmallVector<Type, 2> PossibleTypes;
57255707
SmallVector<StringRef, 2> PossibleNames;
57265708
if (TypeAnalyzer.Analyze(PossibleTypes, PossibleNames)) {
@@ -5844,9 +5826,8 @@ void CodeCompletionCallbacksImpl::doneParsing() {
58445826
case CompletionKind::UnresolvedMember: {
58455827
Lookup.setHaveDot(DotLoc);
58465828
SmallVector<Type, 2> PossibleTypes;
5847-
::CodeCompletionTypeContextAnalyzer
5848-
TypeAnalyzer(CurDeclContext, CodeCompleteTokenExpr,
5849-
/*AncestorsWithinBrace=*/true);
5829+
::CodeCompletionTypeContextAnalyzer TypeAnalyzer(CurDeclContext,
5830+
CodeCompleteTokenExpr);
58505831
if (TypeAnalyzer.Analyze(PossibleTypes))
58515832
Lookup.setExpectedTypes(PossibleTypes);
58525833
Lookup.getUnresolvedMemberCompletions(PossibleTypes);

0 commit comments

Comments
 (0)