Package javarepl.completion

Examples of javarepl.completion.CompletionResult


    }

    @Test
    public void returnsCompletions() throws Exception {
        client.execute("life = 42");
        CompletionResult result = client.completions("li");

        assertThat(result.expression(), is("li"));
        assertThat(result.position(), is(0));
        assertThat(result.candidates().map(candidateValue()), is(one("life")));
    }
View Full Code Here


            private jline.console.completer.Completer clientCompleter() {
                return new jline.console.completer.Completer() {
                    public int complete(String expression, int cursor, List<CharSequence> candidates) {
                        try {
                            CompletionResult result = client.completions(expression);
                            candidates.addAll(asList(toJson(result)));
                            return result.candidates().isEmpty() ? -1 : result.position();
                        } catch (Exception e) {
                            return -1;
                        }
                    }
                };
View Full Code Here

    public static class JlineCompletionHandler implements CompletionHandler {
        // TODO: handle quotes and escaped quotes && enable automatic escaping of whitespace

        public boolean complete(final ConsoleReader reader, final List<CharSequence> candidatesJson, final int pos) throws IOException {
            CursorBuffer buf = reader.getCursorBuffer();
            CompletionResult completionResult = fromJson(sequence(candidatesJson).head().toString());
            Sequence<String> candidatesToPrint = Sequences.empty(String.class);

            // if there is only one completion, then fill in the buffer
            if (completionResult.candidates().size() == 1) {
                CharSequence value = completionResult.candidates().head().value();

                // fail if the only candidate is the same as the current buffer
                if (value.equals(buf.toString())) {
                    return false;
                }

                setBuffer(reader, value, pos);
                candidatesToPrint = completionResult.candidates().flatMap(candidateForms());
            } else if (completionResult.candidates().size() > 1) {
                String value = getUnambiguousCompletions(completionResult.candidates());
                setBuffer(reader, value, pos);
                candidatesToPrint = completionResult.candidates().map(candidateValue());
            }

            printCandidates(reader, candidatesToPrint.safeCast(CharSequence.class).toList());

            // redraw the current console buffer
View Full Code Here

TOP

Related Classes of javarepl.completion.CompletionResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.