Bug 345213 - [content assist][preferences] Add enablement to Java completion proposal category extension point
Summary: [content assist][preferences] Add enablement to Java completion proposal cate...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.6.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Paul Fullbright CLA
QA Contact:
URL:
Whiteboard:
Keywords: api, helpwanted
Depends on:
Blocks: 349471
  Show dependency tree
 
Reported: 2011-05-09 18:03 EDT by Paul Fullbright CLA
Modified: 2012-08-29 17:18 EDT (History)
2 users (show)

See Also:


Attachments
proposed patch (9.00 KB, patch)
2011-06-13 10:59 EDT, Paul Fullbright CLA
daniel_megert: review-
Details | Diff
test plugin (6.76 KB, application/x-zip-compressed)
2011-12-28 10:25 EST, Paul Fullbright CLA
no flags Details
updated patch (13.11 KB, patch)
2011-12-28 10:33 EST, Paul Fullbright CLA
no flags Details | Diff
updated patch (15.33 KB, patch)
2012-01-03 16:24 EST, Paul Fullbright CLA
daniel_megert: iplog+
daniel_megert: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Fullbright CLA 2011-05-09 18:03:21 EDT
We have a java completion proposal computer, but it should only be used for projects of a specific type.  However, there is no way to eliminate our computer for projects that don't match this criteria.  If there were an enablement (optional) element on the extension point, we'd be able to prevent this completion proposal category from showing up on project where it makes no sense.

example:

    <extension
        point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
        id="jaxbCompletionProposals"
        name="%jaxbCompletionProposals">
		
        <proposalCategory icon="icons/full/etool16/jaxb_facet.gif"/>

        <enablement>
            <with variable="project">
                <test 
                    property="org.eclipse.wst.common.project.facet.core.projectFacet"
                    value="jpt.jaxb" forcePluginActivation="true"/>
            </with>
        </enablement>
		
    </extension>
Comment 1 Dani Megert CLA 2011-05-10 01:31:12 EDT
> If there were an enablement (optional) element on the extension point, we'd 
> be able to prevent
> this completion proposal category from showing up 
Showing up where exactly?
Comment 2 Paul Fullbright CLA 2011-05-10 10:33:32 EDT
Showing up as a category when hitting ctrl-space.  If it makes no sense to have jaxb proposals in a particular context, then the category itself should not show up.

i.e. "Press ctrl-space to see JAXB proposals"
Comment 3 Dani Megert CLA 2011-05-10 10:35:50 EDT
So, an option to hide categories with 0 proposals would also do the trick for you?
Comment 4 Paul Fullbright CLA 2011-05-10 12:15:27 EDT
Effectively, sure.

Do you mean a user option or an extension option?
Comment 5 Dani Megert CLA 2011-05-11 03:32:26 EDT
> Do you mean a user option or an extension option?
A user option. I think the user should decide whether he wants this or not. Imagine he knows the third category is 'Templates' and hits 'Space' two times to get there. If that becomes unreliable because the second category decides to be skipped if empty, then his workflow is doomed.
Comment 6 Paul Fullbright CLA 2011-05-11 10:11:48 EDT
Then no, this is not what I'm talking about at all.

Our completion proposals will only show up on certain projects.  On other projects they will *always* be empty, and the user will *always* get an empty category.

In fact for *most* projects, our empty proposals will show up.  And we actually have two of them (two different kinds of projects).  The simple fact that a user has to remember that he needs the fourth or fifth category itself is probably bad form.
Comment 7 Dani Megert CLA 2011-05-11 10:28:35 EDT
OK I see. I would accept a high quality patch that implements the solution described in comment 0.
Comment 8 Paul Fullbright CLA 2011-05-11 11:11:11 EDT
If you have any requests for enablement variables, please let me know.  I'll take a look at this after Indigo release.
Comment 9 Dani Megert CLA 2011-05-11 11:36:50 EDT
(In reply to comment #8)
> If you have any requests for enablement variables, please let me know. 
Nothing at the moment and I can't recall any requests in this area.

> I'll take a look at this after Indigo release.
Thanks!
Comment 10 Paul Fullbright CLA 2011-06-13 10:59:28 EDT
Created attachment 197893 [details]
proposed patch

Patch handles enablement for the following two scenarios:

- specific content assist category menu items
- invoking content assist within source code

Tested against our extensions (and existing java extensions):

	<extension
		point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
		id="jaxbCompletionProposals"
		name="%jaxbCompletionProposals">
		
		<proposalCategory icon="icons/full/etool16/jaxb_facet.gif">
			<enablement>
				<with variable="project">
					<adapt type="org.eclipse.core.resources.IProject">
						<test
							property="org.eclipse.wst.common.project.facet.core.projectFacet"
							value="jpt.jaxb"/>
					</adapt>
				</with>
			</enablement>
		</proposalCategory>
		
	</extension>


Comments are appreciated.  I was potentially overly defensive, not being that familiar with the code.

I was unsure how to handle ContentAssistProcessor, as it is a concrete internal class, but seems to never be instantiated, and I couldn't test implementations of that specifically.  I ended up treating it as though it were an abstract class.

API (extension point schema) was also updated.
Comment 11 Dani Megert CLA 2011-06-14 04:42:02 EDT
Paul, I will look at this probably in September. We are currently 100% busy with Java 7.
Comment 12 Paul Fullbright CLA 2011-06-14 10:45:25 EDT
No worries, just wanted to give plenty of time for feedback back and forth.
Comment 13 Dani Megert CLA 2011-12-14 09:55:56 EST
Hi Paul,

I finally reviewed your patch. Looks good in general. Some minor changes need to be made:
- the example in the extension point definition should be adjusted
- please adjust copyright date in the extension point definition
- new additional checks should only be made if all other checks return 'true'
- CompletionProposalCategory.matches(IJavaProject) should only compute the 
  expression once and cache it
- the signature change of #computeEnablement(ITextEditor) is not needed
- use EditorUtility.getJavaProject(editor.getEditorInput()) to get the project
- I would probably also add the check to
  SpecificContentAssistExecutor.invokeContentAssist(ITextEditor, String) since
  someone might directly use it in the future (instead of going via 
  SpecificContentAssistAction).
- all new methods need Javadoc and a @since 3.8
- add your credentials to the Java files, e.g.:
  Dani Megert <dani@eclipse.org> - this is a bug - https://bugs.eclipse.org...
- please add test cases or add an example plug-in to verify that it works
Comment 14 Paul Fullbright CLA 2011-12-22 09:26:59 EST
(In reply to comment #13)
> Hi Paul,
> 
> I finally reviewed your patch. Looks good in general. Some minor changes need
> to be made:
> - the example in the extension point definition should be adjusted

How?  The enablement tag is optional and the existing example (which seems to be a real example) doesn't make use of it.
What would you suggest?

> - please adjust copyright date in the extension point definition

done

> - new additional checks should only be made if all other checks return 'true'

done

> - CompletionProposalCategory.matches(IJavaProject) should only compute the 
>   expression once and cache it

done

> - the signature change of #computeEnablement(ITextEditor) is not needed
> - use EditorUtility.getJavaProject(editor.getEditorInput()) to get the project

done.  helpful utility, that.

> - I would probably also add the check to
>   SpecificContentAssistExecutor.invokeContentAssist(ITextEditor, String) since
>   someone might directly use it in the future (instead of going via 
>   SpecificContentAssistAction).

would I just check enablement for that category and if not enabled, then *not* set it to be included?

> - all new methods need Javadoc and a @since 3.8

done

> - add your credentials to the Java files, e.g.:
>   Dani Megert <dani@eclipse.org> - this is a bug - https://bugs.eclipse.org...

done

> - please add test cases or add an example plug-in to verify that it works

working on example plug-in  ... 


Can you provide answers to the two above questions?  Everything else is taken care of or in progress.  Thanks.
Comment 15 Paul Fullbright CLA 2011-12-28 10:25:40 EST
Created attachment 208826 [details]
test plugin

Test plugin.

If the project is named "Enabled" content assist category is enabled (for text regions).
If the project is named otherwise, content assist category is not enabled.
Comment 16 Paul Fullbright CLA 2011-12-28 10:33:14 EST
Created attachment 208827 [details]
updated patch

Made all above changes except:

- Updated example.  The current example doesn't make use of enablement, enablement is optional, and enablement is fairly well understood (or at least documented all over the place).  I didn't think it was appropriate to add enablement to the current example.

- Specific content assist.  I feel that if a user is *specifically* invoking content assist for a given category, that the content assist - even if there are no proposals due to not being enabled - should proceed normally.  There just won't be any proposals returned.  The whole point of enablement is to filter categories from the default invocation, not for any need to specifically prevent a category from being invoked.
Comment 17 Dani Megert CLA 2012-01-03 11:51:04 EST
> - Updated example.  The current example doesn't make use of enablement,
> enablement is optional, and enablement is fairly well understood (or at least
> documented all over the place).  I didn't think it was appropriate to add
> enablement to the current example.

Fair enough.


> - Specific content assist.  I feel that if a user is *specifically* invoking
> content assist for a given category, that the content assist - even if there
> are no proposals due to not being enabled - should proceed normally.  There
> just won't be any proposals returned.

It's a bit more tricky: a contributor might enable the category e.g. only for projects of a certain type/nature and then write code that relies on this, e.g. by doing a cast inside the proposal computer.
Comment 18 Paul Fullbright CLA 2012-01-03 16:24:49 EST
Created attachment 208966 [details]
updated patch

OK, I updated the specific content assist to disable if the enablement test fails.
Comment 19 Dani Megert CLA 2012-01-09 07:20:37 EST
Thanks for the updated patch Paul.

I've slightly modified your credential string and updated the copyright date to 2012.

Fixed in master: 9538bb8c56138fb59335cd939a339e0cc7354a87
Comment 20 Paul Fullbright CLA 2012-01-09 10:40:13 EST
Thanks.

What do I need to do to get this taken up by the 4.x stream?
Comment 21 Dani Megert CLA 2012-01-09 10:44:57 EST
(In reply to comment #20)
> Thanks.
> 
> What do I need to do to get this taken up by the 4.x stream?

Nothing. 4.x automatically consumes JDT from the 3.x builds.