liveBook · Manning

VS Code extension

As explained in LLMs in Production

A VS Code extension is a packaged software component that adds capabilities to the Visual Studio Code editor.

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

How LLMs in Production covers it

How deep it goes
Builds from generated scaffolding through activation, manifest configuration, inline suggestions, selections, and HTTP requests, while deferring production completeness.
Examples
Uses a Hello World scaffold, Python inline suggestions, highlighted selections, a local /generate endpoint, and a coding-copilot project.
What it assumes
Starts JavaScript and TypeScript unfamiliarity from basics, but requires Node, npm, and an updated VS Code installation.
What you can do after
Build it from scratch using the extension generator, VS Code API, inline completion provider, and an HTTP-based coding model.
How it connects
Connects inline completion providers with the VS Code API, JavaScript, Node.js, npm, LLM services, and retrieval-augmented generation.

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.