Plugin API Reference

This is the complete reference for the Colab Plugin API. All APIs are accessed through the PluginAPI object passed to your activate() function.


api.plugin

Read-only plugin metadata.

interface {
  readonly name: string;    // npm package name
  readonly version: string; // npm package version
}

api.commands

Register and execute commands.

registerCommand(id, handler)

Register a command that can be triggered by keybindings or other plugins.

const disposable = api.commands.registerCommand(
  'myPlugin.doSomething',
  async (...args: unknown[]) => {
    // Handle command
    return result;
  }
);

executeCommand(id, ...args)

Execute a registered command.

const result = await api.commands.executeCommand<MyResult>(
  'otherPlugin.command',
  arg1,
  arg2
);

api.webview

Inject scripts into web browser tabs.

registerPreloadScript(script)

Register JavaScript to be injected into all webviews. The script runs in the webpage context.

const script = `
  (function() {
    console.log('Injected script running!');
    // Modify the page, add event listeners, etc.
  })();
`;

const disposable = api.webview.registerPreloadScript(script);

api.terminal

Terminal operations and custom commands.

registerCommand(name, handler)

Register a terminal command. Users type the command name directly in the terminal.

const disposable = api.terminal.registerCommand('greet', async (ctx) => {
  const { args, cwd, terminalId, write } = ctx;

  // Write to terminal (supports ANSI escape codes)
  write('\x1b[32m'); // Green color
  write('Hello!\r\n');
  write('\x1b[0m');  // Reset color

  write(`Arguments: ${args.join(', ')}\r\n`);
  write(`Working directory: ${cwd}\r\n`);
});

TerminalCommandContext

Property Type Description
args string[] Command arguments (space-separated)
cwd string Current working directory
terminalId string Unique terminal identifier
write (text: string) => void Write output to terminal

createTerminal(options)

Create a new terminal instance.

const terminalId = await api.terminal.createTerminal({
  name: 'My Terminal',
  cwd: '/path/to/directory'
});

sendText(terminalId, text)

Send text to a terminal as if typed by the user.


api.editor

Editor operations and code completions.

registerCompletionProvider(languages, provider)

Register a completion provider for code suggestions.

const disposable = api.editor.registerCompletionProvider(
  ['typescript', 'javascript', 'typescriptreact', 'javascriptreact'],
  {
    triggerCharacters: ['.', '('],

    provideCompletions(ctx) {
      // ctx.linePrefix - text before cursor
      // ctx.lineText - full line text
      // ctx.lineNumber - 1-indexed line number
      // ctx.column - 1-indexed column
      // ctx.filePath - file path
      // ctx.triggerCharacter - character that triggered completion

      if (!ctx.linePrefix.endsWith('myLib.')) {
        return [];
      }

      return [
        {
          label: 'myFunction',
          insertText: 'myFunction($1)',
          detail: 'My custom function',
          documentation: 'Does something useful',
          kind: 'function',
        },
      ];
    },
  }
);

CompletionItem

Property Type Description
label string Text shown in completion list
insertText string Text to insert (supports $1, $0 placeholders)
detail string? Short detail shown next to label
documentation string? Longer description in details pane
kind string? 'function' | 'snippet' | 'text' | 'keyword' | 'variable' | 'class' | 'method' | 'property'

getActiveEditor()

Get information about the currently active editor.

getSelection()

Get the currently selected text.

insertText(text)

Insert text at the cursor position.


api.statusBar

Add items to the status bar.

createItem(item)

Create a status bar item. Returns a handle to update or dispose it.

const statusItem = api.statusBar.createItem({
  id: 'my-status',
  text: 'My Plugin',
  tooltip: 'Click for more info',
  color: '#00ff00',
  alignment: 'right', // 'left' or 'right'
  priority: 100,      // higher = more to the left
});

// Update the item
statusItem.update({
  text: 'Updated Text',
  color: '#ff0000',
});

// Remove when done
statusItem.dispose();

api.fileDecorations

Add decorations (badges, colors) to files in the file tree.

registerProvider(provider)

Register a file decoration provider.

const disposable = api.fileDecorations.registerProvider({
  provideDecoration(filePath) {
    if (filePath.endsWith('.test.ts')) {
      return {
        badge: 'T',
        badgeColor: '#00ff00',
        tooltip: 'Test file',
      };
    }

    if (filePath.includes('/deprecated/')) {
      return {
        faded: true,
        color: '#888888',
        tooltip: 'Deprecated',
      };
    }

    return undefined; // No decoration
  },
});

FileDecoration

Property Type Description
badge string? 1-2 character badge text or emoji
badgeColor string? CSS color for the badge
tooltip string? Hover tooltip text
faded boolean? Dim the file name
color string? CSS color for the file name

api.contextMenu

Add items to right-click context menus.

registerItem(item, handler)

Register a context menu item.

const disposable = api.contextMenu.registerItem(
  {
    id: 'my-action',
    label: 'Do Something',
    context: 'both', // 'editor' | 'fileTree' | 'both'
    shortcutHint: 'Ctrl+Shift+D', // Optional hint shown in menu
  },
  async (ctx) => {
    // ctx.filePath - file path if in file tree
    // ctx.selection - selected text if in editor
    api.log.info(`Action triggered for: ${ctx.filePath || ctx.selection}`);
  }
);

api.keybindings

Register keyboard shortcuts.

register(shortcut)

Register a keyboard shortcut that triggers a command.

const disposable = api.keybindings.register({
  key: 'ctrl+shift+m',  // Key combination
  command: 'myPlugin.myCommand', // Command to execute
  when: 'global', // 'editor' | 'terminal' | 'global'
});

Key Format

Keys are specified as lowercase strings with modifiers:

  • ctrl+k - Control + K
  • shift+enter - Shift + Enter
  • alt+shift+f - Alt + Shift + F
  • cmd+s or meta+s - Command/Meta + S

api.settings

Create a settings panel for your plugin. Users can access it by clicking on your plugin's status bar item.

registerSchema(schema)

Register a settings schema. This creates a settings panel accessible from your status bar item.

const disposable = api.settings.registerSchema({
  title: 'My Plugin Settings',
  description: 'Configure My Plugin behavior',
  fields: [
    {
      key: 'enabled',
      label: 'Enable Feature',
      type: 'boolean',
      default: true,
      description: 'Enable or disable the main feature',
    },
    {
      key: 'mode',
      label: 'Operation Mode',
      type: 'select',
      default: 'auto',
      options: [
        { label: 'Automatic', value: 'auto' },
        { label: 'Manual', value: 'manual' },
        { label: 'Disabled', value: 'disabled' },
      ],
      description: 'How the plugin should operate',
    },
    {
      key: 'delay',
      label: 'Delay (ms)',
      type: 'number',
      default: 1000,
      min: 100,
      max: 5000,
      step: 100,
      description: 'Delay in milliseconds',
    },
    {
      key: 'username',
      label: 'Username',
      type: 'string',
      default: '',
      description: 'Your username for the service',
    },
    {
      key: 'highlightColor',
      label: 'Highlight Color',
      type: 'color',
      default: '#ff0000',
      description: 'Color used for highlights',
    },
  ],
});

PluginSettingField

Property Type Description
key string Unique identifier for the setting
label string Display label shown to user
type string 'string' | 'number' | 'boolean' | 'select' | 'color'
default any? Default value
description string? Help text shown below the field
options array? For 'select' type: [{ label, value }]
min number? For 'number' type: minimum value
max number? For 'number' type: maximum value
step number? For 'number' type: increment step

get(key)

Get a setting value.

const isEnabled = api.settings.get<boolean>('enabled');
const mode = api.settings.get<string>('mode');
const delay = api.settings.get<number>('delay');

set(key, value)

Update a setting value. This persists the value and triggers change callbacks.

api.settings.set('enabled', false);
api.settings.set('delay', 2000);

getAll()

Get all settings as an object.

const allSettings = api.settings.getAll();
// { enabled: true, mode: 'auto', delay: 1000, ... }

onChange(callback)

Subscribe to settings changes. Called when any setting is modified (including from the UI).

const disposable = api.settings.onChange((key, value) => {
  api.log.info(`Setting changed: ${key} = ${value}`);

  if (key === 'highlightColor') {
    updateHighlightColor(value as string);
  }

  if (key === 'enabled') {
    if (value) {
      enableFeature();
    } else {
      disableFeature();
    }
  }
});

Status Bar Integration

When you register a settings schema and also have a status bar item, clicking on your status bar item will open the settings panel. This provides a convenient way for users to configure your plugin.

// Create status bar item
const statusItem = api.statusBar.createItem({
  id: 'my-plugin-status',
  text: 'My Plugin',
  tooltip: 'Click to configure',
  alignment: 'right',
});

// Register settings - clicking status item now opens settings
api.settings.registerSchema({
  title: 'My Plugin Settings',
  fields: [ /* ... */ ],
});

api.notifications

Show user notifications.

api.notifications.showInfo('Operation completed');
api.notifications.showWarning('Something might be wrong');
api.notifications.showError('Something failed');

api.log

Logging functions (always available).

api.log.debug('Debug message', { data: 123 });
api.log.info('Info message');
api.log.warn('Warning message');
api.log.error('Error message', error);

Logs appear in the Colab developer console with your plugin name as a prefix.


api.workspace

Workspace and file operations. Some methods require fs permissions.

// Get workspace folders
const folders = await api.workspace.getWorkspaceFolders();

// Check if file exists
const exists = await api.workspace.exists('/path/to/file');

// Read file (requires fs: 'readonly' or 'readwrite')
const content = await api.workspace.readFile('/path/to/file');

// Write file (requires fs: 'readwrite')
await api.workspace.writeFile('/path/to/file', content);

// Find files matching pattern
const files = await api.workspace.findFiles('**/*.ts');