-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Deprecate CommandNames in favor of protocol.CommandTypes, direct import for better bundler output #52208
Deprecate CommandNames in favor of protocol.CommandTypes, direct import for better bundler output #52208
Conversation
command: ts.server.CommandNames.Geterr, | ||
command: ts.server.protocol.CommandTypes.GeterrForProject, |
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.
Here's one bug caught by this PR.
ts.server.CommandNames.ApplyChangedToOpenFiles, | ||
ts.server.CommandNames.EncodedSemanticClassificationsFull, | ||
ts.server.CommandNames.Cleanup, | ||
ts.server.CommandNames.OutliningSpans, |
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.
Here's another caught bug; this should be GetOutliningSpans
.
ts.server.protocol.CommandTypes.GetOutliningSpans, | ||
ts.server.protocol.CommandTypes.GetOutliningSpansFull, |
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.
These are the new fixed ones. But, it's weird to me that we encode this huge list rather than just iterating over the enum; seems trivial to do it that way instead and never have this drift or be wrong.
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.
Yeah, this "just works":
const allCommandNames: ts.server.protocol.CommandTypes[] = Object.values((ts.server.protocol as any).CommandTypes);
I'm curious if this would be a better idea in the long term.
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.
@sheetalkamat Since you're back, do you have any opinion one way or another here? I think the baselines are enough to indicate that something changed, so I think just using values
here is probably going to be better in the long term to not forget than the comments.
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.
Well, the above isn't needed for the beta; I think I'll merge this now and send a followup PR for discussion instead, that way the deprecation is seen.
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.
See: #52319
/** @deprecated use ts.server.protocol.CommandTypes */ | ||
export type CommandNames = protocol.CommandTypes; | ||
/** @deprecated use ts.server.protocol.CommandTypes */ | ||
export const CommandNames = (protocol as any).CommandTypes; |
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 wonder if these could have just been declared as import CommandNames = protocol.Commandtypes
in the first place. It probably would preserve the enum inlining issue you commented on, but at this point, I wouldn't worry about it.
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.
That's true, this could be export import CommandNames = protocol.CommandTypes
; I'll have to see if it bundles alright as that does help a bit.
But, I do think that if we're switching to direct imports, no reason not to use the real deal.
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.
Hah, so this is syntax I never bothered to implement in the dts bundler since I removed all instances during the conversion. Oops.
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.
Seems like you fixed the mismatches correctly given the surrounding code
In helping make a test for #50161 and trying to statically type the request handlers for #49929, I noticed that
CommandNames
isany
and turns out to not have any completions, checking, etc, even though it is written astype CommandNames = protocol.CommandTypes
.The way that it's forwarded also makes it suboptimal in the output bundle; in the output, uses are always an explicit access to a
CommandNames
object rather than inlined constants.This PR switches all uses of
CommandNames
toCommandTypes
, then does a selective direct import of the protocol module in order to improve esbuild's code gen (it has troubles looking past one level of reexports; evanw/esbuild#2636).In doing so, this exposed a couple of cases where the use of CommandNames was wrong! For example, it's not
OutliningSpans
, it'sGetOutliningSpans
andGetOutliningSpansFull
. There was also a unit test with a baseline that usedGeterr
instead ofGeterrForProject
.Partially for #51443.