Community
Participate
Working Groups
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 } }
To be investigated for 3.4
On the plan for M6, providing we can narrow the requirement.
Usecase is for deciding insertion of relevant templates.
A possible simplification would be for the context to tell only if at the beginning of a new line.
Maybe we have this information already when reporting only relevant keyword completions.
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 ?
Looks go to me. Maybe the API could be called getTokenLocation this fits nicely to the existing API getTokenKind
+1 Looks good.
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() {...} ... }
Released for 3.4M6. Tests added CompletionContextTests#test0129() -> test0142() CompletionContextTests_1_5#test0026() -> test0027()
Verified for 3.4M6 using I20080325-0100