{"id":19410412,"url":"https://github.com/weirongxu/coc-helper","last_synced_at":"2025-04-24T10:32:38.291Z","repository":{"id":55409541,"uuid":"287501447","full_name":"weirongxu/coc-helper","owner":"weirongxu","description":"Helpers module for coc.nvim","archived":false,"fork":false,"pushed_at":"2023-01-26T02:53:52.000Z","size":889,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T03:33:30.663Z","etag":null,"topics":["coc","floating","vim"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weirongxu.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-14T09:57:54.000Z","updated_at":"2025-02-26T23:03:57.000Z","dependencies_parsed_at":"2023-02-14T13:31:30.575Z","dependency_job_id":null,"html_url":"https://github.com/weirongxu/coc-helper","commit_stats":null,"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weirongxu%2Fcoc-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weirongxu%2Fcoc-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weirongxu%2Fcoc-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weirongxu%2Fcoc-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weirongxu","download_url":"https://codeload.github.com/weirongxu/coc-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250609147,"owners_count":21458437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coc","floating","vim"],"created_at":"2024-11-10T12:16:39.187Z","updated_at":"2025-04-24T10:32:38.024Z","avatar_url":"https://github.com/weirongxu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# coc-helper\n\nHelpers for coc.nvim\n\n## Used by\n\n- [coc-floatinput](https://github.com/weirongxu/coc-floatinput)\n- [coc-explorer](https://github.com/weirongxu/coc-explorer)\n- [coc-webview](https://github.com/weirongxu/coc-webview)\n\n## Usage\n\n### activateHelper\n\n- **Note: Only some modules need to call activateHelper, as noted in the documentation below.**\n\n```typescript\nimport { activateHelper } from 'coc-helper';\n\nexport async function activate(context: ExtensionContext) {\n  await activateHelper(context);\n}\n```\n\n### Notifier\n\nCombine the notify of coc.nvim\n\n```typescript\nimport { Notifier } from 'coc-helper';\nimport { workspace } from 'coc.nvim';\n\nconst { nvim } = workspace;\n\n// create\nconst callNotifier = Notifier.create(() =\u003e {\n  nvim.call('func', true);\n  nvim.call('func2', true);\n});\n\nconst callNotifier2 = Notifier.create(() =\u003e {\n  nvim.call('func3', true);\n});\n\n// combine\nconst callNotifierCombined = callNotifier.concat(callNotifier2);\nconst callNotifierCombined2 = Notifier.combine([callNotifier, callNotifier2]);\n\nasync function fetchNotifier() {\n  return callNotifier;\n}\n\n// run\nawait callNotifierCombined.run();\nawait Notifier.run(fetchNotifier());\nawait Notifier.runAll([fetchNotifier(), callNotifierCombined]);\n\n// notify\nnvim.pauseNotification();\n(await fetchNotifier()).notify();\nNotifier.notifyAll([callNotifierCombined, callNotifier2]);\ncallNotifierCombined.notify();\nawait nvim.resumeNotification();\n```\n\n### HelperLogger\n\nLogger with OutputChannel support\n\n```typescript\nimport { ExtensionContext } from 'coc.nvim';\nimport { HelperLogger } from 'coc-helper';\nconst logger = new HelperLogger('extensionChannelName');\n\n// OutputChannel\nconst channel = logger.outputChannel;\n\nfunction activate(context: ExtensionContext) {\n  // Change level\n  logger.level = isDebug ? 'debug' : 'info';\n}\n\nasync function stuff() {\n  logger.info('info');\n  logger.warn('info');\n  // Log and print error\n  logger.error('error');\n\n  logger.prettyPrint({ token: 'xxx', data: 'foo' });\n\n  const [jobReturn, elapsedMilliseconds] = logger.measureTime(async () =\u003e {\n    return await asyncJobs();\n  });\n\n  await helperLogger.measureTask(async () =\u003e {\n    await asyncJobs();\n  }, 'job name');\n}\n```\n\n### HelperEventEmitter\n\nTyped events emitter\n\n```typescript\nimport { HelperEventEmitter, HelperLogger } from 'coc-helper';\nconst logger = new HelperLogger('extensionChannelName');\n\ninterface Events {\n  foo: (foo: number) =\u003e void;\n  bar: (bar: string) =\u003e Promise\u003cvoid\u003e;\n}\n\nconst events = new HelperEventEmitter(logger);\nevents.on('foo', (foo) =\u003e {});\nevents.fire('foo', 1);\n```\n\n### WinLayoutFinder\n\nFind the vim window by `winlayout()`\n\n```typescript\nimport { WinLayoutFinder } from 'coc-helper';\n\nconst winFinder = WinLayoutFinder.create(tabnr);\nconst leaf = winFinder.find(winid);\n// Parent\nconst parent = leaf.parent;\n// Group type, 'col' or 'row'\nconst parentType = parent.group.type;\n// Siblings\nconst siblings = parent.group.children;\n```\n\n### Jest setup and CI\n\njest.config.json\n\n```javascript\nconst jest = require('./node_modules/coc-helper/jest.config.js');\n\nmodule.exports = {\n  ...jest,\n  // your jest configuration in here\n  // clearMocks: true,\n  // moduleNameMapper: {\n  //   ...jest.moduleNameMapper,\n  //   '^lodash-es$': 'lodash',\n  // },\n};\n```\n\n[github ci workflows](./.github/workflows/ci.yml)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweirongxu%2Fcoc-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweirongxu%2Fcoc-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweirongxu%2Fcoc-helper/lists"}