lumide_api
The official SDK for building plugins for Lumide IDE.
lumide_api provides a set of high-level abstractions to interact with the Lumide IDE, allowing you to extend the editor, manage the file system, execute shell commands, and more.
Features
- Plugin Lifecycle: Seamlessly handle plugin activation and deactivation.
- Commands API: Register commands for the Command Palette with cross-platform keybindings, and run other commands with
executeCommand.
- Status Bar API: Create and manage custom status bar items.
- Editor API: Access active editor, selections, navigate to locations, and handle real-time events.
- Workspace API: Access configurations, get workspace root, get private plugin storage, find files by glob, and listen to document edits, saves, and file changes. Every listener returns a
LumideDisposable.
- FileSystem API: Secure file operations within the workspace, including directory creation and checks.
- Window API: UI interactions (messages with titles, quick picks, input boxes, confirm dialogs, file/folder pickers), cancellable status bar progress, and window focus changes.
- Shell & HTTP APIs: Controlled execution of shell commands (working directory, environment, stdin, signals) and standardized network requests.
- Toolbar API: Add custom buttons to the IDE toolbar.
- Context Menu API: Add actions to Add Pane, file tree, tab bar, and editor context menus with grouped sections.
- Terminal API: Create and control integrated terminals.
- Output API: Write logs and data to the Output Panel.
- Languages API: Register language servers (with per-extension language IDs), inline completion providers, formatters, and diagnostics; send custom LSP requests.
- Plugin manifests: Mark declarative asset-only plugins as non-executable with
executable: false; otherwise, process needs are inferred from the manifest.
- Snippet Contributions: Contribute TextMate-compatible snippets for one or more languages without starting a plugin process.
- Debug API: Start debugger sessions, synchronize breakpoints (with conditions and log messages), inspect stack frames/scopes/variables, evaluate expressions, and control exception pause mode.
- Tests API: Report test runs to Lumide's Tests pane, and hear when any run ends.
- Agents API: Follow the coding agents Lumide runs, Agent Chats and terminal agents: working, waiting for input, done, failed or ended.
- SDK Provider API: Contribute SDK catalogs, discovery, validation, install plans, workspace resolution, and host-validated execution, including long-running processes.
Getting Started
Add lumide_api to your pubspec.yaml:
dependencies:
lumide_api: ^1.12.0
Basic Usage
Extend the LumidePlugin class and implement the onActivate method:
import 'package:lumide_api/lumide_api.dart';
void main() => MyPlugin().run();
class MyPlugin extends LumidePlugin {
@override
Future<void> onActivate(LumideContext context) async {
// Show a message with a title
await context.window.showMessage(
'Plugin activated!',
title: 'My Plugin',
);
// Register a command
await context.commands.registerCommand(
id: 'my_plugin.hello',
title: 'Hello World',
callback: () async => log('Command executed!'),
);
// Run another command (Lumide's or another plugin's)
await context.commands.executeCommand('flutter.hotReload');
// Create a status bar item with an icon
await context.statusBar.createItem(
id: 'status',
text: 'Ready',
alignment: 'right',
iconPath: 'assets/my_icon.svg', // Optional SVG icon
);
}
}
Activation Events
Plugins are lazy-loaded by default to improve startup performance. Specify activation_events in your plugin.yaml to control when your plugin should be loaded.
[!NOTE]
If activation_events is empty or omitted, the plugin will NOT be started as a process. This is useful for plugins that only provide static assets like icon themes or color themes.
name: my_plugin
version: 0.0.1
activation_events:
- onStartup
- onCommand:my_plugin.hello
- workspaceContains:pubspec.yaml
Supported events:
onStartup: Activate immediately on IDE startup.
onCommand:<commandId>: Activate when a specific command is executed. Declare the command under contributes.commands so it appears in the Command Palette before the plugin starts.
workspaceContains:<fileName>: Activate if the workspace contains a specific file pattern. Start it with **/ (workspaceContains:**/pyproject.toml) to look a few folders deep too, for a folder of several projects.
onSdkProvider:<providerId>: Activate when the native SDK Manager needs a provider.
onProjectTemplate:<templateId>: Activate when the user creates a project from one of your templates.
Keybindings
Bind commands in plugin.yaml. Use mod for the primary modifier (Cmd on
macOS, Ctrl on Windows and Linux) so one binding works everywhere. when
takes the same context clauses as user keymaps, e.g. editorTextFocus or
terminalFocus && !editorFocus.
contributes:
keybindings:
- command: my_plugin.hello
key: 'mod+shift+h'
when: 'editorTextFocus'
SDK providers
SDK providers describe toolchains while Lumide owns downloads, checksums,
archive extraction, persistence, selection, progress, and native UI. Declare a
provider statically so it remains visible in Settings even before the plugin
process starts:
activation_events:
- onSdkProvider:example
permissions:
- network:
- downloads.example.dev
contributes:
sdkProviders:
- id: example
kind: example
title: Example SDK
capabilities:
catalog: true
discovery: true
resolution: true
validation: true
install: true
Register matching callbacks during activation. Install plans are declarative:
the host requires HTTPS and SHA-256, rejects unsafe archive paths, and performs
the installation itself.
context.sdks.onListAvailable((request) async {
return [
LumideSdkRelease(
id: 'example-2.0.0',
version: '2.0.0',
channel: 'stable',
archiveUri: 'https://downloads.example.dev/example-2.0.0.zip',
sha256: releaseSha256,
archiveFormat: LumideSdkArchiveFormat.zip,
archiveRootDirectory: 'example-sdk',
),
];
});
context.sdks.onGetInstallPlan((request) async {
final release = request.release;
final archiveUri = release.archiveUri;
final sha256 = release.sha256;
final format = release.archiveFormat;
final rootDirectory = release.archiveRootDirectory;
if (archiveUri == null ||
sha256 == null ||
format == null ||
rootDirectory == null) {
throw StateError('Release is not installable');
}
return LumideSdkInstallPlan.archive(
releaseId: release.id,
archiveUri: archiveUri,
sha256: sha256,
format: format,
rootDirectory: rootDirectory,
executables: const {'example': 'bin/example'},
);
});
context.sdks.onDiscover(discoverInstalledSdks);
context.sdks.onResolve(resolveExampleSdk);
context.sdks.onValidate(validateExampleSdk);
await context.sdks.registerProvider(
const LumideSdkProviderDescriptor(
id: 'example',
kind: LumideSdkKind('example'),
title: 'Example SDK',
capabilities: LumideSdkProviderCapabilities(
catalog: true,
install: true,
),
),
);
Use logical execution for one-shot SDK commands. The host resolves the selected
workspace SDK and validates that example belongs to its registered root.
final result = await context.sdks.run(
const LumideSdkResolveRequest(
kind: LumideSdkKind('example'),
providerId: 'example',
executable: 'example',
purpose: LumideSdkPurpose.build,
),
const ['build'],
workingDirectory: workspaceRoot,
);
Provider IDs are local in plugin code and are qualified by the host. Cache
catalog data in context.workspace.getPluginStorageDir() so installed SDK
management remains useful while offline. Never delete external SDK roots;
Lumide only uninstalls SDKs it installed beneath its managed storage root.
Project Templates
List the kinds of project you create under contributes.projectTemplates. Lumide shows them in its New Project dialog without starting your plugin, asks for the name and folder itself, and draws your fields:
activation_events:
- onProjectTemplate:my_plugin.app
contributes:
projectTemplates:
- id: my_plugin.app
name: App
description: A starter app
group: My Language
nameHint: my_app
namePattern: '^[a-z][a-z0-9_]*$'
nameRule: Use lowercase letters, digits and underscores.
packageName: true
fields:
- { id: platforms, type: multiSelect, label: Platforms, options: [web, desktop], default: [web, desktop], required: true }
- { id: org, type: text, label: Organization, default: com.example, remember: true, note: Can't change after release }
- { id: offline, type: boolean, label: Offline, advanced: true }
Field types are text, select, multiSelect (a list of values) and boolean. advanced folds a field under More, and remember makes the user's last value the next default. Options are values, or { value, label } maps.
packageName: true lets the folder and the package have different names. Lumide adds a Package name under More that follows the name until the user changes it; namePattern then checks the package name, and the folder can be called anything. Read it as request.packageName, which is request.name otherwise.
When the user presses Create, Lumide starts your plugin with onProjectTemplate:<id> and calls your handler. While it runs, you may write to request.parent without a file system permission:
context.projects.onCreate('my_plugin.app', (request) async {
final result = await context.shell.run(
'my-tool',
['new', request.name, '--package', request.packageName],
workingDirectory: request.parent,
);
if (result.exitCode != 0) {
throw Exception(result.stderr);
}
return const LumideProjectCreation(openFiles: ['src/main.ext']);
});
Throw to fail: Lumide shows the error's message in the dialog. Once you return, Lumide initializes Git if asked, opens the folder and your openFiles.
Workspace
Query the workspace root and search for files:
// Get the workspace root path (the first folder)
final root = await context.workspace.getRootUri();
// Every folder of the workspace, and changes to them
final folders = await context.workspace.getWorkspaceFolders();
context.workspace.onDidChangeWorkspaceFolders((event) {
for (final folder in event.added) indexFolder(folder.uri);
// event.folders lists every folder in order; event.reordered says they moved.
});
// The folder holding a file, or null outside every folder
final folder = await context.workspace.getWorkspaceFolder(fileUri);
// Find all pubspec.yaml files in every workspace folder, or in one
final pubspecs = await context.workspace.findFiles(
'**/pubspec.yaml',
maxResults: 50,
);
final folderPubspecs = await context.workspace.findFiles(
'**/pubspec.yaml',
folder: folder?.uri,
);
// Read a configuration value, for the folder of a file
final tabSize = await context.workspace.getConfiguration(
'editor.tabSize',
scope: fileUri,
);
// Get this plugin's private storage directory
final storageDir = await context.workspace.getPluginStorageDir();
await context.fs.writeString(
'$storageDir/cache.json',
'{"lastRun": "${DateTime.now().toIso8601String()}"}',
);
// Listen to file events. Every listener returns a LumideDisposable.
final saveListener = context.workspace.onDidSaveTextDocument((uri) {
log('File saved: $uri');
});
// Batched, ordered edits. A change without a range replaces the document.
// Lumide only tracks edits while at least one change listener exists.
final changeListener = context.workspace.onDidChangeTextDocument((event) {
for (final change in event.changes) {
log('${event.uri} v${event.version}: ${change.startLine}:${change.startColumn}');
}
});
// Files created, changed, deleted, or renamed by Lumide or other programs.
final filesListener = context.workspace.onDidChangeFiles((event) {
if (event.isOverflow) return rescanWorkspace();
for (final change in event.changes) {
if (change.uri.endsWith('/pubspec.yaml')) refreshDependencies();
}
});
// Stop listening.
saveListener.dispose();
changeListener.dispose();
filesListener.dispose();
Document and file events only cover paths allowed by the plugin's
fileSystem permissions.
Editor
Navigate, read, and manipulate documents:
// Open a document
await context.editor.openDocument('file:///path/to/file.dart');
// Navigate to a specific line
await context.editor.revealRange(
uri: 'file:///path/to/file.dart',
line: 42,
column: 10,
);
// Read the full text of an open document
final text = await context.editor.getDocumentText(
'file:///path/to/file.dart',
);
// Get or set selections
final selections = await context.editor.getSelections();
final selectedText = await context.editor.getSelectedText();
await context.editor.insertText('Hello!');
File System
Read, write, and inspect files:
// Check if a path is a directory
if (await context.fs.isDirectory('/some/path')) {
final entries = await context.fs.list('/some/path');
}
// Read and write files
final content = await context.fs.readString('/path/to/file.txt');
await context.fs.createDirectory('/path/to/generated', recursive: true);
await context.fs.writeString('/path/to/output.txt', content);
// Download and extract an archive natively via the IDE
await context.fs.downloadFile(
'https://example.com/file.tar.gz',
'/path/to/dest',
label: 'Downloading dependency',
extract: true,
);
Files under context.workspace.getPluginStorageDir() are private to your
plugin and do not require a fileSystem permission entry in plugin.yaml.
Other filesystem paths still require manifest permissions.
Shell
Execute commands with optional working directory: