liveBook · Manning

Coding copilot

As explained in LLMs in Production

A coding copilot is a software assistant that generates or suggests source code in response to a developer's context or request.

A coding copilot turns highlighted editor code into an LLM-generated inline suggestion. A practical implementation keeps the model local and connects it directly to VS Code. section 10.3

A minimal interaction flow:

  • Highlight code in a Python file and manually trigger the suggestion with Alt+S. section 10.3
  • Normalize backward selections so the cursor ends at the correct position before requesting completion. section 10.3
  • Send the selected text to an HTTP LLM service and return its response as ghost text. section 10.3

Local VS Code copilot

Create a VS Code extension with an inline completion provider. When the user selects code and presses Alt+S, POST the selection to http://localhost:8000/generate, then display the returned text at the selection endpoint; accept it with Tab. section 10.3

Listing 10.8 Sending a request to our coding copilot
// On activation send highlighted text to LLM for suggestions
if (manuallyTriggered && selection && !selection.isEmpty) {
    // Grab highlighted text
    const selectionRange = new vscode.Range(
        selection.start, selection.end
    );
    const highlighted = editor.document.getText(
        selectionRange
    );

    // Send highlighted text to LLM API
    var payload = {
        prompt: highlighted
    };

    const response = await fetch(
        'http://localhost:8000/generate', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(payload),
    });

    // Return response as suggestion to VSCode editor
    var responseText = await response.text();

    range = new vscode.Range(selection.end, selection.end)
    return new Promise(resolve => {
        resolve([{ insertText: responseText, range }])
    })
}

Inspect the request path that serializes highlighted editor text, calls the local generation endpoint, and converts the response into an editor suggestion. section 10.3

How LLMs in Production covers it

How deep it goes
Explains extension wiring, selection handling, API calls, and inline output, but stops short of broader production evaluation.
Examples
Demonstrates a Python-file extension using highlighted code, Alt+S, ghost text, Tab acceptance, and a localhost generation endpoint.
What it assumes
Assumes familiarity with VS Code extension development and HTTP requests while teaching the copilot integration workflow directly.
What you can do after
Builds a local coding copilot from scratch as a VS Code extension backed by an LLM API.
How it connects
Connects LLMs, VS Code extensions, inline completion providers, HTTP APIs, and local model services.

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.