liveBook · Manning

Inline suggestion provider

As explained in LLMs in Production

An inline suggestion provider is a VS Code extension component that supplies completion suggestions displayed at the cursor position.

An inline suggestion provider supplies completion suggestions at the cursor, rendering generated text as ghost text that users can preview, accept with Tab, or reject. In a coding copilot, it replaces a conventional command as the main user-interface mechanism. section 10.3

A provider typically handles these responsibilities:

  • Implement provideInlineCompletionItems with the document, cursor position, invocation context, and cancellation token supplied by VS Code. section 10.3
  • Register for a language scope, such as Python files, or for all files. section 10.3
  • Restrict execution to manual triggers, read highlighted editor text, send it to an LLM service, and return the response as an inline suggestion. section 10.3

Minimal registration

const provider = { provideInlineCompletionItems: async (document, position, context, token) => { /* return suggestions */ } }; vscode.languages.registerInlineCompletionItemProvider({ scheme: 'file', language: 'python' }, provider); section 10.3

Listing 10.6 Example inline suggestion provider
// Create inline completion provider, this makes suggestions inline
const provider = {
    provideInlineCompletionItems: async (
            document, position, context, token
        ) => {
        // Inline suggestion code goes here

    }
};

// Add provider to Python files
vscode.languages.registerInlineCompletionItemProvider(
    { scheme: 'file', language: 'python' },
    provider
);
// Example of adding provider to all languages
vscode.languages.registerInlineCompletionItemProvider(
    { pattern: '**' },
    provider
);

Browse the compact provider definition and its language-scope registration examples. section 10.3

How LLMs in Production covers it

How deep it goes
Explains callback inputs, registration scope, manual triggering, selection handling, and response conversion, without detailing VS Code internals.
Examples
Uses JavaScript registration code, Python-only or all-language scopes, selected editor text, and an HTTP generation request.
What it assumes
Assumes a generated VS Code extension and introduces the relevant vscode library, editor objects, selections, and registration API.
What you can do after
Build it from scratch by registering a provider, filtering manual invocations, forwarding selected code, and returning generated completion text.
How it connects
Connects VS Code extensions with inline completion items, keybindings, editor selections, and LLM services.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.