The way I see it, once org.netbeans.modules.csl.api.CodeCompletionHandler.complete() starts running, there is now way for it to stop ahead of time if the task has been canceled.
A common example would be if the user triggers completion then gets bored waiting and presses Escape.
Without knowing when to stop, the handler will just run as long as it takes consuming CPU for nothing. And if another completion is triggered, we'll have multiple threads running the handlers.
It seems AsyncCompletionTask is cancelable and this is also provided in AsyncCompletionQuery but we don't provide this info via GsfCompletionProvider.CodeCompletionContextImpl (which implements CodeCompletionContext).
I can provide my patch for this, it's quite short.
The only thing to debate is if this makes sense and update the CodeCompletionContext API.
BTW, the suggested api is:
I'll try it. Strictly speaking (thanks to the original design), adding a method to CCContext is an incompatible API change, so I wonder how the API will look like.
My patch is on some older code and basically just a hack, so there isn't much to share.
But overall, I've just added:
public abstract boolean isTaskCanceled();
which defers to AsyncCompletionQuery.isTaskCancelled().
Not knowing if the task has been cancelled is a bug that wastes CPU and should allow client code to bail early if isTaskCanceled() starts returning 'true'.
So I would say this is an API change that should be done in some form.