本文整理匯總了TypeScript中@chemzqm/neovim.NeovimClient類的典型用法代碼示例。如果您正苦於以下問題:TypeScript NeovimClient類的具體用法?TypeScript NeovimClient怎麽用?TypeScript NeovimClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NeovimClient類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: default
export default (opts: Attach): Plugin => {
const nvim: NeovimClient = attach(opts)
const plugin = new Plugin(nvim)
let initialized = false
nvim.on('notification', async (method, args) => {
switch (method) {
case 'VimEnter': {
if (!initialized) {
initialized = true
await plugin.init()
}
break
}
case 'OptionSet':
await events.fire('OptionSet', args)
break
case 'InputChar':
await events.fire('InputChar', args)
break
case 'GlobalChange':
await events.fire('GlobalChange', args)
break
case 'CocAutocmd':
await events.fire(args[0], args.slice(1))
break
default:
const m = method[0].toLowerCase() + method.slice(1)
if (typeof plugin[m] == 'function') {
try {
await Promise.resolve(plugin[m].apply(plugin, args))
} catch (e) {
// tslint:disable-next-line:no-console
console.error(`error on notification '${method}': ${e}`)
}
}
}
})
nvim.on('request', async (method: string, args, resp) => {
try {
if (method == 'CocAutocmd') {
await events.fire(args[0], args.slice(1))
resp.send()
return
}
let m = method[0].toLowerCase() + method.slice(1)
if (typeof plugin[m] !== 'function') {
return resp.send(`Method ${m} not found`, true)
}
let res = await Promise.resolve(plugin[m].apply(plugin, args))
resp.send(res)
} catch (e) {
logger.error(`Error on "${method}": ` + e.stack)
resp.send(e.message, true)
}
})
nvim.channelId.then(async channelId => {
if (isTest) nvim.command(`let g:coc_node_channel_id = ${channelId}`, true)
let json = require('../package.json')
let { major, minor, patch } = semver.parse(json.version)
nvim.setClientInfo('coc', { major, minor, patch }, 'remote', {}, {})
let entered = await nvim.getVvar('vim_did_enter')
if (entered && !initialized) {
initialized = true
await plugin.init()
}
}).catch(e => {
console.error(`Channel create error: ${e.message}`) // tslint:disable-line
})
return plugin
}
示例2: require
nvim.channelId.then(async channelId => {
if (isTest) nvim.command(`let g:coc_node_channel_id = ${channelId}`, true)
let json = require('../package.json')
let { major, minor, patch } = semver.parse(json.version)
nvim.setClientInfo('coc', { major, minor, patch }, 'remote', {}, {})
let entered = await nvim.getVvar('vim_did_enter')
if (entered && !initialized) {
initialized = true
await plugin.init()
}
}).catch(e => {