← Vscode
Publishedrole: extensionlicense: BSD-3-Clause

tom_vscode_scripting_api

tom_vscode_scripting_api · v1.1.0

Bridge-agnostic Dart abstractions over VS Code's extension APIs. It defines the typed interface scripts write against and a socket bridge client that connects them to the extension host.

View repository → See License
Status
Published
LOC
8.0k
Tests
85
Test LOC
1.6k

Overview

`tom_vscode_scripting_api` is the Dart API surface that editor scripts target. It defines an abstract adapter contract plus typed namespaces over VS Code's Window, Workspace, Commands, Extensions, Language Model, and Chat APIs, with convenient top-level accessors like `window`, `workspace`, and `commands`. The interface is bridge-agnostic: the same script code runs against any adapter. A bundled socket-based, JSON-RPC client connects to the extension host, and an adapter wires the typed namespaces onto that transport. It is the scripting layer over the bridge runtime. Where `tom_vscode_bridge` provides the executing server, this package gives framework authors the clean, typed Dart surface to write VS Code automation against.

What it enables

Enables Typed VS Code scripting in Dart, Bridge-agnostic editor automation, Language-model access for scripts.

Relationships

Standalone — no declared relationships.

tom_vscode_scripting_api

Dart abstractions for VS Code extension APIs, providing a bridge-agnostic interface for VS Code scripting.

Overview

This package provides a complete Dart API surface for interacting with VS Code extensions. It defines abstract adapter interfaces and concrete socket-based bridge implementations, allowing Dart scripts to control VS Code windows, workspaces, commands, extensions, language models, and chat participants.

Features

  • **Window API** — Show messages, quick picks, input boxes, manage editors and terminals, display progress indicators.
  • **Workspace API** — Access workspace folders, read/write files, manage configuration, create file watchers.
  • **Commands API** — Execute and register VS Code commands.
  • **Extensions API** — Query and activate VS Code extensions.
  • **Language Model API** — Access AI models (e.g., GitHub Copilot) for chat completions and tool calls.
  • **Chat API** — Create chat participants, handle chat requests, stream responses.
  • **Bridge Client** — JSON-RPC 2.0 socket-based communication with the VS Code extension host.
  • **Script Globals** — Convenient top-level accessors (`vscode`, `window`, `workspace`, `commands`, `extensions`, `lm`, `chat`).

Getting Started

Add the package to your `pubspec.yaml`:

dependencies:
  tom_vscode_scripting_api: ^1.0.0

Usage

Using Script Globals

The simplest way to use the API is through the global accessors:

import 'package:tom_vscode_scripting_api/script_globals.dart';

void main() async {
  // Initialize with a bridge adapter
  VSCode.initialize(adapter);

  // Show a message
  await window.showInformationMessage('Hello from Dart!');

  // Execute a command
  await commands.executeCommand('workbench.action.files.save');

  // Read workspace folders
  final folders = await workspace.getWorkspaceFolders();
  print('Workspace folders: ${folders.map((f) => f.name).join(', ')}');
}

Using the Bridge Client

Connect to VS Code through the socket bridge:

import 'package:tom_vscode_scripting_api/tom_vscode_scripting_api.dart';

void main() async {
  // Create and connect the bridge client
  final client = VSCodeBridgeClient();
  await client.connect();

  // Create the adapter and initialize
  final adapter = VSCodeBridgeAdapter(client);
  VSCode.initialize(adapter);

  // Use the API
  final version = await vscode.getVersion();
  print('VS Code version: $version');

  // Cleanup
  await client.disconnect();
}

Window Operations

// Information, warning, and error messages
await window.showInformationMessage('Info');
await window.showWarningMessage('Warning');
await window.showErrorMessage('Error');

// Quick pick
final choice = await window.showQuickPick(
  ['Option A', 'Option B', 'Option C'],
  placeHolder: 'Choose an option',
);

// Input box
final input = await window.showInputBox(prompt: 'Enter a value');

// Open a file in the editor
await window.showTextDocument('/path/to/file.dart');

Language Model

// Select available models
final models = await lm.selectChatModels(vendor: 'copilot');
if (models.isNotEmpty) {
  final model = models.first;
  final response = await model.sendRequest([
    LanguageModelChatMessage.user('Explain this code'),
  ]);
  print(response);
}

Architecture

The package is structured around three layers:

1. **Adapter interface** (`VSCodeAdapter`) — Abstract request/response contract. 2. **Bridge implementation** (`VSCodeBridgeAdapter`, `VSCodeBridgeClient`) — Socket-based JSON-RPC 2.0 communication with the VS Code extension host. 3. **API namespaces** (`VSCodeWindow`, `VSCodeWorkspace`, etc.) — High-level typed APIs built on the adapter.

License

BSD-3-Clause — see [LICENSE](LICENSE) for details.

License
BSD 3-Clause License

Copyright (c) 2024-2026, Peter Nicolai Alexis Kyaw
Find me on LinkedIn under Alexis Kyaw
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.