Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 41750

Summary: [templates] Code assist not narrowing on templates
Product: [Eclipse Project] JDT Reporter: John Arthorne <john.arthorne>
Component: TextAssignee: Tom Hofmann <eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Darin_Swanson, jpshack
Version: 3.0   
Target Milestone: 3.1 M2   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description John Arthorne CLA 2003-08-20 14:41:50 EDT
Build: I20030820

1) Start with:

class A {
   public void foo() {
      sys
   }
}

2) With the cursor after "sys", invoke code assist.  Note that the templates
"sysout", "syserr", etc are in the list.

3) Now type the letter "o".  The list disappears, although "sysout" is still a
valid match.  Expect: it will fill in "sysout" since it's the only valid match

4) Delete the letter "o" and invoke code assist again.

5) Type the letter "t".  The list narrows to exclude "sysout".

6) With code-assist still up, hit backspace.  Now you have "sys" again, but it
no longer recommends "sysout" as a possible completion.
Comment 1 Olivier Thomann CLA 2003-08-20 14:52:33 EDT
Please investigate.
I checked and the same bug is in integration build 0813.
Comment 2 David Audel CLA 2004-01-22 10:08:36 EST
Bug still occurs in 20040120

Template completion are managed by JDT/UI
Move to JDT/UI
Comment 3 Dani Megert CLA 2004-01-27 04:01:52 EST
The closer only looks at the code completions and ignores templates.
Comment 4 Tom Hofmann CLA 2004-04-08 03:17:52 EDT
*** Bug 55357 has been marked as a duplicate of this bug. ***
Comment 5 Tom Hofmann CLA 2004-04-08 03:44:08 EDT
The problem is that the display string of a template proposals does not
necessarily match the start of the text that would be inserted by applying the
template.

I believe however we could take the template name (the first part of the display
string, before the dash) and match it with the current document content to see
whether the template proposal is still valid.
Comment 6 Tom Hofmann CLA 2004-04-08 06:47:26 EDT
Added some code to TemplateProposal to allow validation. However, it relies on
the context to report the correct offsets for the replacement region, which
DocumentTemplateContext does not currently do. It would need to either use a
position based approach tracking the content being replaced by applying the
template, or use a parsing approach (see JavaContext) to figure out the relevant
content.

Of course, this is something anyone can do in their respective contexts... 

Leaving this open since we should eventually integrate this into
DocumentTemplateContext.
Comment 7 Tom Hofmann CLA 2004-04-26 05:40:58 EDT
changed the validation code again:

now, validate and apply take into account the current offset. This will fix the
most annoying problems with validation.

Templates will still not support overwriting mode like java templates.
Comment 8 Tom Hofmann CLA 2004-04-29 05:06:16 EDT
reducing priority since most of this is fixed.
Comment 9 Tom Hofmann CLA 2004-08-19 11:06:41 EDT
Added a position based constructor to DocumentTemplateContext. The caller is
responsible for (un-)registering the Position with the document, as the context
itself does not have the lifecycle for this.

fixed > 20040819