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

Deprecate CommandNames in favor of protocol.CommandTypes, direct import for better bundler output #52208

Merged
merged 3 commits into from
Jan 20, 2023

Conversation

jakebailey
Copy link
Member

In helping make a test for #50161 and trying to statically type the request handlers for #49929, I noticed that CommandNames is any and turns out to not have any completions, checking, etc, even though it is written as type 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 to CommandTypes, 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's GetOutliningSpans and GetOutliningSpansFull. There was also a unit test with a baseline that used Geterr instead of GeterrForProject.

Partially for #51443.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 12, 2023
command: ts.server.CommandNames.Geterr,
command: ts.server.protocol.CommandTypes.GeterrForProject,
Copy link
Member Author

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,
Copy link
Member Author

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.

Comment on lines +262 to +263
ts.server.protocol.CommandTypes.GetOutliningSpans,
ts.server.protocol.CommandTypes.GetOutliningSpansFull,
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

See: #52319

Comment on lines +307 to 310
/** @deprecated use ts.server.protocol.CommandTypes */
export type CommandNames = protocol.CommandTypes;
/** @deprecated use ts.server.protocol.CommandTypes */
export const CommandNames = (protocol as any).CommandTypes;
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a 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

@jakebailey jakebailey merged commit ddac387 into microsoft:main Jan 20, 2023
@jakebailey jakebailey deleted the deprecate-command-names branch January 20, 2023 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants