Bug 202467 - [assist] provide info what is completed
Summary: [assist] provide info what is completed
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.4 M6   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 202628
  Show dependency tree
 
Reported: 2007-09-06 10:41 EDT by Martin Aeschlimann CLA
Modified: 2008-03-25 08:56 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix (125.85 KB, patch)
2008-02-25 11:07 EST, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2007-09-06 10:41:54 EDT
3.3

To proceed on bug 110181, we decided to split it in smaller, specific requests.

To be able to provide our own proposals (for example templates) at good locations, we need to know what element is currently completed:

Minimal requirement for us:
- Body declaration
- statement

we also need the source range of the token being completed

class A {

| // completing body declaration
pub| // completing body declaration
public static fo| // completing body declaration

public static void foo() {
| // completing statement
fo| // completing statement
a.x|//completing something else
}

}
Comment 1 Jerome Lanneluc CLA 2007-09-11 08:14:16 EDT
To be investigated for 3.4
Comment 2 Philipe Mulet CLA 2008-02-13 08:21:09 EST
On the plan for M6, providing we can narrow the requirement.
Comment 3 Philipe Mulet CLA 2008-02-13 08:25:22 EST
Usecase is for deciding insertion of relevant templates.
Comment 4 Philipe Mulet CLA 2008-02-13 08:28:59 EST
A possible simplification would be for the context to tell only if at the beginning of a new line.
Comment 5 Philipe Mulet CLA 2008-02-13 08:29:57 EST
Maybe we have this information already when reporting only relevant keyword completions.
Comment 6 David Audel CLA 2008-02-20 08:03:00 EST
I propose to add the following API

public class CompletionContext {
/**
 * Returns the type of the location of the completed token.
 * The returned value is a bit mask which may contains these values:
 * <ul>
 * <li>{@link #MEMBER_START} : if the completed token is the first token of a member declaration.</li>
 * <li>{@link #STATEMENT_START} : if the completed token is the first token of a statement.</li>
 * </ul>
 */
public int getLocationType()

/**
 * The completed token is the first token of a member declaration.<br>
 * e.g.
 * <pre>
 * public class X {
 *   Foo| // completion occurs at |
 * }
 * </pre>
 */
public static final int MEMBER_START = 1;
	
/**
 * The completed token is the first token of a statement.<br>
 * e.g.
 * <pre>
 * public class X {
 *   public void bar() {
 *     Foo| // completion occurs at |
 *   }
 * }
 * </pre>
 */
public static final int STATEMENT_START = 2;
}

These would solve the 'templates' case and we could add new constants in the future for some other locations.
For example if we want to describe that the completion occurs inside a members declaration we would need to add a constant like MEMBER_PART.

public class X {
  public class Foo| // completion occurs at |
}

Another example if we want to describe that completion occurs at the start of a method's statement we would add a constant like METHOD_STATEMENT_START.

I don't plan to add MEMBER_PART or METHOD_STATEMENT_START if they are not required. It is just to show how the API could be extended in the future.

Daniel, Martin - What do you think of this API ? Would it solve your usecases ?
Comment 7 Martin Aeschlimann CLA 2008-02-20 08:41:05 EST
Looks go to me.

Maybe the API could be called
  getTokenLocation

this fits nicely to the existing API
  getTokenKind
Comment 8 Dani Megert CLA 2008-02-21 03:44:15 EST
+1 Looks good.
Comment 9 David Audel CLA 2008-02-25 11:07:46 EST
Created attachment 90651 [details]
Proposed fix

I renamed the method getTokenLocation() and the constants TL_MEMBER_START and TL_STATEMENT_START.

Then the API is:

public class CompletionContext {
	...
	
	/**
	 * The completed token is the first token of a member declaration.<br>
	 * e.g.
	 * <pre>
	 * public class X {
	 *   Foo| // completion occurs at |
	 * }
	 * </pre>
	 * 
	 * @see #getTokenLocation()
	 * 
	 * @since 3.4
	 */
	public static final int TL_MEMBER_START = 1;
	
	/**
	 * The completed token is the first token of a statement.<br>
	 * e.g.
	 * <pre>
	 * public class X {
	 *   public void bar() {
	 *     Foo| // completion occurs at |
	 *   }
	 * }
	 * </pre>
	 * 
	 * @see #getTokenLocation()
	 * 
	 * @since 3.4
	 */
	public static final int TL_STATEMENT_START = 2;
	
	/**
	 * Returns the location of completion token being proposed.
	 * The returned location is a bit mask which can contain some values
	 * of the constants declared on this class whose name starts with <code>TL</code>,
	 * or possibly values unknown to the caller.
	 * 
	 * <p>
	 * The set of different location values is expected to change over time.
	 * It is strongly recommended that clients do <b>not</b> assume that
	 * the location contains only known value, and code defensively for 
	 * the possibility of unexpected future growth.
	 * </p>
	 * 
	 * @return the location
	 * 
	 * @since 3.4
	 */
	public int getTokenLocation() {...}
	
	...
}
Comment 10 David Audel CLA 2008-02-25 11:10:46 EST
Released for 3.4M6.

Tests added
   CompletionContextTests#test0129() -> test0142()
   CompletionContextTests_1_5#test0026() -> test0027()
Comment 11 Jerome Lanneluc CLA 2008-03-25 08:56:18 EDT
Verified for 3.4M6 using I20080325-0100