eclipse.jdt.ls
eclipse.jdt.ls copied to clipboard
[WIP] Add contribution points for completion customization
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]
@Eskibear
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.
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 Thanks for sharing the context. I'll propose a more general one later.
@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:
- 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)
- 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:
- The selected completion item.
- The elapsed time of resolving all the completion items.
@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.
@testforstephen This is the PR to open a contribution point for completion ranking.
@Eskibear @testforstephen I've updated the PR per our discussion about the APIs
@rgrunber Feel free to take a look. I think the latest change should address the comment about plugins can contribute their relevance score
Tested https://github.com/eclipse/eclipse.jdt.ls/pull/2110/commits/b397c2c772c7563725918063b45fc61272ad2029 , migrating intellicode-java with the new API. so far so good.
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.