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
