public interface CodeCompletionProvider

Supplies IDE style code completion proposals to a CodeEditor.

The provider is invoked by the editor as the user types (or when completion is explicitly triggered) and returns its proposals asynchronously, which makes it suitable both for fast in-memory completion and for completion driven by a remote language server.

Example

editor.setCompletionProvider((ed, code, cursor, results) -> {
    String prefix = currentWord(code, cursor);
    List<CodeCompletion> out = new ArrayList<>();
    for (String kw : KEYWORDS) {
        if (kw.startsWith(prefix)) {
            out.add(new CodeCompletion(kw).setType("keyword"));
        }
    }
    results.onSucess(out);
});

Methods

public abstract void getCompletions(CodeEditor editor, String code, int cursorPosition, SuccessCallback<List<CodeCompletion>> results)Requests completion proposals for the given editor state.

Method details

getCompletions

public abstract void getCompletions(CodeEditor editor, String code, int cursorPosition, SuccessCallback<List<CodeCompletion>> results)
Requests completion proposals for the given editor state. Implementations must eventually invoke results.onSucess(list) (possibly asynchronously); passing an empty list or null hides the completion popup.

Parameters

editor CodeEditor
the editor requesting completions
code String
the full editor text
cursorPosition int
the character offset of the caret within code
results SuccessCallback<List<CodeCompletion>>
callback to deliver the proposals