VS Code Extension Samples

repository·main·Indexed 27 days ago

https://github.com/microsoft/vscode-extension-samples

A collection of self-contained sample extensions illustrating various VS Code APIs and Contribution Points. Examples include implementing Chat Participants, Authentication Providers, Code Action Providers, CodeLens, Call Hierarchy, and the Commenting API to help developers learn and adapt code for their own extensions.

Tokens
115.1K
Snippets
265
Records
553
Agent score
94%

What's inside vscode-extension-samples

  1. Overview of the notebook-serializer-sample

    main

    This sample demonstrates how to implement notebook serializer and controller APIs in a VS Code extension. It provides three key functionalities:

    1. Notebook Serializer: Activated for files with the *.sample-json-notebook extension. It handles the serialization of notebook data into a JSON-based format.
    2. Notebook Controller: Provides execution capabilities for JSON-type code cells. When a cell is executed, the controller adds an output containing the cell's content parsed as JSON.
    3. Command: Includes a Create JSON Notebook command to instantiate a new untitled notebook of this specific type.
  2. Overview of LSP UI Example functionality

    main

    This sample demonstrates how to implement UI support for code actions within a Language Server Protocol (LSP) implementation. It is designed to work with plain text files and provides the following language features:

    • Diagnostics: Reporting errors or warnings in the code.
    • Code Actions with UI: Providing interactive user interface elements when performing code actions.
  3. Use MemFS to test filesystem provider compatibility

    main

    MemFS is an extension that implements an in-memory file system using the VS Code filesystem provider API. It serves two primary use cases:

    1. Reference Implementation: Provides a sample for extension authors looking to implement their own filesystem provider.
    2. Compatibility Testing: Acts as a testbed for other extensions to ensure they do not incorrectly assume that text documents always reside on a physical disk.
  4. Implement Custom Editors using the VS Code API

    main

    This sample demonstrates two ways to implement the Custom Editor API:

    • Custom Text Editor: Used for text-based or structured data files (like .cscratch JSON files). It utilizes the CustomTextEditor interface.
    • Binary Custom Editor: Used for non-textual files (like .pawdraw PNG files). It utilizes the CustomEditor interface.

    To register a provider for a specific file extension, use the window.registerCustomEditorProvider method from the vscode module.

  5. LSP Example Functionality and Structure

    main

    This sample demonstrates a Language Server working with plain text files.

    Supported Features

    • Completions: Provides language-specific suggestions.
    • Diagnostics: Automatically regenerates diagnostics on every file change or configuration change.
    • Testing: Includes End-to-End (E2E) tests for the Language Client and Server.

    Project Structure

    • client/src/extension.ts: The entry point for the Language Client.
    • client/src/test/: Contains End-to-End tests.
    • server/src/server.ts: The entry point for the Language Server.
    • package.json: The extension manifest.
  6. Implement document changes using the VS Code API

    main

    This sample demonstrates how to create a command that modifies the content of the active editor. The implementation relies on the following VS Code API components:

    • vscode.commands.registerCommand: To register the command that triggers the edit.
    • vscode.window.activeTextEditor: To access the currently focused editor.
    • vscode.TextDocument.getText: To retrieve text from the document.
    • vscode.TextEditor.edit: To perform the actual document modification.
    • vscode.TextEditorEdit: To define the specific edits (e.g., inserting or replacing text) within the edit method.