UNPKG

@chemzqm/neovim

Version:

NodeJS client API for vim9 and neovim

48 lines (47 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.attach = attach; const net_1 = require("net"); const constants_1 = require("../utils/constants"); const logger_1 = require("../utils/logger"); const client_1 = require("./../api/client"); function attach({ reader: _reader, writer: _writer, proc, socket, }, logger = null, requestApi = true) { let writer; let reader; let neovim; if (!logger) logger = logger_1.nullLogger; if (socket) { const client = (0, net_1.createConnection)(socket); writer = client; reader = client; client.once('close', () => { neovim.detach(); }); } else if (_reader && _writer) { writer = _writer; reader = _reader; } else if (proc) { writer = proc.stdin; reader = proc.stdout; proc.once('disconnect', () => { neovim.detach(); }); } writer.on('error', err => { if (err.code == 'EPIPE') { neovim.detach(); } }); if (writer && reader) { neovim = new client_1.NeovimClient(logger, constants_1.isVim); neovim.attach({ writer, reader, }, requestApi); return neovim; } throw new Error('Invalid arguments, could not attach'); }