Skip to content

Conversation

@AnthonyLatsis
Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis commented May 13, 2018

Fixed duplicate completions for generic parameters in non-generic members.
This also fixed the SemanticContextKind for some related tests.

Resolves SR-7670.

fixed duplicate completions for generic parameters in non-generic members
this also fixed the SemanticContextKind for some tests
if (auto decl = DC->getAsDeclOrDeclExtensionContext()) {
if (auto GC = decl->getAsGenericContext()) {
auto params = GC->getGenericParams();
namelookup::FindLocalVal(SM, Loc, Consumer).checkGenericParams(params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just inlines getGenericParamsOfContext() - but drops a check for being in an extension. Could you revert to just the call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is pointless since I'm retrieving only the parameters of the current context. What do you mean by reverting to just the call?

@CodaFi
Copy link
Contributor

CodaFi commented May 13, 2018

The explanation in the SR is correct but the fix being in NameLookup is suspicious.

@benlangmuir Is there somewhere in code completion where generic parameters can be de-duplicated?

@AnthonyLatsis
Copy link
Collaborator Author

I've dug up the problem and I am sure that the generic parameters of a nominal type are looked up as members. Because of the way getGenericParamsOfContext() works, they sometimes get added there as well before performing member lookup.

@CodaFi
Copy link
Contributor

CodaFi commented May 13, 2018

Yes, the diagnosis is correct. But this change to name lookup doesn't seem so. If CodeCompletion is making multiple requests and receiving duplicate values because they share an ancestor DeclContext, then CodeCompletion needs to handle that, no?

@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented May 13, 2018

Edit I misunderstood. I see what you mean now. I don't really see though how duplicates can happen this way if we are looking up one concrete thing (the completions at the position of the cursor). And I don't think there is a de-duplicator – that would be expensive (code completion is already slow). Let's see what Ben says.

@slavapestov
Copy link
Contributor

Can you add a new test that fails without your change?

@AnthonyLatsis
Copy link
Collaborator Author

@slavapestov Good idea. Give me an hour

@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented May 14, 2018

What is the difference between

// CHECK: Decl[GenericTypeParam]/Local: T[#T#]{{; name=.+$}}

and

// CHECK: Decl[GenericTypeParam]/Local: T[#T#]; name=T

?
They seem to be used on tests with analogous completions.

@xedin
Copy link
Contributor

xedin commented May 14, 2018

.+ is going to match any symbol not just T, I think the second example is more correct is pamater names are supposed to match.

@AnthonyLatsis
Copy link
Collaborator Author

@xedin So in other words it will ignore the name?

@xedin
Copy link
Contributor

xedin commented May 14, 2018

@AnthonyLatsis Yes, that's right.

@AnthonyLatsis
Copy link
Collaborator Author

@slavapestov Thank you for calling me to do the failing tests, I discovered the problem still persisted for subscripts and fixed that as well.

@slavapestov
Copy link
Contributor

Thanks! The change looks good to me, but @benlangmuir or @nkcsgexi should also take a look.

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented May 14, 2018

It failed right away?

Thanks! The change looks good to me, but @benlangmuir or @nkcsgexi should also take a look.

No problem, I'm all for it.

@slavapestov
Copy link
Contributor

@AnthonyLatsis yeah, there's some kind of problem with Linux CI right now.

@slavapestov
Copy link
Contributor

@swift-ci smoke test

1 similar comment
@slavapestov
Copy link
Contributor

@swift-ci smoke test

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AnthonyLatsis
Copy link
Collaborator Author

Are we waiting for Ben to have a look?

@nkcsgexi
Copy link
Contributor

@benlangmuir any more comments on this PR?

@benlangmuir
Copy link
Contributor

@nkcsgexi go ahead and merge if you're happy with this. If you think there's something here that I should review let me know.

@nkcsgexi
Copy link
Contributor

OK! 🚢

@nkcsgexi nkcsgexi merged commit 713eb1a into swiftlang:master May 17, 2018
@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented May 23, 2018

.+ is going to match any symbol not just T, I think the second example is more correct is pamater names are supposed to match.

@xedin, do you know if it is possible to do the same trick with another part of the string? For example:

// CHECK: Decl[InstanceMethod]/{{.+:}} foo()[#Void#]; name=foo()

I've tried with no success.

@xedin
Copy link
Contributor

xedin commented May 23, 2018

@AnthonyLatsis You can do it anywhere in the string since it's just a regex

@AnthonyLatsis AnthonyLatsis deleted the dup-gen-param-completion-member-decl branch February 17, 2022 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants