neovim/node-host

Help getting simple plugin working

gblock0 opened this issue · 14 comments

I'm new to developing neovim plugins and I'm trying get a simple node plugin working, but when I run :UpdateRemotePlugins it throws this error:

Plugin error

Here is my plugin:

/* globals plugin, debug */
'use strict';

debug('In plugin');
var fmt = require('util').format,
    numCalls = 0;

function incrementCalls() {
    if ( numCalls === 5 ) {
        debug('too many calls');
    }
    numCalls++;
}

plugin.command('testCmd', {
    range: '',   // Line 16
    nargs: '*'
}, function (nvim, args, range) {
    debug('in testCmd');
    incrementCalls();
    nvim.commandOutput( fmt('Test cmd press: ', numCalls, ' times. ', range) );
});

You can find the rest of the project at neovim-autoformat.

I try to run :testCmd in nvim and it gives me the E492: Not an editor command: testCmd error.

Eventually I would like to have this run a shell command when a nvim : command is sent, but this plugin doesn't seem like it's even getting loaded properly.

nvim version:

NVIM 0.1.0 (compiled Nov  1 2015 16:15:29)
Commit: v0.1.0
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim20151101-33169-32i8gt/build/config -I/tmp/neovim20151101-33169-32i8gt/src -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include/luajit-2.0 -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include -I/tmp/neovim20151101-33169-32i8gt/deps-build/usr/include -I/usr/local/opt/gettext/include -I/usr/include -I/tmp/neovim20151101-33169-32i8gt/build/src/nvim/auto -I/tmp/neovim20151101-33169-32i8gt/build/include
Compiled by gregoryblock@Geebs

Optional features included (+) or not (-): +acl   +iconv    +jemalloc
For differences from Vim, see :help vim-differences

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

Nothing in the $NEOVIM_JS_DEBUG file and just this in my ~/.nvimlog:

2015/08/16 10:35:09 [info @ main_loop:558] 71322 - Starting Neovim main loop.
2015/08/16 10:35:21 [info @ main_loop:558] 71366 - Starting Neovim main loop.
2015/08/16 10:43:44 [info @ main_loop:558] 72402 - Starting Neovim main loop.
2015/08/16 10:44:04 [info @ main_loop:558] 72557 - Starting Neovim main loop.
2015/08/16 10:45:45 [info @ main_loop:558] 72910 - Starting Neovim main loop.
2015/08/16 10:46:07 [info @ main_loop:558] 74787 - Starting Neovim main loop.
2015/08/16 10:50:47 [info @ main_loop:558] 76445 - Starting Neovim main loop.
2015/08/16 10:51:03 [info @ main_loop:558] 78304 - Starting Neovim main loop.
2015/10/31 17:46:19 [info @ main_loop:558] 20212 - Starting Neovim main loop.
2015/10/31 17:46:37 [info @ main_loop:558] 20334 - Starting Neovim main loop.
2015/10/31 17:46:42 [info @ main_loop:558] 20415 - Starting Neovim main loop.
2015/10/31 17:46:50 [info @ main_loop:558] 20476 - Starting Neovim main loop.
2015/10/31 17:48:28 [info @ main_loop:558] 20883 - Starting Neovim main loop.
2015/10/31 17:49:28 [info @ main_loop:558] 21111 - Starting Neovim main loop.
2015/10/31 17:52:51 [info @ main_loop:558] 21906 - Starting Neovim main loop.
2015/10/31 17:54:20 [info @ main_loop:558] 22553 - Starting Neovim main loop.
2015/10/31 17:54:55 [info @ main_loop:558] 22786 - Starting Neovim main loop.
2015/11/01 13:41:43 [info @ main_loop:558] 89297 - Starting Neovim main loop.
2015/11/01 13:44:25 [info @ main_loop:558] 89749 - Starting Neovim main loop.

Any help would be greatly appreciated! Thanks!

Once I get back developing the infrastructure for remote plugins, I will look for a plan to removing the requirement for running :UpdateRemotePlugins, make things a little bit more automatic.

@tarruda Sounds great!

While you are working on that, is there any advice you can give to help me get this working?

@gblock0 The message suggests that the connection was closed due to an error, which I guess is caused by the lowercase command your plugin defines(vim/nvim only accept uppercase names for user-defined commands and functions).

@gblock0 did changing the command name to uppercase solve your issue?

No it did not.

I think that the problem is that you want commandOutput to send nvim the output of TestCmd, but what it actually does is asks nvim to execute a command (e.g. w) and return the output (e.g. "main.js" 25L, 507C written).

If you want to display an output message, try using nvim.commandOutput('echo "output!"')!

I changed it to:

plugin.command('TestCmd', {
    range: '',   // Line 16
    nargs: '*'
}, function (nvim) {
    nvim.commandOutput( 'w' );
});

but I am still getting the same error.

Weird. Your plugin works perfectly on my end. Perhaps you could try updating to the most recent version of Neovim? Otherwise, could you please paste the contents of .init.vim-rplugin~ (or ~/..nvim-rplugin~ if you haven't updated recently) after running :UpdateRemotePlugins?

I just updated Neovim with homebrew and it seems to be the same version. Where would the init.vim-rplugin~ file be? I don't see it in my home directory and I can't find it in the neovim homebrew folder.

Try taking a look in ~/.config/nvim!

I had checked there but forgot to add -a to the command...derp. Here is the output:

" node plugins


" python3 plugins
call remote#host#RegisterPlugin('python3', '/Users/gregoryblock/.config/nvim/plugged/vim-markdown-composer/rplugin/python3/markdown_composer.py', [
      \ {'sync': 0, 'name': 'ComposerOpen', 'type': 'command', 'opts': {}},
      \ {'sync': 0, 'name': 'ComposerPort', 'type': 'command', 'opts': {}},
      \ {'sync': 0, 'name': 'ComposerStart', 'type': 'command', 'opts': {}},
      \ {'sync': 0, 'name': 'CursorHold,CursorHoldI,CursorMoved,CursorMovedI', 'type': 'autocmd', 'opts': {'pattern': '*.md,*.mkd,*.markdown'}},
      \ {'sync': 1, 'name': 'ComposerUpdate', 'type': 'command', 'opts': {}},
      \ {'sync': 1, 'name': 'FileType', 'type': 'autocmd', 'opts': {'pattern': 'markdown'}},
     \ ])


" python plugins

Okay, my questions then are 1) whether you've installed this repo as a plugin and 2) whether you've done npm install inside of it.

  1. I am using vim-plug and this is the line in my init.vim for this plugin Plug '~/neovim-autoformat'. I have tried running :PlugInstall and then :UpdateRemotePlugins. Doesn't me getting remote/host: node host registered plugins ['main.js'] mean the plugin is trying to install?

  2. I was not aware that I was supposed to run npm install inside the plugin. Does my plugin need to be aware of node-host even though Neovim is? Currently I do not have a package.json insde my plugin.

I did run npm install in the node-host plugin folder when I first installed it.

The path to my plugins is: ~/.config/nvim/plugged, not sure if that matters. Maybe I'm not installing the plugin correctly with vim-plug?

I just changed it to look at my repo, installed it the normal way, and I am still getting the error on :UpdateRemotePlugins