[CodeCompletion] Avoid expensive top-level lookups in type-specific completion

We can't afford to walk all the top-level results, which includes every
type and global function in the SDK.  Instead, use the usual caching
mechanisms.

This means we never get type relations on top-level SDK symbols, but
this should be fine for most cases because:

1) For ObjC code, we don't generally care about global functions. And
in practice most of the matching global functions for common types are
not high-priority anyway (e.g. alignof for Int).

2) In a previous commit I manually added the names of types so that we
can do later code completions to get initializers and static methods.
E.g. you will still get "CGRect" if you complete inside drawInRect(...).

Top-level results from the current module should be unaffected.

Swift SVN r31961
This commit is contained in:
Ben Langmuir
2015-09-15 18:12:01 +00:00
parent 253d56cbdf
commit 242859eb5f

View File

@@ -2444,9 +2444,7 @@ public:
addArgNameCompletionResults(ExpectedNames);
if (!ExpectedTypes.empty()) {
setExpectedTypes(ExpectedTypes);
getValueCompletionsInDeclContext(Loc, DefaultFilter,
/*IncludeTopLevel*/true,
/*RequestCache*/false);
getValueCompletionsInDeclContext(Loc, DefaultFilter);
}
return true;
}
@@ -3412,9 +3410,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
case CompletionKind::AssignmentRHS : {
SourceLoc Loc = P.Context.SourceMgr.getCodeCompletionLoc();
Lookup.setExpectedTypes(AssignmentExpr->getDest()->getType()->getRValueType());
Lookup.getValueCompletionsInDeclContext(Loc, DefaultFilter,
/*IncludeTopLevel*/true,
/*RequestCache*/false);
Lookup.getValueCompletionsInDeclContext(Loc, DefaultFilter);
break;
}
case CompletionKind::CallArg : {