Skip to content

Make sortText on completions be enum-typed #36043

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

Closed

Conversation

uniqueiniquity
Copy link
Contributor

We've had a couple issues in the past where the value of a member of the SortText enum has changed when adding a new member. This has caused bugs in editors that use TSServer.

Here, we ensure that the sortText property of completion entries is specifically typed with the SortText enum, so that it's properly represented in the protocol.

@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary

declare namespace ts.Completions {
export enum SortText {
LocationPriority = "0",
OptionalMember = "1",
Copy link
Member

Choose a reason for hiding this comment

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

Why are some "member" and others "members"?

@weswigham
Copy link
Member

So if VS relies on specific string-numbers for the sort text, does that mean that VS/vscode couldn't handle LS plugins that provide arbitrary alphanumeric content for the sortText? I always assumed the content was an arbitrary relative "string to sort by".

@weswigham
Copy link
Member

weswigham commented Jan 7, 2020

For reference: The angular language service plugin definitely passes full on arbitrary strings. The sort they map into sortText is the full alphanumeric name of a thing. I imagine that's currently fine, since they don't mix their template completions in with normal completion results?

@mjbvz
Copy link
Contributor

mjbvz commented Jan 7, 2020

@weswigham VS code uses string sorting logic: https://github.com/microsoft/vscode/blob/9f474febfee5330f7a9a7456862ef73d0b6f0bf5/src/vs/editor/contrib/suggest/suggest.ts#L229

So you could use 'a', 'b', 'c', ... instead of '0', '1', ...

@weswigham
Copy link
Member

weswigham commented Jan 7, 2020

Right - all that matters is that whoever is sending the sortText is internally consistent in that case. @uniqueiniquity how is it used elsewhere? And why is it not used as an opaque sortable string in those cases? As I've pointed out - the angular LS plugin does make use of it as not-internal-numbering-scheme, so this protocol change would definitely break it.

@sheetalkamat
Copy link
Member

agree with @weswigham here.. this needs to be string so that any string value can be passed in.. Its enum in services layer internally so that it can easily be labeled instead of making them "1" or "2"

@uniqueiniquity
Copy link
Contributor Author

@weswigham @sheetalkamat we don't generally care about the text - we specifically care about the JavaScriptIdentifiers entries, as since they're basically guesses, we want to handle those a little differently than the others. In all other cases, interpreting it as "a string to sort by" is fine.

My goal here is to either prevent these values from being changed or, if that's not feasible, to at least have a way to get notified when they get changed. I'd also be open to an additional property saying "this entry is a js-only guess" if that's preferred.

@sheetalkamat
Copy link
Member

I think making a property for js-only guess is better than having enum for the sorting text

@uniqueiniquity
Copy link
Contributor Author

Superseded by #36063.

@uniqueiniquity uniqueiniquity deleted the wellTypeSortText branch January 7, 2020 22:45
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.

6 participants