Giter Club home page Giter Club logo

node-client's Introduction

Coverity Scan analysis Packages Debian CI Downloads

Neovim is a project that seeks to aggressively refactor Vim in order to:

See the Introduction wiki page and Roadmap for more information.

Features

See :help nvim-features for the full list, and :help news for noteworthy changes in the latest version!

Install from package

Pre-built packages for Windows, macOS, and Linux are found on the Releases page.

Managed packages are in Homebrew, Debian, Ubuntu, Fedora, Arch Linux, Void Linux, Gentoo, and more!

Install from source

See BUILD.md and supported platforms for details.

The build is CMake-based, but a Makefile is provided as a convenience. After installing the dependencies, run the following command.

make CMAKE_BUILD_TYPE=RelWithDebInfo
sudo make install

To install to a non-default location:

make CMAKE_BUILD_TYPE=RelWithDebInfo CMAKE_INSTALL_PREFIX=/full/path/
make install

CMake hints for inspecting the build:

  • cmake --build build --target help lists all build targets.
  • build/CMakeCache.txt (or cmake -LAH build/) contains the resolved values of all CMake variables.
  • build/compile_commands.json shows the full compiler invocations for each translation unit.

Transitioning from Vim

See :help nvim-from-vim for instructions.

Project layout

├─ cmake/           CMake utils
├─ cmake.config/    CMake defines
├─ cmake.deps/      subproject to fetch and build dependencies (optional)
├─ runtime/         plugins and docs
├─ src/nvim/        application source code (see src/nvim/README.md)
│  ├─ api/          API subsystem
│  ├─ eval/         Vimscript subsystem
│  ├─ event/        event-loop subsystem
│  ├─ generators/   code generation (pre-compilation)
│  ├─ lib/          generic data structures
│  ├─ lua/          Lua subsystem
│  ├─ msgpack_rpc/  RPC subsystem
│  ├─ os/           low-level platform code
│  └─ tui/          built-in UI
└─ test/            tests (see test/README.md)

License

Neovim contributions since b17d96 are licensed under the Apache 2.0 license, except for contributions copied from Vim (identified by the vim-patch token). See LICENSE for details.

Vim is Charityware.  You can use and copy it as much as you like, but you are
encouraged to make a donation for needy children in Uganda.  Please see the
kcc section of the vim docs or visit the ICCF web site, available at these URLs:

        https://iccf-holland.org/
        https://www.vim.org/iccf/
        https://www.iccf.nl/

You can also sponsor the development of Vim.  Vim sponsors can vote for
features.  The money goes to Uganda anyway.

node-client's People

Contributors

billyvg avatar carlosrocha avatar chemzqm avatar chillee avatar dependabot[bot] avatar dylanscott avatar fidgetingbits avatar jalcine avatar janlazo avatar justinmk avatar kadobot avatar kalekseev avatar kwonoj avatar marg51 avatar mhartington avatar nhynes avatar pyrho avatar rhysd avatar simlrh avatar smolck avatar sohnryang avatar stefanpenner avatar tarruda avatar tsubota-kouga avatar tsukinoko-kun avatar xiyaowong avatar yanick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-client's Issues

NvimPlugin API change fails Nvim master build

Nvim master is failing since the new node-client release:

�[1m�[31m[  ERROR   ]�[0m�[0m �[1m1�[0m error, listed below:
�[1m�[31m[  ERROR   ]�[0m�[0m �[36m...ovim/neovim/test/functional/provider/nodejs_spec.lua�[0m @ �[36m40�[0m: �[1mnodejs host plugin works�[0m
test/functional/helpers.lua:312: 
retry() attempts: 99
test/functional/helpers.lua:99: Vim:E121: Undefined variable: g:job_out

stack traceback:
	test/functional/helpers.lua:312: in function 'retry'
	...ovim/neovim/test/functional/provider/nodejs_spec.lua:59: in function <...ovim/neovim/test/functional/provider/nodejs_spec.lua:40>


 �[1m14�[0m SKIPPED TESTS
 �[1m1�[0m ERROR
-- Output to stderr:

CMake Error at /home/travis/build/neovim/neovim/cmake/RunTests.cmake:53 (message):

Still investigating.

(@next) - cannot find module '../lib/host'

Trying to follow the install instructions here https://github.com/neovim/node-client/tree/next

I get this:

function remote#define#AutocmdBootstrap[1]..remote#host#Require[10]..provider#node#Require, line 22
Vim(if):ch 2 was closed by the client
module.js:487
    throw err;
    ^
Error: Cannot find module '../lib/host'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/neovim/bin/cli.js:2:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
Error detected while processing function remote#define#AutocmdBootstrap[1]..remote#host#Require[10]..provider#node#Require:
line   32:
E605: Exception not caught: Failed to load node host. You can try to see what happened by starting nvim with $NVIM_NODE_LOG_FILE set and opening the generated log file. Also, the host stderr is available in messages.
Error detected while processing function remote#define#AutocmdBootstrap[1]..remote#host#Require:
line   10:
E171: Missing :endif

I am running with $NVIM_NODE_LOG_FILE but nothing gets sent there.

Support Volta

volta.sh, (formally Notion) is a node launcher which takes over global installations of npm packages. When installing "neovim" with volta I get the following error:

## Node.js provider (optional)
  - INFO: Node.js: v10.16.0
  - WARNING: Missing "neovim" npm (or yarn) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim

Release with #54

There's an older plugin which I'd like to port, and it is not written in a language which can generate ES6 classes. The functional API is perfect though,

Is a release of master possible/ready?

Error Running README Sample

After installing node-host, after installing neovim@next, I get the following errors when running the sample on README. Tested with node version 7.5.0 as well as 8.0.0.

const nvim = await attach({ proc: nvim_proc });
                   ^^^^^^
SyntaxError: Unexpected identifier
    at Object.exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:533:3

Am I doing something wrong?

Can not register any command or function using plugin API

I'm using the example plugin code from readme, I can have plugin registered but no luck for command and function, the result in generated rplugin.vim would be

" node plugins
call remote#host#RegisterPlugin('node', '/Users/chemzqm/.vim/rplugin/node/index.js', [
     \ ])

The result of CheckHealth:

## Node provider (optional)
  - INFO: Node: v9.7.1
  - INFO: Host: /usr/local/bin/neovim-node-host
  - OK: Latest "neovim" npm is installed: 3.5.2

I have the same issue for neovim 0.2.2 and latest master branch.

export RPC functions

This is more a tracking issue.

Pynvim offers the ability to export RPC functions from the plugin decorator. This should be supported by node-client as well.

Bug: expand autocmd with <abuf> is wrong for BufUnload

  @Autocmd('BufUnload', {
    sync: true,
    pattern: '*',
    eval: 'expand("<abuf>")'
  })
  public async onBufUnload(bufnr: string):Promise<void> {
    logger.debug(`file: ${bufnr} remove`)
  }

The bufnr here is always the buffer number of current buffer number, but it should be the buffer number of removed buffer.

autocmd BufUnload * call s:OnUnload()
function! s:OnUnload()
  echo +expand('<abuf>')
endfunction

vim script doesn't have this problem.

BTW: <afile> is neither correct.

update README

Glad to see node plugin support landed in Neovim 0.2.2! 🎆

This project README still references installing node-host.

What are the new requirements for building a Neovim plugin in node? Is there a way to confirm that the engine is available?

Please consider improve blacklist behaviour

I'm using the module https://www.npmjs.com/package/mkdirp, and got:

2018-05-10T23:55:45.163Z - info: [complete.nvim] TypeError: process.umask is not a function
    at Function.sync (/Users/chemzqm/work/complete.nvim/node_modules/mkdirp/index.js:64:34)
    at RollingFileStream.BaseRollingFileStream.openTheStream (/Users/chemzqm/work/complete.nvim/node_modules/streamroller/lib/BaseRollingFileStream.js:79:10)
    at RollingFileStream.BaseRollingFileStream (/Users/chemzqm/work/complete.nvim/node_modules/streamroller/lib/BaseRollingFileStream.js:41:8)
    at new RollingFileStream (/Users/chemzqm/work/complete.nvim/node_modules/streamroller/lib/RollingFileStream.js:24:28)
    at openTheStream 

At first I thought some module is doing bad. And finally I found there is a BLACKLISTED_GLOBALS in node-client module. It's reasonable to blacklist these method, but for the developer experience, please consider add a warning when the blacklisted function is called instead of just let it throw.

Another thing is mkdirp call the method process.umask is just reading, https://github.com/substack/node-mkdirp/blob/master/index.js#L20 it should be possible to preserve the read behavior but prevent the write behavior.

Unknown function: remote#host#Register

I am facing this error when I open gvim but there is no error when I open nvim.

Please tell me how to fix this? Thank you

Error detected while processing /home/lalit/.vim/plugged/node-host/plugin/js_host.vim:
line    1:
E117: Unknown function: remote#host#Register

Can not compile with typescript

~/vim-dev/complete.nvim(master|●7✚3…)
❯ npm run build

> [email protected] build /Users/chemzqm/vim-dev/complete.nvim
> tsc

src/index.ts(3,1): error TS1238: Unable to resolve signature of class decorator when called as an expression.
  Cannot invoke an expression whose type lacks a call signature. Type 'PluginWrapperConstructor | ((cls: any) => PluginWrapperConstructor)' has no compatible call signatures.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/chemzqm/.npm/_logs/2018-05-02T23_33_30_165Z-debug.log

Change

export declare function plugin(outter: any): PluginWrapperConstructor | ((cls: any) => PluginWrapperConstructor);

to

export declare function plugin(outter: any): any

in neovim/lib/plugin/plugin.d.ts could fix this problem, I don't know if there is better way.

Node 12 support

There seems to be an issue when used with nodejs 12.4

Just the mention of 'Buffer' inside a plugin, triggers a 'ReferenceError: Buffer is not defined'.
When switching back to nodejs 10 the problem goes away.

Node Provider Configuration Issue

I think there's a bug related to how the neovim interpret the configuration for Node.js provider. Below are the steps to duplicate the problem I had, and the way how I fixed it.

Problem:

  • I have a clean install of node, npm, and nvm, and I installed the node-client globally with npm install -g neovim.
  • Then I editted the neovim configuration file (under ~/.config/neovim/init.vim on my disk) with let g:node_host_prog = '~/.nvm/versions/node/v11.3.0/bin/neovim-node-host'.
  • If I run the :checkhealth command in neovim, it always shows that the node '~/.nvm/versions/node/v11.3.0/bin/neovim-node-host'' --version throws an error which says it cannot find the file /Users/myusername/~/.nvm/versions/node/v11.3.0/bin/neovim-node-host'

My Fix:

  • I change the configuration to let g:node_host_prog = '.nvm/versions/node/v11.3.0/bin/neovim-node-host' and the :checkhealth finally passed with no error.

Deadlock when registering plugin host

While trying to implement a plugin host, I ran into difficulties with deadlock. The crux of the issue is that this library waits until after receiving api info to register the request and notification handlers. This prevents it from handling Neovim's synchronous specs request (@see the request and how it blocks).

Neovim              Node
specs -------------> *       (blocking request on Neovim's end)
  * <------------ api_info   (blocking request on Node's end)

I see two solutions to this problem (though I may be myopic!). The first is to immediately register the request and notification handlers and return a promise on the fully-populated nvim object (and convert the rest of the library to use promises, too). The second, which seems like the simplest way to avoid duplication of effort for clients, is to allow Neovim, acting as a RPC client, to handle requests on a separate thread, like a RPC server.

It goes without saying that I'd be happy to help look into whichever solution is deemed most appropriate.

Edit: a third solution would be to simply buffer non-specs requests/notifications until the api has been processed.

floating window and setlines jump

Trying out floatingWindows and noticed a jump when the floating window's buffer has lines set.

Without calling setLines, the buffer/window position is set correctly.

This is the pseudo-code used.

      const buffer = (await this.nvim.createBuffer(false, false)) as Buffer;
      const text = errorSign.text.split('\n');
      await buffer.setLines(text, { start: 0, end: -1, strictIndexing: false });

      this.floatingWindow = (await this.nvim.openWindow(buffer, false, 20, 10, {
        relative: 'cursor',
        row: 1,
        col: 0
      })) as Window;

Run tests on Appveyor to debug rplugin on Windows

After work done on neovim/neovim#7706, neovim/neovim#7734, neovim/neovim#7738, I can't make a simple echo class with an EchoHello command work on Windows. The APIs are fine because testing on them directly, bypassing the host and rplugin/node, works on all OS consistently. :checkhealth and :UpdateRemotePlugins are ok now (on Windows) and I see rplugin.vim with EchoHello registered from nodejs plugin I made it.

That leaves msgpack and the RPC api from both sides which I don't know how to debug/fix yet.
To get more debug info, the tests should run on Appveyor as well. We can reuse the same configuration from neovim repo.

neovim not registering RPC commands for Node.js remote plugins

Howdy!

It seems like neovim isn't correctly registering RPC commands for Node.js remote plugins: it detects that the remote plugin exists, but doesn't actually add dictionary entries for the plugin's commands/functions/autocmds in the remote plugin manifest.

I've tried "hardcoding" the remote plugin manifest with the correct values, and once I do that, the remote plugin seems to work fine.

This might be the same issue as described in #53 and/or #43, and possibly fixed by #54, but the issue still occurs on my machine for whatever reason.

Steps to Reproduce

cd temp
git clone https://github.com/neovim/node-client.git && cd node-client

cd examples
cat << EOF > .vimrc
set runtimepath+=.
EOF

cd rplugin/node/demo_beautify_css
yarn install

cd ../../..

nvim -u .vimrc +UpdateRemotePlugins
# then exit nvim

cat /home/$USER/.local/share/nvim/rplugin.vim

Expected Output

" node plugins
call remote#host#RegisterPlugin('node', './rplugin/node/demo_beautify_css', [
      \ {'sync': v:false, 'name': 'BeautifyCSS', 'type': 'command', 'opts': {'nargs': '0'}},
     \ ])


" python3 plugins


" ruby plugins


" python plugins

Actual Output

" node plugins
call remote#host#RegisterPlugin('node', './rplugin/node/demo_beautify_css', [
     \ ])


" python3 plugins


" ruby plugins


" python plugins

Version Info

Tested on Ubuntu 16.04.

NVIM v0.3.1
Build type: RelWithDebInfo
LuaJIT 2.0.4
Compilation: /usr/bin/x86_64-linux-gnu-gcc -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG -Wdate-time -D_FORTIFY_SOURCE=2 -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim-xZey2V/neovim-0.3.1/build/config -I/build/neovim-xZey2V/neovim-0.3.1/src -I/usr/include -I/build/neovim-xZey2V/neovim-0.3.1/build/src/nvim/auto -I/build/neovim-xZey2V/neovim-0.3.1/build/include
Compiled by [email protected]

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info
# node.js
v11.4.0

checkhealth Output

health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: RelWithDebInfo

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~

## tmux
  - OK: escape-time: 1ms
  - INFO: $TERM: xterm-256color
  - INFO: default-terminal: tmux
  - ERROR: $TERM differs from the tmux `default-terminal` setting. Colors might look wrong.
    - ADVICE:
      - $TERM may have been set by some rc (.bashrc, .zshrc, ...).

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: xclip

## Python 2 provider (optional)
  - INFO: `g:python_host_prog` is not set.  Searching for python2 in the environment.
  - INFO: Executable: /usr/bin/python2
  - INFO: Python2 version: 2.7.12
  - INFO: python2-neovim version: 0.3.1
  - OK: Latest python2-neovim is installed: 0.3.1

## Python 3 provider (optional)
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - INFO: Executable: /usr/bin/python3
  - INFO: Python3 version: 3.5.2
  - INFO: python3-neovim version: 0.3.1
  - OK: Latest python3-neovim is installed: 0.3.1

## Ruby provider (optional)
  - INFO: Ruby: ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
  - WARNING: `neovim-ruby-host` not found.
    - ADVICE:
      - Run `gem install neovim` to ensure the neovim RubyGem is installed.
      - Run `gem environment` to ensure the gem bin directory is in $PATH.
      - If you are using rvm/rbenv/chruby, try "rehashing".
      - See :help |g:ruby_host_prog| for non-standard gem installations.

## Node.js provider (optional)
  - INFO: Node.js: v11.4.0
  - INFO: Neovim node.js host: /usr/lib/node_modules/neovim/bin/cli.js
  - OK: Latest "neovim" npm/yarn package is installed: 4.2.1

Thanks in advance!

$NVIM_NODE_HOST_DEBUG should not rely on the end user running cli.js directly

See neovim/neovim#7706 (comment)

I can't add --inspect-brk on node.exe on Windows because of how the npm shims work. On Ubuntu, neovim-node-host is a javascript shim (with /usr/bin/env node as first line) so the user can run it with node directly instead of relying on the shell to do it for you. That doesn't work in Windows, even on Cygwin, so the only way to add it is something like node --inspect-brk C:\node\node_modules\neovim\bin\cli.js, ignoring the npm shims.

I prefer that this be resolved on bin/cli.js by restarting itself with --inspect-brk if the environment variable is defined.

process.stdout.write or console.log in forked process killing the plugin process

So, I've got a very peculiar case where I was noticing that the plugin process dies whenever a forked process tries to call console.log or process.stdout.write.

Steps to reproduce:

cat << EOF > .vimrc
execute 'set runtimepath+='.getcwd()
EOF

mkdir -p ./rplugin/node/sample.vim

cat << EOF > ./rplugin/node/sample.vim/index.js
const { fork } = require('child_process');

module.exports = plugin => {
  function TestMe() {
    const child = fork(\`\${__dirname}/child.js\`);
    console.log('--end function--');
  }

  plugin.registerCommand("TestMe", [plugin.nvim.buffer, TestMe]);
};

process.on('exit', msg => {
  console.log('exiting..', msg);
})
EOF

cat << EOF > ./rplugin/node/sample.vim/child.js
(function test(){
  console.log("should print hello");
  return "hello";
}());
EOF

cd ./rplugin/node/sample.vim && npm init -y

cd ../../../
nvim -u .vimrc +UpdateRemotePlugin

Now when we start nvim

NVIM_NODE_LOG_FILE=./loggy nvim

and run :TestMe command that we registered in our plugin and check our log in loggy
we notice that the plugin process has exited.
But we carry on and run :TestMe one more time and to find that it fails to run again.

To confirm this I had htop opened with node filtered and I do notice that it kills the node process that the plugin started.

In order to make this work I simply removed
console.log("should print hello"); from child.js and it worked just fine.

It's mentioned that winston is used instead of console.log in the readme and I wonder if that has something to do with it.

Anyway, would be curious to find out what's causing this even though it's not a blocker for me right now.
Cheers.

Having `neovim` required will break the plugin

Been trying to figure out why my plugin doesn't work for about two hours now.
Turns out that if there is a require("neovim") in the plugin it will just not work.
Importing other modules works just fine.
I couldn't find any logs related to this, is there any way to debug something like this?

Versions:

  • neovim: v0.5.0-271-g52566dd78
  • neovim node package: "^4.7.0"

Let me know if I can help.

Edit:
The same happens with console.log.
It fails with the error from this issue: winstonjs/winston#1577

"Error: Invalid method arguments" when using promises

When cloning the current source, running npm i, and then make, I get the following error from mocha:

(node:91429) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Invalid method arguments
(node:91429) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Source of the problem seems to be this not getting passed properly when using Buffer, Window, or Tabpage.

I'm experiencing the same problem in my source. This doesn't work:

const pos = await win.getPosition()

This almost works, but throws a different error:

const pos = await win.getPosition(win)

How could I catch the errors of current plugin?

It seemsnode-client is not providing a good feed back when where's error thrown in remote plugins, it just log the error. So I need to figure out the way to notify user when there's error thrown.

I know I can do:

    process.on('unhandledRejection', (reason, p) => {
    })
    process.on('uncaughtException', this.handleError)

But the error here could be comes from other plugins.

Calling API after UI attaching occurs an error.

Hi, I'm making neovim GUI frontend with node.js.

Please see below test code.

var cp = require('child_process');
var attach = require('.');

var nvim_proc = cp.spawn('nvim', ['-u', 'NONE', '-N', '--embed'], {});
attach(nvim_proc.stdin, nvim_proc.stdout, function(err, nvim) {
  nvim.on('request', function(method, args, resp) {
    console.log('request', method, args, resp);
  });

  nvim.on('notification', function(method, args) {
    console.log('notification', method, args);
  });

  nvim.on('disconnect', function() {
    console.log('disconnected');
  });

  nvim.uiAttach(80, 24, true, function() {
    nvim.getBuffers(function(err, bufs){
        if (err) {
            console.error(err);
            return;
        }
        console.log(bufs[0]);
    });
  });
});

After UI attaching, some APIs (here, I used getBuffers as example) fail with below error.

TypeError: this.slice(...)[m] is not a function
    at BufferList.(anonymous function) [as readUInt8] (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/node_modules/bl/bl.js:210:58)
    at tryDecode (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/index.js:219:21)
    at Object.decode (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/index.js:203:18)
    at Decoder.decodeWithoutHeader [as _transform] (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/lib/streams.js:79:32)
    at Decoder.decodeWithoutHeader [as _transform] (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/lib/streams.js:91:10)
    at Decoder.Transform._read (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at Decoder.Transform._write (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/node_modules/readable-stream/lib/_stream_writable.js:279:12)
    at writeOrBuffer (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/node_modules/readable-stream/lib/_stream_writable.js:266:5)
    at Decoder.Writable.write (/Users/rhayasd/Dev/github.com/neovim/node-client/node_modules/msgpack5rpc/node_modules/msgpack5/node_modules/readable-stream/lib/_stream_writable.js:211:11)

I'm in trouble with this error because my frontend can't get the information from neovim while UI attaching. (Of course many UI notifications are sent from neovim, but I want more information about buffers, windows and tabs to improve frontend behavior.)

I tried to fix this issue, but I couldn't because the error occured deeply inside the depended libraries.

My environment is below:

  • OS X 10.11
  • node.js 4.1.0 or Electron v0.34.2

Node 12 support

This is basically #122 but with reproduction steps.

Using one of the examples, but with console.log(Buffer) line in a command:

$ mkdir -p /tmp/test/rplugin/node/test

$ cat > /tmp/test/rplugin/node/test/index.js <<EOF
class MyPlugin {
  constructor(plugin) {
    this.plugin = plugin;

    plugin.registerCommand('SetMyLine', [this, this.setLine]);
  }

  setLine() {
    console.log(Buffer)
    this.plugin.nvim.setLine('A line, for your troubles');
  }
}

module.exports = (plugin) => new MyPlugin(plugin);

// Or for convenience, exporting the class itself is equivalent to the above

module.exports = MyPlugin;
EOF

On node 10 this works as expected and buffer updated with a line, on node 12 nothing happens and log contains:

Error in plugin for command:SetMyLine: Buffer is not defined (file: /tmp/test/rplugin/node/test, stack: ReferenceError: Buffer is not defined
  at MyPlugin.setLine (/tmp/test/rplugin/node/test/index.js:9:17)
  at Object.fn (/home/konstantin/.config/yarn/global/node_modules/neovim/lib/host/NvimPlugin.js:19:26)
  at NvimPlugin.<anonymous> (/home/konstantin/.config/yarn/global/node_modules/neovim/lib/host/NvimPlugin.js:156:41)
  at Generator.next (<anonymous>)
  at /home/konstantin/.config/yarn/global/node_modules/neovim/lib/host/NvimPlugin.js:8:71
  at new Promise (<anonymous>)
  at __awaiter (/home/konstantin/.config/yarn/global/node_modules/neovim/lib/host/NvimPlugin.js:4:12)
  at NvimPlugin.handleRequest (/home/konstantin/.config/yarn/global/node_modules/neovim/lib/host/NvimPlugin.js:134:16)
  at Host.<anonymous> (/home/konstantin/.config/yarn/global/node_modules/neovim/lib/host/index.js:71:27)
  at Generator.next (<anonymous>))

Nodejs blocked after called lines API and build regex from string

Basic info:

After called buffer.lines and then build a regex from string, it could sometimes totally block nodejs and cause 100% CPU usage, without any error thrown

Steps to reproduce:

function run():void {
  let contents = 'abnc fw fewfff ffffffffffffffffe ffffffffef'
  let s = '[\\wÀ-ÿ]{3,}'
  let re = new RegExp(s, 'g')
  logger.debug('regex:' + s)
}

 let buffer = await this.nvim.buffer
 let lines = await buffer.lines
 run()

The process would be blocked at line new RegExp, everything works fine with out buffer.lines.
The issue also depends on the regex string, it would also fail when '-' inside.

It's quite serious, and really took some time to trace.

[idea] Return a promise if callback not supplied.

So we can do

async function main() {
  const windows = await nvim.getWindows()
  console.log(windows)
}

main()

The Promise returned just needs to resolve the value. f.e.

nvim.getWindows = function() {
  return new Promise(function(resolve) {
    let windows = []
    // get Windows from nvim...
    resolve(windows)
  })
}

Where's the rplugin/node directory?

In README it shows that node plugin should be put into the rplugin/node directory, but where's it?
Is it in ~/.local/share/nvim/rplugin/node or ~/config/nvim/rplugin/node?

attach() doesn't work on Windows

I tried the sample code in README but it didn't work. When executing $node sample.js, it finished silently.

While I was investigating this issue with inserting console(), I saw below EPIPE error (but it did not always occur).

Error: write EPIPE
    at exports._errnoException (util.js:856:11)
    at Socket._writeGeneric (net.js:675:26)
    at Socket._write (net.js:694:8)
    at doWrite (_stream_writable.js:292:12)
    at writeOrBuffer (_stream_writable.js:278:5)
    at Socket.Writable.write (_stream_writable.js:207:11)
    at Socket.write (net.js:618:40)
    at Encoder.ondata (C:\Users\xxx\Tmp\node_modules\readable-stream\lib\_stream_readable.js:572:20)
    at emitOne (events.js:77:13)
    at Encoder.emit (events.js:169:7)

I confirmed that spawning nvim process was OK. And requesting vim_get_api_info in attach() never executed its callback.

  • Environment
    • Windows 8.1
    • Neovim nightly (got from AppVeyor result)
    • Node.js 5.4.1

Set default logger transport for neovim/node-client

image

It looks like neovim node client is initialized with default values (debug loglevel / no transport) makes all debug message keep erroring in winston.

  • default loglevel may not need to be debug: maybe worth expose debug config for the extension to launch neovim in the full-debugging mode
  • set default transport : to console? for debug-mode, may write it into file transport instead.

Incorrect type definitions

Hi,

Thanks for the awesome library! However, I'm having a slight problem: some of the type definitions seem to be incorrect. For instance, with this one:

getLine(index: Buffer, cb: number): void;

It seems like the class type (a.k.a. Buffer) got prepended to the arguments list, which put everything one place to the right. Am I correct? If so, is there any chance this could be fixed? It's not a major problem, but I'm currently using the type definitions as a reference, which make finding the right args just a littlebit more difficult.

Neovim npm package not loaded properly

Running :UpdateRemotePlugins gives and error

function remote#host#UpdateRemotePlugins[6]..<SNR>72_RegistrationCommands[15]..remote#
host#Require[10]..provider#node#Require, line 2
Vim(echoerr):Cannot find the "neovim" node package. Try :checkhealth

npm install -g neovim runs fine, but I still get the same error.

Relevant :checkhealth

## Node.js provider (optional)
  - INFO: Node.js: v9.8.0
  - WARNING: Missing "neovim" npm package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Is the npm bin directory in $PATH?

Node.js provider Error with `:checkHealth`

Hi.
I'm using ndenv, and I want to use node-client.
Simply, I installed neovim npm package to global,
then added let g:node_host_prog = expand($NDENV_ROOT . '/shims/neovim-node-host') to init.vim.
However, run :checkHealth, always shows that message.

## Node.js provider (optional)
  - INFO: Node.js: v10.6.0
  - INFO: Neovim node.js host: /Users/yacoolto/Develop/github.com/riywo/anyenv/envs/ndenv/shims/neovim-node-host
  - ERROR: Command error (job=16): `node /Users/yacoolto/Develop/github.com/riywo/anyenv/envs/ndenv/shims/neovim-node-host --version` (in '/Users/yacoolto')
    Output: /Users/yacoolto/Develop/github.com/riywo/anyenv/envs/ndenv/shims/neovim-node-host:3[ -n "$NDENV_DEBUG" ] && set -x     ^^^^^^^^^^^^^^SyntaxError: Unexpected string    at new Script (vm.js:51:7)    at createScript (vm.js:138:10)    at Object.runInThisContext (vm.js:199:10)    at Module._compile (module.js:626:28)    at Object.Module._extensions..js (module.js:673:10)    at Module.load (module.js:575:32)    at tryModuleLoad (module.js:515:12)    at Function.Module._load (module.js:507:3)    at Function.Module.runMain (module.js:703:10)    at startup (bootstrap_node.js:193:16)
  - ERROR: Failed to run: ['node', '/Users/yacoolto/Develop/github.com/riywo/anyenv/envs/ndenv/shims/neovim-node-host', '--version']
    - ADVICE:
      - Report this issue with the output of: 
      - ['node', '/Users/yacoolto/Develop/github.com/riywo/anyenv/envs/ndenv/shims/neovim-node-host', '--version']

Following that ADVICE, I tried node $NDENV_ROOT/shims/neovim-node-host --version, it failed with same error.

$ node $NDENV_ROOT/shims/neovim-node-host --version
/Users/yacoolto/Develop/github.com/riywo/anyenv/envs/ndenv/shims/neovim-node-host:3
[ -n "$NDENV_DEBUG" ] && set -x
     ^^^^^^^^^^^^^^

SyntaxError: Unexpected string
    at new Script (vm.js:51:7)
    at createScript (vm.js:138:10)
    at Object.runInThisContext (vm.js:199:10)
    at Module._compile (module.js:626:28)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)

In contrast, $NDENV_ROOT/shims/neovim-node-host --version shows 4.2.1 without errors.
That's why? Is there anything wrong?

Is there documentation for the `nvim` API?

I assume the nvim argument passed to the example callback in the README is a wrapper around a lower-level NeoVim API. Where can I find documentation for that API? I'd like to get in on the ground floor with this thing and start helping improve it if I can :). What resources do you think I should grok first before I would know enough to start contributing to this driver?

Nice work btw :D

Get `undefined` error in nvim.log_node_rplugin

2018-05-01T17:16:07.241Z - error: Error in plugin for command:"PlugCheck": undefined (file: /Users/chemzqm/vim-dev/plug.nvim, stack: undefined)

There's error thrown in my code, that I didn't catch in promise, looks like node-client failed to find the error object.
Another issue is the file file: /Users/chemzqm/vim-dev/plug.nvim is the folder of plugin, not the file that throw error.

The constructor method of decorated class could be called from time to time

Something like:

export default class CompletePlugin {
  public nvim: Neovim

  constructor(nvim: Neovim) {
    this.nvim = nvim
    logger.debug('called')
  }

This behavior could cause issue when you assign other object to this and change that object later, since when the constructor is called, the old plugin instance is gone and you got a fresh one.
It that intended or a bug?

Reduce complexity of the plugin API

I think API should be vanilla NodeJS friendly. Babel and friends don't help developers at this point and using legacy decorators and other early features shouldn't be recommended. Please keep the API simple.

I could write the plugins like this now without Babel configurations but decorators looks bad to be honest.

const { Plugin, Command } = require('neovim')

class TestPlugin {
	splitV() {
		this.nvim.command('vsplit')
	}
}

Command('Vsplit')(TestPlugin.prototype.splitV)

module.exports = Plugin({ dev: true })(TestPlugin)

Where does the code run

There is sample code in the README, but it is just code. Where do you place it? I'm pretty sure it goes in a file somewhere in the rplugin directory, but is there a specific subdirectory it goes in for Node like what you do with Python? How does Neovim activate Node? Looking at the sample code, it seems to be the other way around, like the plugin starts Neovim, is that right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.