Skip to content

Commit

Permalink
[Completion] Add completion for sending specifier
Browse files Browse the repository at this point in the history
This was added in SE-0430.

rdar://130296278
  • Loading branch information
hamishknight committed Jun 21, 2024
1 parent 3d57297 commit f842cba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 6 additions & 2 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,14 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
addKeyword(Sink, "consuming", CodeCompletionKeywordKind::None);
addKeyword(Sink, "isolated", CodeCompletionKeywordKind::None);
LLVM_FALLTHROUGH;
case CompletionKind::TypeDeclResultBeginning:
addKeyword(Sink, "sending", CodeCompletionKeywordKind::None);
LLVM_FALLTHROUGH;
case CompletionKind::TypeBeginning:
addKeyword(Sink, "repeat", CodeCompletionKeywordKind::None);
// Not technically allowed after '->', since you need to write in parens.
if (Kind != CompletionKind::TypeDeclResultBeginning)
addKeyword(Sink, "repeat", CodeCompletionKeywordKind::None);
LLVM_FALLTHROUGH;
case CompletionKind::TypeDeclResultBeginning:
case CompletionKind::TypeSimpleOrComposition:
addKeyword(Sink, "some", CodeCompletionKeywordKind::None);
addKeyword(Sink, "any", CodeCompletionKeywordKind::None);
Expand Down
22 changes: 18 additions & 4 deletions test/IDE/complete_param_specifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func bar(_ x: borrowing #^FUNC_PARAM_2?check=SPECIFIER^#) {}

struct S {
init(x: #^INIT_PARAM?check=SPECIFIER^#) {}
subscript(x: #SUBSCRIPT_PARAM?check=SPECIFIER#) {}
subscript(x: #SUBSCRIPT_PARAM?check=SPECIFIER#) -> #^SUBSCRIPT_RET?check=RESULT;check=RESULT_NOT^# {}
}

// Don't complete for enum cases.
Expand All @@ -22,18 +22,32 @@ enum E {
case f(x: #^ENUM_CASE_LABELED_TY?check=SPECIFIER_NOT^#)
}

// Don't complete for a regular variable type.
let x: #^VAR_TY?check=SPECIFIER_NOT^#
// Don't complete the parameter specifiers for a variable type.
//
// Note that we will still complete 'sending' here, even though it isn't
// currently supported for computed properties (it is supported for functions
// and subscripts though).
let x: #^VAR_TY?check=RESULT;check=RESULT_NOT^#
var y: #^VAR_TY2?check=RESULT;check=RESULT_NOT^#

// Or for a return type.
func bar() -> #^RETURN_TY?check=SPECIFIER_NOT^# {}
func bar() -> #^RESULT_TY?check=RESULT;check=RESULT_NOT^# {}

// SPECIFIER-DAG: Keyword[inout]/None: inout; name=inout
// SPECIFIER-DAG: Keyword/None: consuming; name=consuming
// SPECIFIER-DAG: Keyword/None: borrowing; name=borrowing
// SPECIFIER-DAG: Keyword/None: isolated; name=isolated
// SPECIFIER-DAG: Keyword/None: sending; name=sending

// SPECIFIER_NOT-NOT: Keyword[inout]/None: inout
// SPECIFIER_NOT-NOT: Keyword/None: consuming
// SPECIFIER_NOT-NOT: Keyword/None: borrowing
// SPECIFIER_NOT-NOT: Keyword/None: isolated
// SPECIFIER_NOT-NOT: Keyword/None: sending

// RESULT_NOT-NOT: Keyword[inout]/None: inout
// RESULT_NOT-NOT: Keyword/None: consuming
// RESULT_NOT-NOT: Keyword/None: borrowing
// RESULT_NOT-NOT: Keyword/None: isolated

// RESULT-DAG: Keyword/None: sending

0 comments on commit f842cba

Please sign in to comment.