Bug 486899 - [templates] Using a variable name for word_selection or line_selection makes the template not being proposed anymore
Summary: [templates] Using a variable name for word_selection or line_selection makes...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 4.6 M6   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on:
Blocks:
 
Reported: 2016-01-30 19:04 EST by Lars Vogel CLA
Modified: 2016-02-08 08:13 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2016-01-30 19:04:51 EST
If I use a variable for word_selection in a template this template "vanishes" if I select a text in the editor.

For example:

${button}.setText(${w:word_selection});

Or in a full template (modified Button template):
---------

${buttonType:newType(org.eclipse.swt.widgets.Button)} ${button:newName(org.eclipse.swt.widgets.Button)}= new ${buttonType}(${parent:var(org.eclipse.swt.widgets.Composite)}, ${style:link(SWT.PUSH, SWT.TOGGLE, SWT.RADIO, SWT.CHECK, SWT.FLAT)});
${button}.setLayoutData(new ${type:newType(org.eclipse.swt.layout.GridData)}(SWT.${horizontal:link(BEGINNING, CENTER, END, FILL)}, SWT.${vertical:link(CENTER, TOP, BOTTOM, FILL)}, ${hex:link(false, true)}, ${vex:link(false, true)}));
${button}.setText(${w:word_selection});
${button}.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				${listener:link('')}
			}
		});
${imp:import(org.eclipse.swt.SWT, org.eclipse.swt.events.SelectionAdapter, org.eclipse.swt.events.SelectionEvent)}${cursor}

----------
Comment 1 Lars Vogel CLA 2016-02-03 09:06:57 EST
Noopur, maybe you can advice here, where the error could be? You worked recently on the code completion code for subwords.
Comment 2 Noopur Gupta CLA 2016-02-03 15:29:58 EST
This template gets filtered here: TemplateEngine#complete, line 144.

I'll take a look.

FYI: To debug such cases, you can add a breakpoint in org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(int offset) and check where a proposal is added or filtered.
Comment 3 Dani Megert CLA 2016-02-04 08:23:22 EST
(In reply to Noopur Gupta from comment #2)
> This template gets filtered here: TemplateEngine#complete, line 144.
> 
> I'll take a look.

Noopur is on vacation now.


Same issue for ${line_selection}.
Comment 4 Lars Vogel CLA 2016-02-05 08:35:51 EST
(In reply to Noopur Gupta from comment #2)
> This template gets filtered here: TemplateEngine#complete, line 144.

Thanks Noopur, the template gets filtered indeed in line 144 via this statement:

(!multipleLinesSelected && template.getPattern().indexOf($_WORD_SELECTION) != -1 || (multipleLinesSelected && template.getPattern().indexOf($_LINE_SELECTION) != -1)))

We should switch to evaluate a pattern. I prepare a patch.
Comment 5 Eclipse Genie CLA 2016-02-05 08:38:02 EST
New Gerrit change created: https://git.eclipse.org/r/66014