Skip to content

Get rid of the duplicated COMPLETION_EXECUTION_TIME in completion items #2635

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

Merged
merged 2 commits into from
May 6, 2023

Conversation

jdneo
Copy link
Contributor

@jdneo jdneo commented May 4, 2023

  • Now, the server will cache the COMPLETION_EXECUTION_TIME and only set it into the data field when the item is selected in the callback function.

fix #2621

Data size change

Triggering completion via 'S' in Spring Petclinic project, the response (textDocument/completion) data size can be reduced from 2.67MB to 2.54MB. (Directly copy the trace to a text file)

- Now, the server will cache the COMPLETION_EXECUTION_TIME and only set
  it into the data field when the item is selected in the callback function.

Signed-off-by: sheche <[email protected]>
@jdneo jdneo force-pushed the cs/issue-2621 branch from 31c9f3b to 76f5dae Compare May 4, 2023 04:10
@jdneo

This comment was marked as off-topic.

Copy link
Contributor

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

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

I can confirm this PR eliminates the the COMPLETION_EXECUTION_TIME from each completion item. It looks like this makes it so that if a client wants access to the completion execution time, they must contribute an ICompletionRankingProvider (presumably in a JDT-LS bundle contribution) to get access to it ?

Initially I was thinking, you would probably just return the execution time in the data field of the response to resolveCompletionItem. But I guess the wording of the data field implies it should not exist after resolve ?

     /**
	 * A data entry field that is preserved on a completion item between
	 * a completion and a completion resolve request.
	 */
	data?: [LSPAny](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#lspAny);

If that's the reason you went with reporting the values through java.completion.onDidSelect and only when a ranking provider is contributed, then feel free to merge. I just thought maybe there's a nicer way that uses less non-spec stuff.

@jdneo
Copy link
Contributor Author

jdneo commented May 5, 2023

Ah yes, those concerns do make sense.

But I guess the wording of the data field implies it should not exist after resolve?

data does not exist in the resolveSupport capability and we could not update it during resolve according to the spec. But I believe that adding a new data entry won't have any impact on the client behavior in terms of the intellisense experience. (It's not critical things like textEdit or sortText). So maybe add it during resolve can be a good idea?

this makes it so that if a client wants access to the completion execution time, they must contribute an ICompletionRankingProvider (presumably in a JDT-LS bundle contribution) to get access to it?

Yes, that's the original intention to introduce COMPLETION_EXECUTION_TIME, but I directly put it into data field because that's how IntelliCode did previously.

I just thought maybe there's a nicer way that uses less non-spec stuff.

I'm not worry about it, because java.completion.onDidSelect command is an API of the LS itself, so the completion related restrictions should not be applied to it.

The discussion makes me thinking that: Is putting the execution time into the completion item's data field a good practice? Maybe we should make it part of the ICompletionRankingProvider API? Something like there will be an additional map of data feed into void onDidCompletionItemSelect(CompletionItem item)

@testforstephen
Copy link
Contributor

testforstephen commented May 5, 2023

The ranking provider may add many data properties to the completion items. You can store the data from ranking providers in the internal CompletionResponse cache instead of merging them to the lsp4j completion items. This will reduce duplication in the lsp4j response result.

https://github.com/eclipse/eclipse.jdt.ls/blob/b9fda0f3776ec0da832cdc3fbc7c63fb91ee06db/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java#L250-L270

@jdneo
Copy link
Contributor Author

jdneo commented May 5, 2023

You can store the data from ranking providers in the internal CompletionResponse cache instead of merging them to the lsp4j completion items.

Thanks for the input. Yes, IntelliCode contributes some other data entries which are now added into the CompletionItem data. I agree that we should avoid doing this and only append those data when onDidSelect happens. Because those data are only used by the registered ranking providers. Both server and client does not care about it actually. I'll address this problem in another separate PR.

Signed-off-by: Sheng Chen <[email protected]>
@jdneo jdneo merged commit c98fd2c into eclipse-jdtls:master May 6, 2023
@jdneo jdneo deleted the cs/issue-2621 branch May 6, 2023 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only send COMPLETION_EXECUTION_TIME once per completion request
4 participants