Files
swift-mirror/include/swift/IDE/UnresolvedMemberCompletion.h
Hamish Knight 30af99e47e [Completion] Better handle merging of lookup base types
For unresolved member completion, we were preferring
the more general type, when we ought to be preferring
the more specific type. Additionally, for both
unresolved member and postfix completion we were
opening archetypes, which doesn't work as expected
since we don't compare requirements. Factor out
the logic that deals with merging base types for
lookup, and have it prefer either the subtype, or
the optional type in the case of optional promotion.

rdar://126168123
2024-06-07 10:04:31 +01:00

66 lines
2.1 KiB
C++

//===--- UnresolvedMemberCompletion.h -------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IDE_UNRESOLVEDMEMBERCOMPLETION_H
#define SWIFT_IDE_UNRESOLVEDMEMBERCOMPLETION_H
#include "swift/IDE/CodeCompletionConsumer.h"
#include "swift/IDE/CodeCompletionContext.h"
#include "swift/IDE/TypeCheckCompletionCallback.h"
namespace swift {
namespace ide {
/// Used to collect and store information needed to perform unresolved member
/// completion (\c CompletionKind::UnresolvedMember ) from the solutions
/// formed during expression type-checking.
class UnresolvedMemberTypeCheckCompletionCallback
: public TypeCheckCompletionCallback {
struct Result {
Type ExpectedTy;
bool IsImpliedResult;
/// Whether the surrounding context is async and thus calling async
/// functions is supported.
bool IsInAsyncContext;
/// Attempts to merge this result with \p Other, returning \c true if
/// successful, else \c false.
bool tryMerge(const Result &Other, DeclContext *DC);
};
CodeCompletionExpr *CompletionExpr;
DeclContext *DC;
SmallVector<Result, 4> ExprResults;
SmallVector<Result, 1> EnumPatternTypes;
/// Add a result to \c Results, merging it with an existing result, if
/// possible.
void addExprResult(const Result &Res);
void sawSolutionImpl(const constraints::Solution &solution) override;
public:
UnresolvedMemberTypeCheckCompletionCallback(
CodeCompletionExpr *CompletionExpr, DeclContext *DC)
: CompletionExpr(CompletionExpr), DC(DC) {}
void collectResults(DeclContext *DC, SourceLoc DotLoc,
ide::CodeCompletionContext &CompletionCtx);
};
} // end namespace ide
} // end namespace swift
#endif // SWIFT_IDE_UNRESOLVEDMEMBERCOMPLETION_H