Skip to content

[CodeCompletion] Prioritize type matching overload for unresovled member #31307

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
Apr 27, 2020

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 25, 2020

For exmaple:

    func foo(_: Int, _: IntOption)
    func foo(_: Float, _: FloatOption)

    foo(intVal, .<HERE>)

Previously, code completion suggests static member from IntOption and FloatOption without any prioritization. Prioritize members from IntOption because the user probably wants to input them.

In such cases, CodeCompletionExpr at the cursor position is pre-typehcecked to IntOption. So mark results with matching type with ExprSpecific.

rdar://problem/62121221

@rintaro
Copy link
Member Author

rintaro commented Apr 25, 2020

@swift-ci Please smoke test

For exmaple:

    func foo(_: Int, _: IntOption)
    func foo(_: Float, _: FloatOption)

    foo(intVal, .<HERE>)

Previously code completion suggests static member from 'IntOption' and
'FloatOption' without any prioritization. Prioritize members from
'IntOption' because the user probably wants to input them.

In such cases, 'CodeCompletionExpr' at the cursor position is
pre-typechecked to 'IntOption'. So mark results with matching type with
'ExprSpecific'.

rdar://problem/62121221
@rintaro rintaro force-pushed the ide-completion-rdar62121221 branch from b92d0b5 to e947512 Compare April 25, 2020 01:02
@rintaro
Copy link
Member Author

rintaro commented Apr 25, 2020

@swift-ci Please smoke test

@rintaro rintaro requested a review from benlangmuir April 25, 2020 01:03
@rintaro
Copy link
Member Author

rintaro commented Apr 25, 2020

@swift-ci Please smoke test Linux

/// fooo(.<HERE>)
/// Prefer '.foo' and '.bar' over '.some' and '.none'.
idealTy = idealTy->lookThroughAllOptionalTypes();
return idealTy->isEqual(Ty);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isEqual instead of isConvertible?

Copy link
Member Author

@rintaro rintaro Apr 27, 2020

Choose a reason for hiding this comment

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

Returning convertible types by static member is pretty uncommon, I guess.

class Derived: Base { ... }
extension Base {
  static func createSub() -> Derived { ... }
}

I just didn't want to check them all by relatively heavy isConvertible() just for prioritization. But if you think it's worth it, I'm happy to do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine, just making sure I understand.

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