Search in sources :

Example 1 with AutoCompleteResult

use of org.yamcs.studio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.

the class LocalContentProvider method listResult.

@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
    var result = new AutoCompleteResult();
    LocalContentDescriptor locDesc = null;
    if (desc instanceof LocalContentDescriptor) {
        locDesc = (LocalContentDescriptor) desc;
    } else {
        // empty result
        return result;
    }
    if (locDesc.isComplete()) {
        // empty result
        return result;
    }
    // handle proposals
    var count = 0;
    if (locDesc.isCompletingVType() && locDesc.getvType() != null) {
        var type = locDesc.getvType();
        Proposal topProposal = null;
        String closestMatchingType = null;
        for (var vType : LocalContentDescriptor.listVTypes()) {
            if (vType.startsWith(type)) {
                var prefix = locDesc.getPvName() + LocalContentParser.VTYPE_START;
                prefix = LocalContentParser.LOCAL_SOURCE + prefix;
                var offset = prefix.length();
                var proposal = new Proposal(prefix + vType + LocalContentParser.VTYPE_END, false);
                proposal.setDescription(LocalContentDescriptor.getVTypeDescription(vType));
                proposal.addStyle(ProposalStyle.getDefault(0, offset + type.length() - 1));
                proposal.setInsertionPos(desc.getStartIndex());
                result.addProposal(proposal);
                count++;
                if (closestMatchingType == null || closestMatchingType.compareTo(vType) > 0) {
                    closestMatchingType = vType;
                    topProposal = proposal;
                }
            }
        }
        // handle top proposals
        if (closestMatchingType != null && !type.isEmpty()) {
            result.addTopProposal(topProposal);
        }
    }
    result.setCount(count);
    // handle tooltip
    TooltipData td = null;
    if (locDesc.isCompletingInitialValue()) {
        td = new TooltipData();
        td.value = "pvname";
        var vType = locDesc.getvType();
        if (vType != null) {
            td.value += LocalContentParser.VTYPE_START + locDesc.getvType() + LocalContentParser.VTYPE_END;
        }
        td.value += LocalContentParser.INITIAL_VALUE_START;
        var start = td.value.length();
        td.value += locDesc.getInitialValueTooltip();
        var end = td.value.length();
        td.value += LocalContentParser.INITIAL_VALUE_END;
        td.styles = new ProposalStyle[1];
        if (locDesc.checkParameters()) {
            td.styles[0] = ProposalStyle.getDefault(start, end);
        } else {
            td.styles[0] = ProposalStyle.getError(start, end);
        }
        result.addTooltipData(td);
    } else if (locDesc.isCompletingVType()) {
        td = new TooltipData();
        td.value = "pvname<type>";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(6, 12);
        result.addTooltipData(td);
        td = new TooltipData();
        td.value = "pvname<type>(initialValue)";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(6, 12);
        result.addTooltipData(td);
    } else {
        // bold <type>
        int from = 6, to = 12;
        if (locDesc.getvType() == null) {
            // bold pvname
            from = 0;
            to = 6;
            td = new TooltipData();
            td.value = "pvname";
            td.styles = new ProposalStyle[1];
            td.styles[0] = ProposalStyle.getDefault(from, to);
            result.addTooltipData(td);
        }
        td = new TooltipData();
        td.value = "pvname<type>";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(from, to);
        result.addTooltipData(td);
        td = new TooltipData();
        td.value = "pvname<type>(initialValue)";
        td.styles = new ProposalStyle[1];
        td.styles[0] = ProposalStyle.getDefault(from, to);
        result.addTooltipData(td);
    }
    return result;
}
Also used : AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) ProposalStyle(org.yamcs.studio.autocomplete.proposals.ProposalStyle) TooltipData(org.yamcs.studio.autocomplete.tooltips.TooltipData) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Example 2 with AutoCompleteResult

use of org.yamcs.studio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.

the class StateContentProvider method provideFunctions.

private AutoCompleteResult provideFunctions(StateContentDescriptor stateDesc, int limit) {
    var result = new AutoCompleteResult();
    var count = 0;
    var regex = stateDesc.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 = StateContentParser.STATE_SOURCE.length();
    for (var function : StateContentDescriptor.listFunctions()) {
        var m = valuePattern.matcher(function);
        if (m.find()) {
            var fctDisplay = function;
            fctDisplay = StateContentParser.STATE_SOURCE + function;
            var proposal = new Proposal(fctDisplay, false);
            proposal.setDescription(StateContentDescriptor.getDescription(function));
            proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
            proposal.setInsertionPos(stateDesc.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 3 with AutoCompleteResult

use of org.yamcs.studio.autocomplete.AutoCompleteResult in project yamcs-studio by yamcs.

the class SysContentProvider method provideSystemProperties.

private AutoCompleteResult provideSystemProperties(SysContentDescriptor sysDesc, int limit) {
    var result = new AutoCompleteResult();
    var count = 0;
    var dotIndex = sysDesc.getValue().indexOf(SYSTEM_SEPARATOR);
    var propValue = sysDesc.getValue().substring(dotIndex + 1);
    var regex = propValue.replaceAll("\\.", "\\\\.");
    regex = regex.replaceAll("\\*", ".*");
    regex = regex.replaceAll("\\?", ".");
    Pattern valuePattern = null;
    try {
        // start with !
        valuePattern = Pattern.compile("^" + regex);
    } catch (Exception e) {
        // empty result
        return result;
    }
    List<String> matchingProperties = new ArrayList<>();
    var systemProperties = System.getProperties();
    Enumeration<?> enuProp = systemProperties.propertyNames();
    var offset = SysContentParser.SYS_SOURCE.length() + 7;
    while (enuProp.hasMoreElements()) {
        var propertyName = (String) enuProp.nextElement();
        var propertyValue = systemProperties.getProperty(propertyName);
        var m = valuePattern.matcher(propertyName);
        if (m.find()) {
            var propDisplay = SYSTEM_FUNCTION + SYSTEM_SEPARATOR + propertyName;
            propDisplay = SysContentParser.SYS_SOURCE + propDisplay;
            var proposal = new Proposal(propDisplay, false);
            proposal.setDescription(propertyValue);
            proposal.addStyle(ProposalStyle.getDefault(0, offset + m.end() - 1));
            proposal.setInsertionPos(sysDesc.getStartIndex());
            if (count <= limit) {
                result.addProposal(proposal);
            }
            matchingProperties.add(propertyName);
            count++;
        }
    }
    // handle top proposals
    var tpf = new TopProposalFinder(SYSTEM_SEPARATOR);
    for (var tp : tpf.getTopProposals(propValue, matchingProperties)) {
        var propDisplay = SYSTEM_FUNCTION + SYSTEM_SEPARATOR + tp.getValue();
        propDisplay = SysContentParser.SYS_SOURCE + propDisplay;
        var proposal = new Proposal(propDisplay, tp.isPartial());
        var propertyValue = systemProperties.getProperty(tp.getValue());
        proposal.setDescription(propertyValue);
        var tpStyle = tp.getStyles().get(0);
        proposal.addStyle(ProposalStyle.getDefault(tpStyle.from, (offset + tpStyle.to)));
        proposal.setInsertionPos(sysDesc.getStartIndex());
        result.addTopProposal(proposal);
    }
    result.setCount(count);
    return result;
}
Also used : Pattern(java.util.regex.Pattern) TopProposalFinder(org.yamcs.studio.autocomplete.proposals.TopProposalFinder) AutoCompleteResult(org.yamcs.studio.autocomplete.AutoCompleteResult) ArrayList(java.util.ArrayList) Proposal(org.yamcs.studio.autocomplete.proposals.Proposal)

Example 4 with AutoCompleteResult

use of org.yamcs.studio.autocomplete.AutoCompleteResult 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 5 with AutoCompleteResult

use of org.yamcs.studio.autocomplete.AutoCompleteResult 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)

Aggregations

AutoCompleteResult (org.yamcs.studio.autocomplete.AutoCompleteResult)7 Proposal (org.yamcs.studio.autocomplete.proposals.Proposal)7 Pattern (java.util.regex.Pattern)4 ArrayList (java.util.ArrayList)2 FunctionDescriptor (org.yamcs.studio.autocomplete.parser.FunctionDescriptor)2 ProposalStyle (org.yamcs.studio.autocomplete.proposals.ProposalStyle)1 TopProposalFinder (org.yamcs.studio.autocomplete.proposals.TopProposalFinder)1 TooltipData (org.yamcs.studio.autocomplete.tooltips.TooltipData)1