Skip to main content

Developer Hub

Single-file Extensions

A focused guide for the single-file extensions stage of extension development. coc.nvim extensions expose an activate(context) entry point to the Node.js extension host.

Create a single-file extension

Use a single JavaScript file for a local prototype that needs the coc.nvim Node.js API but does not need packaging or publication.

  1. 01

    Find the config home

    Run :echo coc#util#get_config_home(). The directory can be overridden with g:coc_config_home before startup.

  2. 02

    Create coc-extensions

    Place local-hello.js under the config home’s coc-extensions directory.

  3. 03

    Restart and invoke

    Run :CocRestart, then :CocCommand local.hello.

coc-extensions/local-hello.js
1const { commands, window } = require('coc.nvim')
2 
3exports.activate = async context => {
4 const disposable = commands.registerCommand('local.hello', async () => {
5 await window.showInformationMessage('Hello from a single-file extension')
6 })
7 context.subscriptions.push(disposable)
8}

Optional activation and command metadata

Create a JSON file with the same basename beside the JavaScript file. Only activationEvents and contributes are used.

coc-extensions/local-hello.json
1{
2 "activationEvents": ["onCommand:local.hello"],
3 "contributes": {
4 "commands": [
5 { "id": "local.hello", "title": "Local: Say hello" }
6 ]
7 }
8}
Local-only boundary: single-file extensions load during coc.nvim initialization and are not managed by the extensions list. Move the prototype into a normal package when it needs dependencies, tests, updates, or :CocInstall distribution.

Build the next feature using the typings

Browse the current commands, workspace, window, languages, events, and public types available to your single-file extension.

Browse typings