mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
493 words
2 minutes
Getting Started with VSCode Plugin Development
2025-03-13

Development Environment#

  1. Node.js

  2. VS Code

  3. Yeoman&generator-code

    To conveniently generate the basic structure of a plugin project, you can use Yeoman and the official VS Code extension generator. Open a terminal and run the following commands to install globally:

    npm install -g yo generator-code

Initial Plugin Framework#

Create Plugin#

yo code

The generator will ask the following questions:

- **Choose Extension Type**:For example “New Extension (TypeScript)” or “New Extension (JavaScript)”.
- **Extension name and description**:Fill in the extension name and description as prompted.
- **Git initialization**:Whether to initialize a Git repository.
- **Package manager**:Choose using npm or yarn.

After generation completes, you will have a basic project structure scaffolded.

Understanding the Structure#

Open the generated project, you will see some important files and directories:

  • package.json

    This file defines the extension’s basic information, dependencies, as well as VS Code activation events and command registrations.

    For example:

    {
    "name": "my-sample-extension",
    "displayName": "My Sample Extension",
    "description": "A simple VS Code extension.",
    "version": "0.0.1",
    "engines": {
    "vscode": "^1.60.0"
    },
    "activationEvents": [
    "onCommand:extension.helloWorld"
    ],
    "main": "./out/extension.js",
    "contributes": {
    "commands": [
    {
    "command": "extension.helloWorld",
    "title": "Hello World"
    }
    ]
    },
    "scripts": {
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./"
    },
    "devDependencies": {
    "typescript": "^4.0.0",
    "vscode": "^1.1.37",
    "@types/node": "^12.0.0"
    }
    }
  • src/extension.ts (or extension.js)

    This is the entry point of the extension; this code runs when the extension is activated.

    For example, a simple sample:

    import * as vscode from 'vscode';
    export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "my-sample-extension" is now active!');
    let disposable = vscode.commands.registerCommand('extension.helloWorld', () => {
    vscode.window.showInformationMessage('Hello World from your VS Code extension!');
    });
    context.subscriptions.push(disposable);
    }
    export function deactivate() {}

Run and Debug#

  • After opening the project, in VS Code’s Debug panel, you will see a configuration named Launch Extension.
  • Press F5; VS Code will start a new Extension Development Host.
  • In the new window, via the Command Palette (Ctrl+Shift+P or Cmd+Shift+P), run the registered command, for example typing “Hello World” to test whether the extension works properly.

Publish Extension#

When development and testing are complete, you may consider publishing the extension to the VS Code Marketplace for others to use:

Specific Development#

Extension Activation#

VS Code extensions are activated according to the activationEvents array in package.json. Here are the main activation event types:

Common Activation Events#

    • Activate the extension immediately when VS Code starts
    • Pros: the extension is always available
    • Cons: may affect VS Code startup performance; not recommended for production environments
  1. onStartupFinished
    • Activate the extension after VS Code finishes starting up
    • Slightly later than the previous, but with less impact on startup performance
  2. onCommand
    • Activate the extension when the user executes a specific command
    • For example: onCommand.helloWorld
  3. onLanguage
    • Activate the extension when opening files of a specific language
    • For example: onLanguage, onLanguage
  4. onView
    • Activate the extension when a specific view becomes visible
    • For example: onView

Other Activation Events#

  1. onUri
  2. onWebviewPanel
    • Activate the extension when creating a specific type of Webview panel
  3. onCustomEditor
    • Activate the extension when opening a custom editor
  4. onDebug
    • Activate the extension when starting a debugging session
  5. onDebugInitialConfigurations
    • Activate the extension when initializing debug configurations
  6. onDebugResolve
    • Activate the extension when resolving a specific type of debug configuration
  7. onFileSystem
    • Activate the extension when accessing a specific filesystem scheme
    • For example: onFileSystem
  8. onTerminalProfile
    • Activate the extension when creating a terminal profile
  9. onAuthenticationRequest
    • Activate the extension when requesting authentication from a specific provider
  10. onSearch
    • Activate the extension when performing a search
  11. onTaskType
    • Activate the extension when executing a task of a specific type
  12. onNotebook
    • Activate the extension when opening a notebook of a specific type
  13. onTerminal
    • Activate the extension when a terminal is created
Share

If this article helped you, please share it with others!

Getting Started with VSCode Plugin Development
https://dreaife.tokyo/en/posts/vscode-plugin-dev/
Author
dreaife
Published at
2025-03-13
License
CC BY-NC-SA 4.0

Some information may be outdated

Related Posts Smart
1
Getting Started with Node.js
BACKEND Node.js is a JavaScript runtime based on the Chrome V8 engine, with features such as single-threaded execution, non-blocking I/O, modularization, and cross-platform support. Common modules include file system handling, HTTP services, path operations, and operating system information. npm is the package manager used to install and manage libraries. Asynchronous programming patterns include callbacks, Promise, and async/await, making Node.js suitable for building web services and real-time applications.
2
Getting Started with TypeScript
FRONTEND TypeScript basics include the type system, interfaces, classes, decorators, and more. It supports many primitive types such as number, string, and boolean, and also provides features such as type annotations, generics, union types, and type aliases. Decorators are used to apply metadata to classes and methods, while modules and namespaces help organize code.
3
Getting Started with Angular
FRONTEND This beginner guide to Angular covers project creation, Angular CLI commands, component and module structure, data binding, directives, services and dependency injection, routing and navigation, form handling, the HTTP client, RxJS, state management, performance optimization, PWA support, and internationalization. It includes detailed command examples and code structure references to help developers get started quickly.
4
Getting Started with Redis
middle-side Redis is an in-memory key-value NoSQL database with low latency and rich data structure support. Compared with traditional relational databases, Redis does not strictly constrain data formats and supports horizontal scaling. Common commands include key-value operations, hash operations, list operations, and set operations. Jedis and Spring Data Redis are the main Java clients for interacting with Redis, providing convenient APIs and connection pool management. Data serialization can be optimized with custom strategies to reduce memory usage.
5
Getting Started with RabbitMQ
middle-side RabbitMQ is a message queue that supports both synchronous and asynchronous communication. Asynchronous communication is decoupled through an intermediary broker, improving throughput and fault isolation. RabbitMQ can be installed with Docker and supports multiple messaging models, including work queues, publish/subscribe, and routing. Spring AMQP simplifies RabbitMQ usage by providing automatic queue declaration and asynchronous message receiving. JSON-based message converters can improve readability and efficiency.

Table of Contents