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
