Search in sources :

Example 1 with StatementContext

use of com.twosigma.beakerx.groovy.autocomplete.GroovyParser.StatementContext in project beakerx by twosigma.

the class GroovyNodeCompletion method exitPathExpression.

@Override
public void exitPathExpression(PathExpressionContext ctx) {
    if (ctx.getStart().getStartIndex() < cursor && ctx.getStop().getStopIndex() + 1 >= cursor) {
        // it might be import
        if (ctx.getParent().getChild(0).equals(ctx) && ctx.getParent().getParent() != null && ctx.getParent().getParent() instanceof StatementContext && ctx.getParent().getParent().getChild(0).equals(ctx.getParent())) {
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        }
        // // try to expand this as a path expression
        if (ctx.getText().contains(".")) {
            addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_NON_STATIC), AutocompleteGroovyResult.getStartIndex(ctx));
            // complete with standard groovy extension functions
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, ctx.getText().substring(ctx.getText().lastIndexOf(".") + 1));
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
            addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
        } else {
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
            c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        }
    }
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) StatementContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.StatementContext)

Aggregations

AutocompleteCandidate (com.twosigma.beakerx.autocomplete.AutocompleteCandidate)1 StatementContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.StatementContext)1