Skip to content

[CodeCompletion] Dont mark type mismatching items 'not recommended' #31474

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

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 1, 2020

func foo() {}
let a: Int = #^HERE^#

Previously, we marked foo() as NotRecommented because Void doesn't have any member hence it cannot be Int. But it was confusing with deprecated.

Now that we output 'typerelation' which is 'invalid' in this case. So clients can de-prioritize them, or even filter them out.

rdar://problem/57726512

@@ -1240,7 +1240,7 @@ CodeCompletionResult *CodeCompletionResultBuilder::takeResult() {
typeRelation =
calculateMaxTypeRelationForDecl(AssociatedDecl, declTypeContext);

if (typeRelation == CodeCompletionResult::Invalid) {
if (!IsNotRecommended && typeRelation == CodeCompletionResult::Invalid) {
IsNotRecommended = true;
NotRecReason = CodeCompletionResult::NotRecommendedReason::TypeMismatch;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

At this point, I don't remove this because complete.open uses this for sorting, and I don't want to change them to use the type relation. It'd be non trivial change.

@rintaro
Copy link
Member Author

rintaro commented May 1, 2020

@swift-ci Please smoke test

@rintaro rintaro force-pushed the sourcekit-completion-invalidtyperelation-rdar57726512 branch from dc6b1d7 to b4b7a1f Compare May 1, 2020 20:44
@rintaro
Copy link
Member Author

rintaro commented May 1, 2020

@swift-ci Please smoke test

@rintaro rintaro requested a review from benlangmuir May 2, 2020 00:03
Copy link
Contributor

@benlangmuir benlangmuir left a comment

Choose a reason for hiding this comment

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

The original idea with "NotRecommendedReason" was we have various kinds of "invalid" symbols, and we could expose the reason so clients could decide how they wanted to mark them up. For example, we also show module names as "not recommended" when they are already imported, which is also distinct from "deprecated".

Have you considered exposing the NotRecommendedReason instead and letting the client decide?

@rintaro
Copy link
Member Author

rintaro commented May 4, 2020

Have you considered exposing the NotRecommendedReason instead and letting the client decide?

Yes, but I don't think the reason should have TypeMismatch even if we expose it. We already exposed the type relation which is "invalid" in this case, so "Not recommended for type mismatch" would be a duplicated information for clients.

@benlangmuir
Copy link
Contributor

Okay, I don't have a strong preference and I'm okay with this approach. I would prefer we cleanup the internal API as well though. I'm not clear why you think that would be a big change? CodeCompletionOrganizer already uses the type relations, so I don't see why we couldn't handle "invalid" specifically in the places where we currently handle "not recommended".

@rintaro rintaro force-pushed the sourcekit-completion-invalidtyperelation-rdar57726512 branch from b4b7a1f to de36957 Compare May 5, 2020 03:18
@rintaro
Copy link
Member Author

rintaro commented May 5, 2020

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented May 5, 2020

Removed TypeMismatch from NotRecommendedReason.
@benlangmuir Could you review this again?

@@ -705,17 +704,18 @@ class CodeCompletionResult {
StringRef BriefDocComment,
ArrayRef<StringRef> AssociatedUSRs,
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
enum ExpectedTypeRelation TypeDistance,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is "enum" used here? I would expect the type name to be unambiiguous in this context

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, just a copy/paste mistake.

func foo() {}
let a: Int = #^HERE^#

Previously, we marked 'foo()' as 'NotRecommented' because 'Void' doesn't
have any member hence it cannot be 'Int'. But it wass confusing with
'deprecated'.

Now that we output 'typerelation' which is 'invalid' in this case. So clients
can deprioritize results, or even filter them out.

rdar://problem/57726512
@rintaro rintaro force-pushed the sourcekit-completion-invalidtyperelation-rdar57726512 branch from de36957 to e9c438c Compare May 5, 2020 17:40
@rintaro
Copy link
Member Author

rintaro commented May 5, 2020

@swift-ci Please smoke test

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.

2 participants