Developer Hub
API Recipes
A focused guide for the api recipes stage of extension development. coc.nvim extensions expose an activate(context) entry point to the Node.js extension host.
API recipes
Use disposables from registration calls and push them to context.subscriptions. Read the linked signature before copying an example.
commands.registerCommandRegister a command callable through CocCommand.workspace.getConfigurationRead extension settings with user and workspace scope.workspace.onDidChangeConfigurationWatch only the configuration keys your extension uses.workspace.applyEditApply a checked WorkspaceEdit and inspect the boolean result.languages.registerCompletionItemProviderProvide completion items for selected documents.window.createTreeViewRegister a TreeDataProvider and keep the returned view disposable.window.withProgressReport cancellable progress while work is running.services.registerLanguageClientRegister a language client with coc.nvim lifecycle management.window.showInformationMessageShow a native coc.nvim information message.window.createStatusBarItemCreate a status item and dispose it with the extension.window.showQuickPickOffer a searchable selection list to users.DisposableUse the returned disposable and push it to context.subscriptions.
src/index.ts
| 1 | import { commands, ExtensionContext, window } from 'coc.nvim' |
| 2 | |
| 3 | export function activate(context: ExtensionContext): void { |
| 4 | const disposable = commands.registerCommand('coc-demo.hello', () => { |
| 5 | window.showInformationMessage('Hello from coc-demo') |
| 6 | }) |
| 7 | context.subscriptions.push(disposable) |
| 8 | } |
For every registration, keep the returned Disposable in
context.subscriptions. Check a CancellationToken before expensive work, and return promptly when cancellation is requested. The typings reference is generated from the pinned coc.nvim TypeScript declarations; a language server is supplied separately by an extension.