A VS Code extension adds editor capabilities through a packaged project. A practical use is bringing a coding copilot into the editor, connecting inline suggestions to an LLM service while keeping the initial scope focused on Python. section 10.0
A minimal extension workflow is:
- Install Node and npm, preferably through a version manager, and update VS Code. section 10.3
- Generate Hello World scaffolding with the VS Code extension generator. section 10.3
- Configure package.json as the extension manifest, including commands, keybindings, activation events, and the VS Code engine version. section 10.3
- Implement activation and register an inline completion provider for Python files or broader language patterns. section 10.3
- Read editor selections, send highlighted code to an HTTP LLM endpoint, and return the response as an inline suggestion. section 10.3
An inline coding copilot
A generated extension can bind a manual shortcut to inline suggestions. When the user highlights code, the provider extracts the selection, posts it as a prompt to a local /generate endpoint, and places the response after the selection. section 10.3
Listing 10.4 Extension manifest for our coding copilot
{
"name": "llm-coding-copilot",
"displayName": "llm_coding_copilot",
"description": "VSCode extension to add LLM code suggestions inline.",
"version": "0.0.1",
"engines": {
"vscode": "^1.86.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onCommand:editor.action.inlineSuggest.trigger"
],
"main": "./extension.js",
"contributes": {
"commands": [{
"command": "llm-coding-copilot.helloWorld",
"title": "Hello World"
}],
"keybindings": [{
"key": "Alt+s",
"command": "editor.action.inlineSuggest.trigger",
"mac": "Alt+s"
}]
},
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "vscode-test"
},
"devDependencies": {
"@types/vscode": "^1.86.0",
"@types/mocha": "^10.0.6",
"@types/node": "18.x",
"eslint": "^8.56.0",
"typescript": "^5.3.3",
"@vscode/test-cli": "^0.0.4",
"@vscode/test-electron": "^2.3.8"
}
}
Inspect the manifest structure used to declare the extension name, activation behavior, commands, keybindings, scripts, dependencies, and supported VS Code version. section 10.3
