Skip to content

Commit 7fc7040

Browse files
committed
[Macros] Drop special code completions for built-in macros.
We don't need special completion logic for things like `#file` and `#line` now that they are declared in the standard library. Drop it and update tests.
1 parent 6d6988b commit 7fc7040

File tree

6 files changed

+25
-154
lines changed

6 files changed

+25
-154
lines changed

include/swift/IDE/CompletionLookup.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
558558
void addTypeRelationFromProtocol(CodeCompletionResultBuilder &builder,
559559
CodeCompletionLiteralKind kind);
560560

561-
/// Add '#file', '#line', et at.
562-
void addPoundLiteralCompletions(bool needPound);
563-
564561
void addValueLiteralCompletions();
565562

566563
void addObjCPoundKeywordCompletions(bool needPound);

lib/IDE/AfterPoundExprCompletion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void AfterPoundExprCompletion::deliverResults(
5151
Result.IsImplicitSingleExpressionReturn,
5252
/*expectsNonVoid=*/true);
5353
Lookup.addPoundAvailable(ParentStmtKind);
54-
Lookup.addPoundLiteralCompletions(/*needPound=*/false);
5554
Lookup.addObjCPoundKeywordCompletions(/*needPound=*/false);
5655
Lookup.getMacroCompletions(/*needPound=*/false);
5756
}

lib/IDE/CompletionLookup.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,58 +2577,6 @@ void CompletionLookup::addTypeRelationFromProtocol(
25772577
}
25782578
}
25792579

2580-
void CompletionLookup::addPoundLiteralCompletions(bool needPound) {
2581-
CodeCompletionFlair flair;
2582-
if (isCodeCompletionAtTopLevelOfLibraryFile(CurrDeclContext))
2583-
flair |= CodeCompletionFlairBit::ExpressionAtNonScriptOrMainFileScope;
2584-
2585-
auto addFromProto = [&](MagicIdentifierLiteralExpr::Kind magicKind,
2586-
Optional<CodeCompletionLiteralKind> literalKind) {
2587-
CodeCompletionKeywordKind kwKind;
2588-
switch (magicKind) {
2589-
case MagicIdentifierLiteralExpr::FileIDSpelledAsFile:
2590-
kwKind = CodeCompletionKeywordKind::pound_file;
2591-
break;
2592-
case MagicIdentifierLiteralExpr::FilePathSpelledAsFile:
2593-
// Already handled by above case.
2594-
return;
2595-
#define MAGIC_IDENTIFIER_TOKEN(NAME, TOKEN) \
2596-
case MagicIdentifierLiteralExpr::NAME: \
2597-
kwKind = CodeCompletionKeywordKind::TOKEN; \
2598-
break;
2599-
#include "swift/AST/MagicIdentifierKinds.def"
2600-
}
2601-
2602-
StringRef name = MagicIdentifierLiteralExpr::getKindString(magicKind);
2603-
if (!needPound)
2604-
name = name.substr(1);
2605-
2606-
if (!literalKind) {
2607-
// Pointer type
2608-
addKeyword(name, "UnsafeRawPointer", kwKind, flair);
2609-
return;
2610-
}
2611-
2612-
CodeCompletionResultBuilder builder(Sink, CodeCompletionResultKind::Keyword,
2613-
SemanticContextKind::None);
2614-
builder.addFlair(flair);
2615-
builder.setLiteralKind(literalKind.value());
2616-
builder.setKeywordKind(kwKind);
2617-
builder.addBaseName(name);
2618-
addTypeRelationFromProtocol(builder, literalKind.value());
2619-
};
2620-
2621-
#define MAGIC_STRING_IDENTIFIER(NAME, STRING, SYNTAX_KIND) \
2622-
addFromProto(MagicIdentifierLiteralExpr::NAME, \
2623-
CodeCompletionLiteralKind::StringLiteral);
2624-
#define MAGIC_INT_IDENTIFIER(NAME, STRING, SYNTAX_KIND) \
2625-
addFromProto(MagicIdentifierLiteralExpr::NAME, \
2626-
CodeCompletionLiteralKind::IntegerLiteral);
2627-
#define MAGIC_POINTER_IDENTIFIER(NAME, STRING, SYNTAX_KIND) \
2628-
addFromProto(MagicIdentifierLiteralExpr::NAME, None);
2629-
#include "swift/AST/MagicIdentifierKinds.def"
2630-
}
2631-
26322580
void CompletionLookup::addValueLiteralCompletions() {
26332581
auto &context = CurrDeclContext->getASTContext();
26342582

@@ -2802,7 +2750,6 @@ void CompletionLookup::getValueCompletionsInDeclContext(SourceLoc Loc,
28022750

28032751
if (LiteralCompletions) {
28042752
addValueLiteralCompletions();
2805-
addPoundLiteralCompletions(/*needPound=*/true);
28062753
}
28072754

28082755
addObjCPoundKeywordCompletions(/*needPound=*/true);

test/IDE/complete_pound_expr.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ func test1() {
1616
}
1717

1818
// POUND_EXPR_INTCONTEXT: Begin completions, 8 items
19-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#function]/None: function[#String#]; name=function
20-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#file]/None: file[#String#]; name=file
21-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#fileID]/None: fileID[#String#]; name=fileID
22-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#filePath]/None: filePath[#String#]; name=filePath
23-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#line]/None/TypeRelation[Convertible]: line[#Int#]; name=line
24-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#column]/None/TypeRelation[Convertible]: column[#Int#]; name=column
25-
// POUND_EXPR_INTCONTEXT-DAG: Keyword[#dsohandle]/None: dsohandle[#UnsafeRawPointer#]; name=dsohandle
19+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: function[#ExpressibleByStringLiteral#]; name=function
20+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: fileID[#ExpressibleByStringLiteral#]; name=fileID
21+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: file[#ExpressibleByStringLiteral#]; name=file
22+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: dsohandle[#UnsafeRawPointer#]; name=dsohandle
23+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: column[#ExpressibleByIntegerLiteral#]; name=column
24+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: line[#ExpressibleByIntegerLiteral#]; name=line
2625
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: externalMacro({#module: String#}, {#type: String#})[#T#]; name=externalMacro(module:type:)
26+
// POUND_EXPR_INTCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: filePath[#ExpressibleByStringLiteral#]; name=filePath
2727
// POUND_EXPR_INTCONTEXT: End completions
2828

2929
// POUND_EXPR_STRINGCONTEXT: Begin completions, 9 items
30-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#function]/None/TypeRelation[Convertible]: function[#String#];
31-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#file]/None/TypeRelation[Convertible]: file[#String#];
32-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#fileID]/None/TypeRelation[Convertible]: fileID[#String#];
33-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#filePath]/None/TypeRelation[Convertible]: filePath[#String#];
34-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#line]/None: line[#Int#];
35-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#column]/None: column[#Int#];
36-
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword[#dsohandle]/None: dsohandle[#UnsafeRawPointer#];
30+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: function[#ExpressibleByStringLiteral#]; name=function
31+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: fileID[#ExpressibleByStringLiteral#]; name=fileID
32+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: file[#ExpressibleByStringLiteral#]; name=file
33+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: dsohandle[#UnsafeRawPointer#]; name=dsohandle
34+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: column[#ExpressibleByIntegerLiteral#]; name=column
35+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: line[#ExpressibleByIntegerLiteral#]; name=line
36+
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: filePath[#ExpressibleByStringLiteral#]; name=filePath
3737
// POUND_EXPR_STRINGCONTEXT-DAG: Keyword/None/TypeRelation[Convertible]: keyPath({#@objc property sequence#})[#String#];
3838
// POUND_EXPR_STRINGCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: externalMacro({#module: String#}, {#type: String#})[#T#]; name=externalMacro(module:type:)
3939
// POUND_EXPR_STRINGCONTEXT: End completions
4040

4141
// POUND_EXPR_SELECTORCONTEXT: Begin completions, 9 items
42-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#function]/None/TypeRelation[Convertible]: function[#Selector#];
43-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#file]/None/TypeRelation[Convertible]: file[#Selector#];
44-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#fileID]/None/TypeRelation[Convertible]: fileID[#Selector#];
45-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#filePath]/None/TypeRelation[Convertible]: filePath[#Selector#];
46-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#line]/None: line[#Int#];
47-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#column]/None: column[#Int#];
48-
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword[#dsohandle]/None: dsohandle[#UnsafeRawPointer#];
42+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: function[#ExpressibleByStringLiteral#]; name=function
43+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: fileID[#ExpressibleByStringLiteral#]; name=fileID
44+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: file[#ExpressibleByStringLiteral#]; name=file
45+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: dsohandle[#UnsafeRawPointer#]; name=dsohandle
46+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: column[#ExpressibleByIntegerLiteral#]; name=column
47+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: line[#ExpressibleByIntegerLiteral#]; name=line
48+
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: filePath[#ExpressibleByStringLiteral#]; name=filePath
4949
// POUND_EXPR_SELECTORCONTEXT-DAG: Keyword/None/TypeRelation[Convertible]: selector({#@objc method#})[#Selector#];
5050
// POUND_EXPR_SELECTORCONTEXT-DAG: Decl[Macro]/OtherModule[Swift]/IsSystem: externalMacro({#module: String#}, {#type: String#})[#T#]; name=externalMacro(module:type:)
5151
// POUND_EXPR_SELECTORCONTEXT: End completions

test/IDE/complete_pound_expr_macros.swift

Lines changed: 0 additions & 72 deletions
This file was deleted.

test/Parse/invalid.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ func test3() {
1111
undeclared_func( // expected-error {{cannot find 'undeclared_func' in scope}}
1212
} // expected-error {{expected expression in list of expressions}}
1313

14-
func runAction() {} // expected-note {{'runAction' declared here}}
14+
func runAction() {} // expected-note {{did you mean 'runAction'?}}
1515

1616
// rdar://16601779
1717
func foo() {
1818
// expected-error@+3 {{argument passed to call that takes no arguments}}
19-
// expected-error@+2 {{cannot find 'SKAction' in scope; did you mean 'runAction'?}} {{13-21=runAction}}
20-
// expected-error@+1 {{expected ',' separator}} {{32-32=,}}
19+
// expected-error@+2 {{cannot find 'SKAction' in scope}}
20+
// expected-error@+1 {{expected ',' separator}}
2121
runAction(SKAction.sequence()
22-
22+
2323
skview!
2424
// expected-error @-1 {{cannot find 'skview' in scope}}
2525
}

0 commit comments

Comments
 (0)