use of org.yamcs.studio.autocomplete.proposals.Proposal 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;
}
use of org.yamcs.studio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class SimContentProvider 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 functionName = functionDesc.getFunctionName();
var set = DSFunctionRegistry.getDefault().findFunctionSet(SimDSFunctionSet.name);
// handle proposals
var count = 0;
if (!functionDesc.hasOpenBracket()) {
var regex = functionName;
regex = regex.replaceAll("\\*", ".*");
regex = regex.replaceAll("\\?", ".");
Pattern valuePattern = null;
try {
// start with !
valuePattern = Pattern.compile("^" + regex);
} catch (Exception e) {
// empty result
return result;
}
Proposal topProposal = null;
DSFunction closestMatchingFunction = null;
var offset = SimContentParser.SIM_SOURCE.length();
for (var function : set.getFunctions()) {
var m = valuePattern.matcher(function.getName());
if (m.find()) {
var proposalStr = function.getName();
if (hasMandatoryArgument(function)) {
proposalStr += "(";
}
proposalStr = SimContentParser.SIM_SOURCE + proposalStr;
var proposal = new Proposal(proposalStr, false);
var description = function.getDescription() + "\n\n" + generateSignature(function);
for (var poly : function.getPolymorphicFunctions()) {
description += "\n" + generateSignature(poly);
}
proposal.setDescription(description);
var currentArgIndex = -1;
if (hasMandatoryArgument(function)) {
currentArgIndex = 0;
}
proposal.addTooltipData(generateTooltipData(function, currentArgIndex));
for (var poly : function.getPolymorphicFunctions()) {
proposal.addTooltipData(generateTooltipData(poly, currentArgIndex));
}
proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
proposal.setInsertionPos(desc.getStartIndex());
result.addProposal(proposal);
count++;
if (closestMatchingFunction == null || closestMatchingFunction.getName().compareTo(function.getName()) > 0) {
closestMatchingFunction = function;
topProposal = proposal;
}
}
}
// handle top proposals
if (closestMatchingFunction != null && !functionName.isEmpty()) {
result.addTopProposal(topProposal);
}
}
result.setCount(count);
// handle tooltip
if (!functionDesc.isComplete()) {
for (var function : set.findFunctions(functionName)) {
// no tooltip for incomplete functions => use proposals
if (function.getName().equals(functionName)) {
if (checkToken(function, functionDesc)) {
result.addTooltipData(generateTooltipData(function, functionDesc.getCurrentArgIndex()));
}
for (var poly : function.getPolymorphicFunctions()) {
if (checkToken(poly, functionDesc)) {
result.addTooltipData(generateTooltipData(poly, functionDesc.getCurrentArgIndex()));
}
}
}
}
}
return result;
}
use of org.yamcs.studio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class SysContentProvider method provideFunctions.
private AutoCompleteResult provideFunctions(SysContentDescriptor sysDesc, int limit) {
var result = new AutoCompleteResult();
var count = 0;
var regex = sysDesc.getValue();
regex = regex.replaceAll("\\*", ".*");
regex = regex.replaceAll("\\?", ".");
Pattern valuePattern = null;
try {
// start with !
valuePattern = Pattern.compile("^" + regex);
} catch (Exception e) {
// empty result
return result;
}
Proposal topProposal = null;
String closestMatchingFunction = null;
var offset = SysContentParser.SYS_SOURCE.length();
for (var function : SysContentDescriptor.listFunctions()) {
var m = valuePattern.matcher(function);
if (m.find()) {
var fctDisplay = function;
fctDisplay = SysContentParser.SYS_SOURCE + function;
if (function.equals(SYSTEM_FUNCTION)) {
fctDisplay += SYSTEM_SEPARATOR;
}
var proposal = new Proposal(fctDisplay, false);
proposal.setDescription(SysContentDescriptor.getDescription(function));
proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
proposal.setInsertionPos(sysDesc.getStartIndex());
if (count <= limit) {
result.addProposal(proposal);
}
count++;
if (closestMatchingFunction == null || closestMatchingFunction.compareTo(function) > 0) {
closestMatchingFunction = function;
topProposal = proposal;
}
}
}
// handle top proposals
if (closestMatchingFunction != null) {
result.addTopProposal(topProposal);
}
result.setCount(count);
return result;
}
use of org.yamcs.studio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class ParameterContentProvider method listResult.
@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
var content = desc.getValue();
if (content.startsWith(getPrefix())) {
content = content.substring(getPrefix().length());
} else if (requirePrefix()) {
return new AutoCompleteResult();
}
content = AutoCompleteHelper.trimWildcards(content);
// Ignore specific index into array
content = content.replaceAll("\\[[0-9]+\\]", "[]");
var namePattern = AutoCompleteHelper.convertToPattern(content);
namePattern = Pattern.compile(namePattern.pattern(), Pattern.CASE_INSENSITIVE);
var result = new AutoCompleteResult();
var matchCount = 0;
var mdb = YamcsPlugin.getMissionDatabase();
if (mdb != null) {
for (var para : mdb.getParameters()) {
var pvCandidates = new ArrayList<String>();
pvCandidates.add(para.getQualifiedName());
if (para.hasType()) {
scanTypeForPvCandidates(para.getQualifiedName(), para.getType(), pvCandidates);
}
for (var pvCandidate : pvCandidates) {
var proposalValue = requirePrefix() ? getPrefix() + pvCandidate : pvCandidate;
var m = namePattern.matcher(proposalValue);
if (m.find()) {
var p = new Proposal(proposalValue, false);
p.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
result.addProposal(p);
matchCount++;
if (matchCount >= limit) {
break;
}
}
}
if (matchCount >= limit) {
break;
}
}
}
result.setCount(matchCount);
return result;
}
Aggregations