use of org.yamcs.studio.autocomplete.parser.FunctionDescriptor in project yamcs-studio by yamcs.
the class SimContentParser method parse.
@Override
public ContentDescriptor parse(ContentDescriptor desc) {
var startIndex = 0;
var contentToParse = desc.getValue();
if (contentToParse.startsWith(SIM_SOURCE)) {
contentToParse = contentToParse.substring(SIM_SOURCE.length());
// startIndex = SIM_SOURCE.length();
}
FunctionDescriptor currentDesc = null;
if (contentToParse.contains(AutoCompleteConstants.WILDCARD_MULTI_REPLACE) || contentToParse.contains(AutoCompleteConstants.WILDCARD_SINGLE_REPLACE)) {
currentDesc = new FunctionDescriptor();
currentDesc.setFunctionName(contentToParse);
} else {
currentDesc = ContentParserHelper.parseStandardFunction(contentToParse);
}
currentDesc.setContentType(SimContentType.SimFunction);
currentDesc.setStartIndex(startIndex);
currentDesc.setValue(contentToParse);
return currentDesc;
}
use of org.yamcs.studio.autocomplete.parser.FunctionDescriptor in project yamcs-studio by yamcs.
the class FormulaContentParser method handlePV.
private void handlePV(ExprPV pv) {
var name = pv.getName();
if (!name.endsWith("'")) {
var value = name.substring(1);
var startIndex = contentToParse.length() - value.length() + 1;
currentToken = new FunctionDescriptor();
currentToken.setValue(value);
currentToken.setStartIndex(startIndex);
currentToken.setContentType(ContentType.PV);
currentToken.setReplay(true);
}
}
use of org.yamcs.studio.autocomplete.parser.FunctionDescriptor in project yamcs-studio by yamcs.
the class FormulaContentParser method handleFunction.
private void handleFunction(ExprFunction f) {
if (f.isComplete()) {
return;
}
currentToken = new FunctionDescriptor();
currentToken.setValue(f.toString());
currentToken.setFunctionName(f.getName());
currentToken.setContentType(ContentType.FormulaFunction);
currentToken.setOpenBracket(true);
if (f.size() == 0) {
currentToken.setCurrentArgIndex(0);
return;
}
currentToken.setCurrentArgIndex(f.size() - 1);
var lastArg = f.getArg(f.size() - 1);
if (lastArg == null) {
return;
}
handleExpr(lastArg);
}
use of org.yamcs.studio.autocomplete.parser.FunctionDescriptor in project yamcs-studio by yamcs.
the class FormulaContentParser method handleVariable.
private void handleVariable(ExprVariable v) {
// No variables, only functions
var value = v.getName();
var startIndex = contentToParse.length() - value.length() + 1;
currentToken = new FunctionDescriptor();
currentToken.setValue(value);
currentToken.setStartIndex(startIndex);
currentToken.setFunctionName(value);
currentToken.setContentType(ContentType.FormulaFunction);
currentToken.setCurrentArgIndex(-1);
currentToken.setOpenBracket(false);
}
use of org.yamcs.studio.autocomplete.parser.FunctionDescriptor in project yamcs-studio by yamcs.
the class FormulaFunctionProvider method listResult.
@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
var result = new AutoCompleteResult();
FunctionDescriptor functionDesc = null;
if (desc instanceof FunctionDescriptor) {
functionDesc = (FunctionDescriptor) desc;
} else {
// empty result
return result;
}
var nameToFind = functionDesc.getFunctionName();
// handle proposals
var count = 0;
// insertionPos is not yet provided for formula
// TODO: improve parser
var originalContent = desc.getOriginalContent();
var insertionPos = originalContent.lastIndexOf(nameToFind);
if (!functionDesc.hasOpenBracket()) {
Proposal topProposal = null;
String closestMatchingFunction = null;
for (var functionName : functions.keySet()) {
if (functionName.startsWith(nameToFind)) {
var proposal = new Proposal(functionName + "(", false);
var description = functions.get(functionName).get(0).getDescription() + "\n\n";
for (var ff : functions.get(functionName)) {
description += generateSignature(ff);
}
proposal.setDescription(description);
for (var ff : functions.get(functionName)) {
proposal.addTooltipData(generateTooltipData(ff, 0));
}
proposal.addStyle(ProposalStyle.getDefault(0, nameToFind.length() - 1));
proposal.setInsertionPos(insertionPos);
// display function icon
proposal.setFunction(true);
result.addProposal(proposal);
count++;
if (closestMatchingFunction == null || closestMatchingFunction.compareTo(functionName) > 0) {
closestMatchingFunction = functionName;
topProposal = proposal;
}
}
}
// handle top proposals
if (closestMatchingFunction != null) {
result.addTopProposal(topProposal);
}
}
result.setCount(count);
// handle tooltip
if (functionDesc.hasOpenBracket() && !functionDesc.isComplete()) {
for (var setName : FormulaRegistry.getDefault().listFunctionSets()) {
var set = FormulaRegistry.getDefault().findFunctionSet(setName);
for (var function : set.findFunctions(nameToFind)) {
if (function.getName().equals(nameToFind)) {
if (function.getArgumentNames().size() >= functionDesc.getArgs().size() || function.isVarArgs()) {
result.addTooltipData(generateTooltipData(function, functionDesc.getCurrentArgIndex()));
}
}
}
}
}
return result;
}
Aggregations