Skip to content
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

Add option to configure automatic optional chain completions #34552

Merged
merged 8 commits into from
Oct 19, 2019

Conversation

DanielRosenwasser
Copy link
Member

Fixes #34542

@DanielRosenwasser DanielRosenwasser force-pushed the includeAutomaticOptionalChainCompletions branch from b871ef4 to 4eca13e Compare October 18, 2019 00:10
@DanielRosenwasser
Copy link
Member Author

Hey @typescript-bot where the heck are you? You're supposed to yell at @minestarks @amcasey and @mjbvz that there's been a protocol change.

@DanielRosenwasser
Copy link
Member Author

Oh, uh, I know the issue.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

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

My reading is that VS doesn't have to do anything unless it wants to add a checkbox to let users disable ?. completions. Is that right?

const insertQuestionDot = origin && originIsNullableMember(origin);
if (insertQuestionDot && preferences === false) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this was supposed to be preferences.includeAutomaticOptionalChainCompletions === false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, comparability strikes - UserPreferences is all-optional and weak type checks don't get applied in comparisons.

Copy link

@fatcerberus fatcerberus Oct 19, 2019

Choose a reason for hiding this comment

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

Out of curiosity, why is any object type considered comparable to a primitive type like boolean? I don't think the result of any such comparison could ever be meaningful, since objects are compared by reference at runtime (i.e. it would always compare false).

Copy link
Member

Choose a reason for hiding this comment

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

@fatcerberus an object type doesn't imply an object value. "hello world" is a valid { toString(): string }

Choose a reason for hiding this comment

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

No, I get why it’s assignable. I’m confused why it’s comparible, as the comparison is never meaningful.

Does assignability always imply comparability?

Copy link
Member Author

Choose a reason for hiding this comment

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

Assignability should imply comparability - at least, that was always the intent. Ideally the hierarchy is

comparable to ≥ assignable to ≥ a subtype of ≥ identical to

src/server/protocol.ts Outdated Show resolved Hide resolved
@DanielRosenwasser DanielRosenwasser force-pushed the includeAutomaticOptionalChainCompletions branch from eb2c4d2 to 3d7451c Compare October 18, 2019 00:42
@DanielRosenwasser
Copy link
Member Author

My reading is that VS doesn't have to do anything unless it wants to add a checkbox to let users disable ?. completions. Is that right?

That's correct!

@DanielRosenwasser DanielRosenwasser changed the title Include automatic optional chain completions Add option to configure automatic optional chain completions Oct 18, 2019
@DanielRosenwasser
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 18, 2019

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 3d7451c. You can monitor the build here. It should now contribute to this PR's status checks.

const insertQuestionDot = origin && originIsNullableMember(origin);
if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) {
Copy link
Member

Choose a reason for hiding this comment

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

This condition should be in addSymbolOriginInfo where we add symbols to the origin map in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

I mean in addPropertySymbol

Copy link
Member

Choose a reason for hiding this comment

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

Oops, I guess I should clarify that I signed off that this change seems sensible for VS and not that the implementation looks correct.

@jessetrinity
Copy link
Contributor

My reading is that VS doesn't have to do anything unless it wants to add a checkbox to let users disable ?. completions. Is that right?

That's correct!

If something can be turned off, someone will want to do it. We'll take it :)

@@ -1119,6 +1120,9 @@ namespace ts.Completions {
insertQuestionDot = isRightOfDot && !isRightOfQuestionDot;
type = type.getNonNullableType();
}
if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this mistake? You don't want to return here.. Instead you want to add this check in addPropertySymbol where insertQuestionDot is checked

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't realize it was a closure function and other checks were happening in there. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, should be fixed now

@DanielRosenwasser DanielRosenwasser merged commit b845800 into master Oct 19, 2019
@DanielRosenwasser DanielRosenwasser deleted the includeAutomaticOptionalChainCompletions branch October 19, 2019 00:36
mjbvz added a commit to microsoft/vscode that referenced this pull request Oct 19, 2019
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.

Provide option to disable ?. completions
7 participants