-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Add option to configure automatic optional chain completions #34552
Conversation
b871ef4
to
4eca13e
Compare
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. |
Oh, uh, I know the issue. |
There was a problem hiding this 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?
src/services/completions.ts
Outdated
const insertQuestionDot = origin && originIsNullableMember(origin); | ||
if (insertQuestionDot && preferences === false) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 }
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
eb2c4d2
to
3d7451c
Compare
That's correct! |
@typescript-bot pack this |
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. |
src/services/completions.ts
Outdated
const insertQuestionDot = origin && originIsNullableMember(origin); | ||
if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean in addPropertySymbol
There was a problem hiding this comment.
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.
If something can be turned off, someone will want to do it. We'll take it :) |
src/services/completions.ts
Outdated
@@ -1119,6 +1120,9 @@ namespace ts.Completions { | |||
insertQuestionDot = isRightOfDot && !isRightOfQuestionDot; | |||
type = type.getNonNullableType(); | |||
} | |||
if (insertQuestionDot && preferences.includeAutomaticOptionalChainCompletions === false) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
Fixes #34542