eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

[WIP] Add contribution points for completion customization

Open jdneo opened this issue 2 years ago • 6 comments

This PR adds a set of contribution points which allows JDT.LS plugins(for example: intellicode) participate into the completion processing - mostly the ranking stuff.

With this PR, intellicode will not need to redirect the completion requests anymore, instead it can have the chance to use its own ranking algorithm during completion processing.

Signed-off-by: sheche [email protected]

jdneo avatar Jun 01 '22 06:06 jdneo

@Eskibear

jdneo avatar Jun 01 '22 06:06 jdneo

This could be abused to some extent if multiple plugins decide to take control. I would have liked to see some kind of extension point contribution where plugins can contribute their relevance score (or sorter), and ultimately let JDT-LS decide. A score is a bit nicer than just a sorter, because with a score the result can be combined.

I'll have a closer look at this.

rgrunber avatar Jun 02 '22 14:06 rgrunber

For better designing the API, let me briefly introduce how IntelliCode (probably the first consumer of this contribution point) ranks the items.

To make smarter ranking, it needs to know context information of the triggerred postion (including AST, bindings etc.). Besides, extra info is appened (using item.command.args) to items for diagnosic use, (e.g. elapsed time of the completion, ranking of each item...) That's why it interferes in an early stage, ranking the CompletionProposals before converting them to CompletionItem.

For clearer and easier implementation, IntelliCode has below requirements:

  • the ranking provider should provide enough context information as parameters.
  • there should be an approach to report diagnotic information (esp. completion performance that we want to monitor and improve). (currently it's using CompletionItem.command which will be executed when an item is selected)

Eskibear avatar Jun 06 '22 08:06 Eskibear

@Eskibear Thanks for sharing the context. I'll propose a more general one later.

jdneo avatar Jun 06 '22 11:06 jdneo

@rgrunber @Eskibear I have some new thoughts of the proposal:

Basically, I'd like to simplify the contribution point to only two methods:

interface CompletionRankingProvider {
    void rank(List<CompletionProposal> proposals, CompletionContext context, ICompilationUnit unit);
    void onDidCompletionItemSelect(Map<String, Object> completionResult);
}

About the rank(...) method

This method is used to let all the ranking providers to rank the proposals by adding or subtracting the relevance filed of the proposals.

About the onDidCompletionItemSelect(...) method

This method is used as a callback when a completion item is selected:

  1. JDT.LS will set a command to the completion items. The command will be triggered when the completion item is selected. And it is a command registered by Java extension itself, which will send the information of the selected item back to JDT.LS. (A benefit of doing this is that we can leverage the information to do something, for example, fix https://github.com/redhat-developer/vscode-java/issues/2441#issuecomment-1118354791)
  2. When JDT.LS receives the information, it will invoke the providers' onDidCompletionItemSelect(...) and passing the necessary information into it. Providers can do some post process here.

Using map here as the argument can allow as adding more entries in the future (if new request comes), but without changing the method signature. At the current stage, following things can be contained:

  1. The selected completion item.
  2. The elapsed time of resolving all the completion items.

jdneo avatar Jun 08 '22 09:06 jdneo

@rgrunber @Eskibear

I update the proposal. Please take a look when you have time. 😃

No need to include it in next release. But we can do some implementation verification at the IntelliCode side if no big issues are found in the proposal.

jdneo avatar Jun 27 '22 07:06 jdneo

@testforstephen This is the PR to open a contribution point for completion ranking.

jdneo avatar Oct 24 '22 05:10 jdneo

@Eskibear @testforstephen I've updated the PR per our discussion about the APIs

jdneo avatar Nov 15 '22 05:11 jdneo

@rgrunber Feel free to take a look. I think the latest change should address the comment about plugins can contribute their relevance score

jdneo avatar Nov 16 '22 08:11 jdneo

Tested https://github.com/eclipse/eclipse.jdt.ls/pull/2110/commits/b397c2c772c7563725918063b45fc61272ad2029 , migrating intellicode-java with the new API. so far so good.

Eskibear avatar Nov 16 '22 12:11 Eskibear

The last change I would like to make is to rename ICompletionRankingService to ICompletionContributionService, so that in the future we can allow contributors register other kinds of providers, e.g. ICompletionItemProvider to provide completion items (like jbang).

@rgrunber @fbricon @snjeza Feel free to leave comments if you have any. If everything looks good, I will start to add test cases.

jdneo avatar Nov 17 '22 05:11 jdneo