Home » Modeling » TMF (Xtext) » How to dynamic filter the content assistant list in XxxProposalProvider?
How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692350] |
Wed, 15 April 2015 09:04 |
Bob Tao Messages: 23 Registered: March 2015 |
Junior Member |
|
|
Hi all,
I have a ProposalProvider class.
"public class UclProposalProvider extends AbstractUclProposalProvider "
I also implement the complete function, which works.
public void completeUclInstanceAttribute_Iafield(EObject model,
Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor)
when I press ctrl+/, it can show the content assistant.
public void completeUclInstanceAttribute_Iafield(EObject model,
Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
in this function , I can get the prefix String(context.getPrefix()) if I input some char before trigger the content assistant.
My problem is that how to refresh the list in the content assistant when I input the char dynamically.
I wish it just dynamically display the item that start with prefix like JDT editor.
I think Xtext support this feature, But I can't find the guide.
Thanks!
|
|
| |
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692356 is a reply to message #1692355] |
Wed, 15 April 2015 09:33 |
Bob Tao Messages: 23 Registered: March 2015 |
Junior Member |
|
|
Hi Christian,
if it is a cross reference, it is work automatically.
Before I can't use cross reference in this Object, the proposal is created by myself.
this a segment code in the function completeUclInstanceAttribute_Iafield.
EList<UclClassMember> members = ((UclClass) parentUclType)
.getMembers();
for (UclClassMember member : members) {
UclClassField field = (UclClassField) member;
UclType fieldType = field.getType();
String replacement = field.getName();
int cursorPosition = replacement.length();
if (fieldType instanceof UclEnum) {
replacement = field.getName() + " : ";
cursorPosition = replacement.length();
}
else if (field.getMaxSize() != null) {
replacement = field.getName() + "[ ];";
cursorPosition = replacement.length() - 3;
} else if (fieldType.getName().equals("Double")
|| fieldType.getName().equals("Long")
|| fieldType.getName().equals("Float")
|| fieldType.getName().equals("Int")
|| fieldType.getName().equals("String")
|| fieldType.getName().equals("JavaScript")
|| fieldType.getName().equals("Boolean")) {
replacement = field.getName() + " : ";
cursorPosition = replacement.length();
} else {
replacement = field.getName() + "{\n \n};";
cursorPosition = replacement.length() - 4;
}
String keyExt;
if (field.getIsRequired() != null) {
keyExt = "*";
} else {
keyExt = "";
}
String key = field.getName();
String additional = field.getType().getName() + " "
+ field.getName();
if (field.getType().getName().equals("JavaScript")) {
additional += "\nExample:\naction:\"/src/hello.js\"";
}
if(context.getPrefix()!=null && context.getPrefix().length()>0 && key.startsWith(context.getPrefix()))
{
ConfigurableCompletionProposal cp = createDalProposal(model,
replacement, key, keyExt, additional, cursorPosition,
context);
acceptor.accept(cp);
}
else if(context.getPrefix()==null || context.getPrefix().length()==0)
{
ConfigurableCompletionProposal cp = createDalProposal(model,
replacement, key, keyExt, additional, cursorPosition,
context);
acceptor.accept(cp);
}
it can filter at first time( I have input the prefix before trigger the content assistant).
but it can't refresh when I input the new char if it has been triggered.
thank your reply.
|
|
|
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1692357 is a reply to message #1692356] |
Wed, 15 April 2015 09:36 |
|
Hi,
i still cannot reproduce that.
the following Example Works fine for me
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
override completeModel_Value(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
super.completeModel_Value(model, assignment, context, acceptor)
acceptor.accept(createCompletionProposal("aaa", context))
acceptor.accept(createCompletionProposal("aab", context))
acceptor.accept(createCompletionProposal("aba", context))
acceptor.accept(createCompletionProposal("abb", context))
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| |
Re: How to dynamic filter the content assistant list in XxxProposalProvider? [message #1695394 is a reply to message #1692426] |
Thu, 14 May 2015 01:29 |
Bob Tao Messages: 23 Registered: March 2015 |
Junior Member |
|
|
Thank Sebastian!
I solved it according to your help.
ConfigurableCompletionProposal cp = new ConfigurableCompletionProposal(
replacementString, replacementOffset, replacementLength,
cursorPosition, img, displayString, null,
additionalProposalInfo);
cp.setMatcher(uclMatcher);
public class UclPrefixMatcher extends PrefixMatcher {
@Override
public boolean isCandidateMatchingPrefix(String name, String prefix) {
return name.regionMatches(true, 0, prefix, 0, prefix.length());
}
}
|
|
|
Goto Forum:
Current Time: Thu Sep 26 06:17:34 GMT 2024
Powered by FUDForum. Page generated in 0.08107 seconds
|