Code completion: don't show [byref] on 'self'

Of course, in structs 'self' is a reference to the value, but this is so
obvious and natural, that calling out this [byref] in code completion results
every single time adds nothing but syntactic noise.

We still show [byref] in other cases, for example, when we complete references
to user-written function parameters.


Swift SVN r8464
This commit is contained in:
Dmitri Hrybenko
2013-09-19 21:31:33 +00:00
parent 8324827297
commit bd38bc4c06

View File

@@ -480,6 +480,7 @@ namespace {
class CompletionLookup : swift::VisibleDeclConsumer {
CodeCompletionContext &CompletionContext;
ASTContext &SwiftContext;
Identifier SelfIdent;
const DeclContext *CurrDeclContext;
enum class LookupKind {
@@ -517,6 +518,7 @@ public:
ASTContext &SwiftContext,
const DeclContext *CurrDeclContext)
: CompletionContext(CompletionContext), SwiftContext(SwiftContext),
SelfIdent(SwiftContext.getIdentifier("self")),
CurrDeclContext(CurrDeclContext) {
// Determine if we are doing code completion inside a static method.
if (CurrDeclContext->isLocalContext()) {
@@ -575,7 +577,15 @@ public:
if (needDot())
Builder.addLeadingDot();
Builder.addTextChunk(Name);
addTypeAnnotation(Builder, VD->getType());
// Add a type annotation.
Type T = VD->getType();
if (VD->getName() == SelfIdent) {
// Strip [byref] from 'self'. It is useful to show [byref] for function
// parameters. But for 'self' it is just noise.
T = T->getRValueType();
}
addTypeAnnotation(Builder, T);
}
void addPatternParameters(CodeCompletionResultBuilder &Builder,