# Interface CodeCompletionProvider

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);
    });

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `getCompletions(CodeEditor editor, String code, int cursorPosition, SuccessCallback<List<CodeCompletion>> results)`
  Requests completion proposals for the given editor state.

- ## Method Details

  - ### getCompletions

    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`: the editor requesting completions

    - `code`: the full editor text

    - `cursorPosition`: the character offset of the caret within `code`

    - `results`: callback to deliver the proposals