Search in sources :

Example 6 with Proposal

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;
}
Also used : AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) FunctionDescriptor(org.yamcs.studio.autocomplete.parser.FunctionDescriptor) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Example 7 with Proposal

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;
}
Also used : Pattern(java.util.regex.Pattern) AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) FunctionDescriptor(org.yamcs.studio.autocomplete.parser.FunctionDescriptor) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Example 8 with Proposal

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;
}
Also used : Pattern(java.util.regex.Pattern) AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Example 9 with Proposal

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;
}
Also used : AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) ArrayList(java.util.ArrayList) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Aggregations

Proposal (org.yamcs.studio.autocomplete.proposals.Proposal)9 AutoCompleteResult (org.yamcs.studio.autocomplete.AutoCompleteResult)7 Pattern (java.util.regex.Pattern)4 ArrayList (java.util.ArrayList)3 FunctionDescriptor (org.yamcs.studio.autocomplete.parser.FunctionDescriptor)2 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Table (org.eclipse.swt.widgets.Table)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 TableItem (org.eclipse.swt.widgets.TableItem)1 Text (org.eclipse.swt.widgets.Text)1 ProposalStyle (org.yamcs.studio.autocomplete.proposals.ProposalStyle)1 TopProposalFinder (org.yamcs.studio.autocomplete.proposals.TopProposalFinder)1 TooltipData (org.yamcs.studio.autocomplete.tooltips.TooltipData)1 ContentProposalList (org.yamcs.studio.autocomplete.ui.content.ContentProposalList)1