@@ -238,6 +238,35 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
238
238
Info.BaseTy , HasLabel, IsAsync, SolutionSpecificVarTypes});
239
239
}
240
240
241
+ void ArgumentTypeCheckCompletionCallback::computeShadowedDecls (
242
+ SmallPtrSetImpl<ValueDecl *> &ShadowedDecls) {
243
+ for (size_t i = 0 ; i < Results.size (); ++i) {
244
+ auto &ResultA = Results[i];
245
+ for (size_t j = i + 1 ; j < Results.size (); ++j) {
246
+ auto &ResultB = Results[j];
247
+ if (!ResultA.FuncD || !ResultB.FuncD || !ResultA.FuncTy || !ResultB.FuncTy ) {
248
+ continue ;
249
+ }
250
+ if (ResultA.FuncD ->getName () != ResultB.FuncD ->getName ()) {
251
+ continue ;
252
+ }
253
+ if (!ResultA.FuncTy ->isEqual (ResultB.FuncTy )) {
254
+ continue ;
255
+ }
256
+ ProtocolDecl *inProtocolExtensionA =
257
+ ResultA.FuncD ->getDeclContext ()->getExtendedProtocolDecl ();
258
+ ProtocolDecl *inProtocolExtensionB =
259
+ ResultB.FuncD ->getDeclContext ()->getExtendedProtocolDecl ();
260
+
261
+ if (inProtocolExtensionA && !inProtocolExtensionB) {
262
+ ShadowedDecls.insert (ResultA.FuncD );
263
+ } else if (!inProtocolExtensionA && inProtocolExtensionB) {
264
+ ShadowedDecls.insert (ResultB.FuncD );
265
+ }
266
+ }
267
+ }
268
+ }
269
+
241
270
void ArgumentTypeCheckCompletionCallback::deliverResults (
242
271
bool IncludeSignature, SourceLoc Loc, DeclContext *DC,
243
272
ide::CodeCompletionContext &CompletionCtx,
@@ -246,6 +275,9 @@ void ArgumentTypeCheckCompletionCallback::deliverResults(
246
275
CompletionLookup Lookup (CompletionCtx.getResultSink (), Ctx, DC,
247
276
&CompletionCtx);
248
277
278
+ SmallPtrSet<ValueDecl *, 4 > ShadowedDecls;
279
+ computeShadowedDecls (ShadowedDecls);
280
+
249
281
// Perform global completion as a fallback if we don't have any results.
250
282
bool shouldPerformGlobalCompletion = Results.empty ();
251
283
SmallVector<Type, 4 > ExpectedCallTypes;
@@ -290,13 +322,17 @@ void ArgumentTypeCheckCompletionCallback::deliverResults(
290
322
}
291
323
if (Result.FuncTy ) {
292
324
if (auto FuncTy = Result.FuncTy ) {
293
- if (Result.IsSubscript ) {
294
- assert (SemanticContext != SemanticContextKind::None);
295
- auto *SD = dyn_cast_or_null<SubscriptDecl>(Result.FuncD );
296
- Lookup.addSubscriptCallPattern (FuncTy, SD, SemanticContext);
297
- } else {
298
- auto *FD = dyn_cast_or_null<AbstractFunctionDecl>(Result.FuncD );
299
- Lookup.addFunctionCallPattern (FuncTy, FD, SemanticContext);
325
+ if (ShadowedDecls.count (Result.FuncD ) == 0 ) {
326
+ // Don't show call pattern completions if the function is
327
+ // overridden.
328
+ if (Result.IsSubscript ) {
329
+ assert (SemanticContext != SemanticContextKind::None);
330
+ auto *SD = dyn_cast_or_null<SubscriptDecl>(Result.FuncD );
331
+ Lookup.addSubscriptCallPattern (FuncTy, SD, SemanticContext);
332
+ } else {
333
+ auto *FD = dyn_cast_or_null<AbstractFunctionDecl>(Result.FuncD );
334
+ Lookup.addFunctionCallPattern (FuncTy, FD, SemanticContext);
335
+ }
300
336
}
301
337
}
302
338
}
0 commit comments