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.
- 01
Find the config home
Run
:echo coc#util#get_config_home(). The directory can be overridden withg:coc_config_homebefore startup. - 02
Create coc-extensions
Place
local-hello.jsunder the config home’scoc-extensionsdirectory. - 03
Restart and invoke
Run
:CocRestart, then:CocCommand local.hello.
| 1 | const { commands, window } = require('coc.nvim') |
| 2 | |
| 3 | exports.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.
| 1 | { |
| 2 | "activationEvents": ["onCommand:local.hello"], |
| 3 | "contributes": { |
| 4 | "commands": [ |
| 5 | { "id": "local.hello", "title": "Local: Say hello" } |
| 6 | ] |
| 7 | } |
| 8 | } |
: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.