Skip to content

[CodeCompletion] Ignore implicit decl when finding equivalent decl #29377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/IDE/CompletionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ template <typename Range>
unsigned findIndexInRange(Decl *D, const Range &Decls) {
unsigned N = 0;
for (auto I = Decls.begin(), E = Decls.end(); I != E; ++I) {
if ((*I)->isImplicit())
continue;
if (*I == D)
return N;
++N;
Expand All @@ -66,6 +68,8 @@ unsigned findIndexInRange(Decl *D, const Range &Decls) {
/// Return the element at \p N in \p Decls .
template <typename Range> Decl *getElementAt(const Range &Decls, unsigned N) {
for (auto I = Decls.begin(), E = Decls.end(); I != E; ++I) {
if ((*I)->isImplicit())
continue;
if (N == 0)
return *I;
--N;
Expand Down Expand Up @@ -140,6 +144,8 @@ static DeclContext *getEquivalentDeclContextFromSourceFile(DeclContext *DC,
llvm_unreachable("invalid DC kind for finding equivalent DC (query)");

if (auto storage = dyn_cast<AbstractStorageDecl>(D)) {
if (IndexStack.empty())
return nullptr;
auto accessorN = IndexStack.pop_back_val();
D = getElementAt(storage->getAllAccessors(), accessorN);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@propertyWrapper
struct TwelveOrLess {
private var number = 0
var wrappedValue: Int {
get { return number }
set { number = min(newValue, 12) }
}
}

struct MyStruct {
@TwelveOrLess var value = 12

func foo() {}

func bar(barParam: Int) {

}
}

// RUN: %sourcekitd-test \
// RUN: -req=track-compiles == \
// RUN: -req=complete -req-opts=reuseastcontext=1 -pos=16:1 -repeat-request=2 %s -- %s > %t.response
// RUN: %FileCheck --check-prefix=RESULT %s < %t.response
// RUN: %FileCheck --check-prefix=TRACE %s < %t.response

// RESULT-LABEL: key.results: [
// RESULT-DAG: key.description: "barParam"
// RESULT: ]
// RESULT-LABEL: key.results: [
// RESULT-DAG: key.description: "barParam"
// RESULT: ]

// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE-NOT: key.description: "completion reusing previous ASTContext (benign diagnostic)"
// TRACE-LABEL: key.notification: source.notification.compile-did-finish,
// TRACE: key.description: "completion reusing previous ASTContext (benign diagnostic)"