FunctionCompletion Example

Questions on using RSyntaxTextArea should go here.

Moderator: robert

FunctionCompletion Example

Postby marciosouzajunior » Mon Sep 24, 2012 4:03 am

Can someone give me a example of function completion?

thanks!
marciosouzajunior
 

Re: FunctionCompletion Example

Postby robert » Tue Sep 25, 2012 12:17 pm

Are you asking for an example of actual usage?

Usually you'll have several FunctionCompletions, and the library encourages you to store them in an XML file. Using DefaultCompletionProvider or a subclass, you can use one of the loadFromXML() method overloads. The XML loaded must validate with the CompletionXml.dtd. It allows you to define both function completions and keyword completions, along with documentation for both. For examples of the XML file format, see the XML files here in the RSTALanguageSupport project.

For a more concrete, specific example, I think something like this would work (untested, may need a slight tweak to actually work):

java code:

FunctionCompletion fc = new FunctionCompletion(provider, "printMultipleTimes", "bool");
fc.setReturnValueDescription("Whether the operation was successful");
List<ParameterizedCompletion.Param> params = new ArrayList<ParameterizedCompletion.Param>();
ParameterizedCompletion.Param param = new ParameterizedCompletion.Param("string", "toPrint");
param.setDescription("This is the string to print.");
params.add(param);
param = new ParameterizedCompletion.Param("int", "count", true);
param.setDescription("This parameter is the number of times to print the string.");
params.add(param);
fc.setParams(params);

completionProvider.addCompletion(fc); // Needs to be a subclass of AbstractCompletionProvider
User avatar
robert
 
Posts: 774
Joined: Sat May 10, 2008 5:16 pm

Re: FunctionCompletion Example

Postby marciosouzajunior » Tue Sep 25, 2012 5:26 pm

Hi Robert, you example helped me a lot. I extended you class:

java code:

public class ParameterFunc extends ParameterizedCompletion.Parameter{

public ParameterFunc(Object o, String string) {
super(o, string);
}

public ParameterFunc(String nome, String desc){
super(null, nome);
setDescription(desc);
}

}


And created a function:

java code:

private FunctionCompletion createFuncComp(DefaultCompletionProvider provider, String nome, String descricao, ParameterizedCompletion.Parameter... p) {

FunctionCompletion fc = new FunctionCompletion(provider, nome, "");
List params = new ArrayList<ParameterizedCompletion.Parameter>();
params.addAll(Arrays.asList(p));
fc.setParams(params);
fc.setShortDescription(descricao);
return fc;

}


So, I just call:

java code:

// abs
provider.addCompletion(createFuncComp(provider, "abs", "The abs() function returns the absolute (positive) portion of the integer number derived from the given numeric expression.",
new ParameterFunc("num.exp", "Expression resulting in an integer number.")));
marciosouzajunior
 


Return to Help

Who is online

Users browsing this forum: majenko and 2 guests

cron