Skip to content

Commit 62e6bf7

Browse files
committed
completion/ui: IElementLabelProviderExtension which accepts CompletionProposal
1 parent a49b32e commit 62e6bf7

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

plugins/org.eclipse.dltk.javascript.ui/src/org/eclipse/dltk/javascript/internal/ui/text/completion/JavaScriptCompletionProposalLabelProvider.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class JavaScriptCompletionProposalLabelProvider extends
4343
public String createTypeProposalLabel(CompletionProposal typeProposal) {
4444
if (typeProposal.getExtraInfo() instanceof Type) {
4545
final Type type = (Type) typeProposal.getExtraInfo();
46-
final String label = getElementLabel(type);
46+
final String label = getElementLabel(type, typeProposal);
4747
if (label != null) {
4848
return label;
4949
}
@@ -66,8 +66,10 @@ public String createTypeProposalLabel(CompletionProposal typeProposal) {
6666
return super.createTypeProposalLabel(typeProposal);
6767
}
6868

69-
private static String getElementLabel(Element element) {
70-
return ElementLabelProviderRegistry.getLabel(element, Mode.PROPOSAL);
69+
private static String getElementLabel(Element element,
70+
CompletionProposal proposal) {
71+
return ElementLabelProviderRegistry.getLabel(element, Mode.PROPOSAL,
72+
proposal);
7173
}
7274

7375
@Override
@@ -77,7 +79,7 @@ protected String createMethodProposalLabel(CompletionProposal methodProposal) {
7779
final Object info = methodProposal.getExtraInfo();
7880
if (info instanceof Method) {
7981
final Method method = (Method) info;
80-
final String label = getElementLabel(method);
82+
final String label = getElementLabel(method, methodProposal);
8183
if (label != null) {
8284
return label;
8385
}
@@ -127,7 +129,7 @@ protected String createFieldProposalLabel(CompletionProposal proposal) {
127129
final Object info = proposal.getExtraInfo();
128130
if (info instanceof Property) {
129131
final Property property = (Property) proposal.getExtraInfo();
130-
final String label = getElementLabel(property);
132+
final String label = getElementLabel(property, proposal);
131133
if (label != null) {
132134
return label;
133135
}

plugins/org.eclipse.dltk.javascript.ui/src/org/eclipse/dltk/javascript/ui/typeinfo/ElementLabelProviderRegistry.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ public static ImageDescriptor getImageDescriptor(Element element) {
3333
}
3434

3535
public static String getLabel(Element element, Mode mode) {
36+
return getLabel(element, mode, null);
37+
}
38+
39+
public static String getLabel(Element element, Mode mode, Object context) {
3640
for (IElementLabelProvider provider : manager) {
37-
String label = provider.getLabel(element, mode);
41+
final String label;
42+
if (provider instanceof IElementLabelProviderExtension) {
43+
label = ((IElementLabelProviderExtension) provider).getLabel(
44+
element, mode, context);
45+
} else {
46+
label = provider.getLabel(element, mode);
47+
}
3848
if (label != null) {
3949
return label;
4050
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012 NumberFour AG
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* NumberFour AG - initial API and Implementation (Alex Panchenko)
11+
*******************************************************************************/
12+
package org.eclipse.dltk.javascript.ui.typeinfo;
13+
14+
import org.eclipse.dltk.core.CompletionProposal;
15+
import org.eclipse.dltk.javascript.typeinfo.model.Element;
16+
17+
public interface IElementLabelProviderExtension extends IElementLabelProvider {
18+
19+
/**
20+
* Similar to {@link #getLabel(Element, Mode)}, but has additional parameter
21+
* <code>context</code>, if <code>mode</code> is {@link Mode#PROPOSAL} then
22+
* context should be of the {@link CompletionProposal} type.
23+
*
24+
* @return label or <code>null</code> to use next provider or default
25+
* implementation if none of the providers returned it.
26+
*/
27+
String getLabel(Element element, Mode mode, Object context);
28+
29+
}

0 commit comments

Comments
 (0)