Bug 508821 - [Content assist] More flexible API in IContentAssistProcessor to decide whether to auto-activate or not
Summary: [Content assist] More flexible API in IContentAssistProcessor to decide wheth...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.19 M3   Edit
Assignee: Christoph Laeubrich CLA
QA Contact:
URL:
Whiteboard:
Keywords: api, noteworthy
Depends on:
Blocks: 101420
  Show dependency tree
 
Reported: 2016-12-07 08:07 EST by Mickael Istria CLA
Modified: 2021-03-02 05:06 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2016-12-07 08:07:47 EST
IContentAssistProcessor takes viewer as input to get proposals, but doesn't take it as input to get trigger chars. However, some processors require the viewer, or the document, to decide what are the proper activation characters to use.
Comment 1 Mickael Istria CLA 2016-12-07 08:09:42 EST
Can we add new methods to IContentAssistProcessor with default in the interface? Or can we create an IContentAssistProcessorExtension with those methods?
Comment 2 Nitin Dahyabhai CLA 2016-12-07 10:54:29 EST
Do you instead mean characters that apply the current proposal? The trigger characters are more interesting to the content assistant and UI part of the story than the potentially headless processors.
Comment 3 Mickael Istria CLA 2016-12-07 10:58:19 EST
I'm talking about IContentAssistProcessor#getCompletionProposalAutoActivationCharacters . In the meantime, I'm using a workaround to retrieve the document from ((ITextEditor)PlatformUI.getWorkbench().getActive....getActiveEditor()).getDocument()"
Comment 4 Mickael Istria CLA 2018-11-23 03:55:57 EST
Actually, it seems to me that triggerChars don't scale: if someone wants to include all chars (how many are there these days, thousands?) except a few ones, then building a list is going to take a lot of RAM for dummy data.
Instead of a new API to improve triggerChars computation, we may need a new API that checks directly a keyEvent and get access to the viewer and document to decide whether to auto-enable for this event.
Comment 5 Christoph Laeubrich CLA 2021-01-15 07:52:59 EST
Any progress on this? I would need this too as the proposals are dependent on the language of the document and in english there are other chars as in french or german (as the keywords are different).

I could try to provide a patch if there is a consensus on how the API should be designed.

We could provide an extension interface with the following properties:

1) getCompletionProposalAutoActivationCharacters could be default implemented returnin null

2) add a new default method (that's what the content processor does anyways)

> boolean isAutoActivation(KeyEvent event, ITextViewer viewer, int offset)
>       char[] triggers= processor.getCompletionProposalAutoActivationCharacters();
>	if (triggers != null && new String(triggers).indexOf(c) >= 0) {
>		return true;
>	}
>       return false

this way new users can choose to implement any of the above methods, old clients are not affected.
Comment 6 Mickael Istria CLA 2021-01-15 08:04:33 EST
@Christoph: That seems good to me, let's try and see. The only concern is just that the getCompletionProposalAutoActivationCharacters would still remain when it's not actually used, so it's a bit of garbage in the API. Maybe a new IContentAssistProcessor2 interface would be cleaner?
Comment 7 Christoph Laeubrich CLA 2021-01-15 08:29:46 EST
I could add a new interface but clients would still need to implement the old one because of ExtensionPoints use that interface also and we otherwise need to add the other methods also.
Comment 8 Mickael Istria CLA 2021-01-15 08:31:08 EST
(In reply to Christoph Laeubrich from comment #7)
> I could add a new interface but clients would still need to implement the
> old one because of ExtensionPoints use that interface also and we otherwise
> need to add the other methods also.

Which extension points actually consume this API? I'm aware of Generic Editor, but that's something we can change easily.
Comment 9 Christoph Laeubrich CLA 2021-01-15 08:43:30 EST
The extension point is org.eclipse.ui.genericeditor.contentAssistProcessors but if we do not extend the interface we also need to change ContentAssistant and IContentAssistant and probably other places.
Comment 10 Mickael Istria CLA 2021-01-15 10:55:49 EST
(In reply to Christoph Laeubrich from comment #9)
> The extension point is org.eclipse.ui.genericeditor.contentAssistProcessors
> but if we do not extend the interface we also need to change
> ContentAssistant and IContentAssistant and probably other places.

That's right. As we're increasing Platform development speed with more and more contributors, we're starting to get hurt very often by this kind of pattern; and so far, no perfect solution has emerged.
I suggest you get started with your proposal and we may discuss potential improvement from this 1st iteration.
Comment 11 Christoph Laeubrich CLA 2021-01-15 12:56:47 EST
I found one issue with passing the key.event, it seems 
org.eclipse.jface.text.contentassist.CompletionProposalPopup
does not has an event object but uses a char from the current document to check for autoactivation I see two opportunities:

1) generate an synthetic event -> but filled data will be incomplete because it is not a real event
2) pass a single char instead of the event

I would tend to option 2 atm even though it is not that flexible it is a bit more cleaner in respect to the ITextViewer/IDocument API as those are not seem to use any SWT specific parts.

A third option would be to use some kind of DocumentEvent (or even ActivationTrigger event) that optionally can carry the original event if present but is might be a bit hard to code against code that sometimes contains an event  and sometimes not...
Comment 12 Mickael Istria CLA 2021-01-15 12:59:41 EST
(In reply to Christoph Laeubrich from comment #11)
> 1) generate an synthetic event -> but filled data will be incomplete because
> it is not a real event
> 2) pass a single char instead of the event
> 
> I would tend to option 2 atm even though it is not that flexible it is a bit
> more cleaner in respect to the ITextViewer/IDocument API as those are not
> seem to use any SWT specific parts.

Ok for approach 2.
Comment 13 Eclipse Genie CLA 2021-01-15 13:15:29 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/174905
Comment 14 Mickael Istria CLA 2021-01-15 16:29:53 EST
I'm curious, what's the use-case for this new API that wouldn't be covered by a proper solution to bug 101420 ?
Comment 15 Christoph Laeubrich CLA 2021-01-16 02:36:28 EST
(In reply to Mickael Istria from comment #14)
> I'm curious, what's the use-case for this new API that wouldn't be covered
> by a proper solution to bug 101420 ?

Well you opened the initial bug on this 4 years ago :-) The referenced Bug is > 15 years old and I don't see any progress there... maybe because its to vague or eclipse is designed to be too generic/extensible to find a solution that suits all to get to a conclusion.

I also would consider this as new API, its more incomplete. All other methods allow access to the document so it seems right to have it here also.

My particular use case is that the set of characters that trigger auto activation is not known as the language I like to supply autocomplete for is not static (the content of the document determines how the keywords are named) and I don't know them in advance. So I'D like to have the opportunity to check the document language, fetch the keywords and then only return those chars that could trigger an auto completion.
Comment 16 Mickael Istria CLA 2021-01-16 07:28:26 EST
(In reply to Christoph Laeubrich from comment #15)
> Well you opened the initial bug on this 4 years ago :-)

Yet I didn't work on it because it wasn't high priority to me. As we've made progress with async completion and so on, the initial use-case I had for this is now better handled by bug 101420

> The referenced Bug
> is > 15 years old and I don't see any progress there... maybe because its to
> vague or eclipse is designed to be too generic/extensible to find a solution
> that suits all to get to a conclusion.

I don't think it's true that there hasn't been any progress. See the relation chain (blocks/depeends/duplicate/see also), there are numerous related issue that were tackled towards that goal.

> My particular use case is that the set of characters that trigger auto
> activation is not known as the language I like to supply autocomplete for is
> not static (the content of the document determines how the keywords are
> named) and I don't know them in advance. So I'D like to have the opportunity
> to check the document language, fetch the keywords and then only return
> those chars that could trigger an auto completion.

OK, that's a very valid case, thanks!
Comment 18 Mickael Istria CLA 2021-01-17 14:55:57 EST
Thanks Christoph. Please add a note about it to https://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/tree/4.19/platform.html
Comment 19 Eclipse Genie CLA 2021-01-18 01:41:35 EST
New Gerrit change created: https://git.eclipse.org/r/c/www.eclipse.org/eclipse/news/+/174959
Comment 20 Eclipse Genie CLA 2021-01-18 01:47:50 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/174960
Comment 22 Mickael Istria CLA 2021-01-19 14:32:12 EST
Thanks Christoph!
(PS: please test the N&N .html files in a browser, there were a bunch of typos that are pretty easy to view in a browser)
Comment 23 Christoph Laeubrich CLA 2021-01-20 00:57:22 EST
Thanks for helping out here Mickael!