Skip to content
This repository was archived by the owner on Nov 12, 2017. It is now read-only.

Commit c41099f

Browse files
authoredJul 24, 2017
Merge pull request #27 from neovim/next
Breaking update
2 parents 0c116cb + 7ad9728 commit c41099f

23 files changed

+590
-769
lines changed
 

‎.jscsrc

-78
This file was deleted.

‎.jshintrc

-18
This file was deleted.

‎.travis.yml

-9
This file was deleted.

‎README.md

+14-81
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,26 @@
22
We will be introducing breaking changes in the near future. See the [new node-host](https://github.com/neovim/node-host/tree/next) and [new node-client](https://github.com/neovim/node-client/tree/next) for more information about the changes
33

44
# node-host
5-
6-
[![Build Status](https://travis-ci.org/neovim/node-host.png)](https://travis-ci.org/neovim/node-host)
7-
<br>
8-
95
## Installation
106

11-
**Prerequisites:** You must have the `node` executable on your PATH and a copy of `npm`
12-
13-
1. Install this plugin using Vundle or your favorite plugin manager
14-
2. Navigate to the `node-host` directory (e.g. `~/.nvim/bundle/node-host`) and run `npm install`
15-
16-
## Usage
17-
18-
To use a Node plugin, place the appropriate file or folder in `rplugin/node` in a `runtimepath` directory (e.g. `~/.nvim/rplugin/node`), run `npm install` if necessary, and then execute a `:UpdateRemotePlugins`.
19-
Once you restart Neovim, you will be able to use your new plugins!
20-
21-
### Example
22-
23-
```javascript
24-
var fmt = require('util').format,
25-
numCalls = 0
26-
27-
function incrementCalls() {
28-
if ( numCalls == 5 ) {
29-
throw new Error('Too many calls!')
30-
}
31-
numCalls++
32-
}
7+
**Prerequisites:** You must have the `node` executable (currently only 7.x is supported) on your PATH and a copy of `npm`
338

34-
plugin.commandSync('Cmd', {
35-
range: '',
36-
nargs: '*',
37-
}, function( nvim, args, range, cb ) {
38-
try {
39-
incrementCalls()
40-
nvim.setCurrentLine(
41-
fmt('Command: Called', numCalls, 'times, args:', args, 'range:', range),
42-
cb )
43-
} catch ( err ) {
44-
cb( err )
45-
}
46-
})
9+
1. Install this plugin using `vim-plug` or your favorite plugin manager
10+
2. Install `neovim` package globally: `npm install -g neovim@next`
4711

48-
plugin.autocmdSync('BufEnter', {
49-
pattern: '*.js',
50-
eval: 'expand("<afile>")'
51-
}, function( nvim, filename, cb ) {
52-
try {
53-
incrementCalls()
54-
nvim.setCurrentLine(
55-
fmt('Autocmd: Called', numCalls, 'times, file:', filename), cb )
56-
} catch ( err ) {
57-
cb( err )
58-
}
59-
})
60-
61-
plugin.function('Func', function( nvim, args ) {
62-
try {
63-
incrementCalls()
64-
nvim.setCurrentLine( fmt('Function: Called', numCalls, 'times, args:', args) )
65-
} catch ( err ) {}
66-
})
12+
### Example config (vim-plug)
13+
```vim
14+
call plug#begin()
15+
Plug 'neovim/node-host', { 'branch': 'next', 'do': 'npm install -g neovim@next' }
16+
call plug#end()
6717
```
6818

69-
### Writing plugins
70-
71-
A plugin can either be a file or folder with the `*.js` extension in the `rplugin/node` directory.
72-
If the plugin is a folder, the package "main" script will be loaded.
73-
74-
The following functions, available on the global `plugin` object, can be used to register plugin commands/functions/autocmds on the attached Neovim instance.
75-
76-
#### (command|function|autocmd)\[Sync](name, [opts], callback)
77-
78-
If the `Sync` variant is used, Neovim will wait for the plugin to return a response via the errback passed as the final argument to the plugin function.
79-
Otherwise, Neovim will continue execution immediately, ignoring any return values or errors.
80-
81-
`name` is the name of the plugin, `opts` is an optional hash of options, and `callback` is a function that is called whenever the command, function, or autocmd, is triggered.
82-
83-
Note: since `require` caches modules, to see your changes, you will need to restart the host by restarting Neovim.
84-
85-
#### Debugging
19+
## Usage
20+
To use a Node plugin, place the appropriate file or folder in `rplugin/node` in a `runtimepath` directory (e.g. `~/.nvim/rplugin/node`), run `npm install` if necessary, and then execute a `:UpdateRemotePlugins`.
8621

87-
Also available in the global scope is the `debug` function, which can be used like `console.log` and writes to the file given by the `$NEOVIM_JS_DEBUG` environment variable.
88-
If you suspect that errors may be occurring in or propagating up to the host, itself, further error output can be found in `.nvimlog`.
22+
You *must* restart neovim after a `:UpdateRemotePlugins` before you can use your new plugin.
8923

90-
## TODO
24+
## Writing plugins
25+
A plugin can either be a file or folder in the `rplugin/node` directory. If the plugin is a folder, the `main` script from `package.json` will be loaded.
9126

92-
* Auto-install Node executable if missing
93-
* Plugin manager that allows post-install hooks for `npm install`
94-
* Better isolation of global variables
27+
Please see the [neovim repository](https://github.com/billyvg/node-client) for documentation on how to write a plugin (API is currently a WIP)

‎autoload/health/node.vim

+485
Large diffs are not rendered by default.

‎autoload/js_host.vim

-15
This file was deleted.

‎autoload/provider/node.vim

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
if exists('g:loaded_node_provider')
3+
finish
4+
endif
5+
let g:loaded_node_provider = 1
6+
7+
let s:stderr = {}
8+
let s:job_opts = {'rpc': v:true}
9+
10+
function! s:job_opts.on_stderr(chan_id, data, event)
11+
let stderr = get(s:stderr, a:chan_id, [''])
12+
let last = remove(stderr, -1)
13+
let a:data[0] = last.a:data[0]
14+
call extend(stderr, a:data)
15+
let s:stderr[a:chan_id] = stderr
16+
endfunction
17+
18+
function! provider#node#Detect() abort
19+
return exepath('neovim-node-host')
20+
endfunction
21+
22+
function! provider#node#Prog()
23+
return s:prog
24+
endfunction
25+
26+
function! provider#node#Require(host) abort
27+
if s:err != ''
28+
echoerr s:err
29+
return
30+
endif
31+
32+
let args = ['node']
33+
34+
if !empty($NVIM_NODE_HOST_DEBUG)
35+
call add(args, '--inspect-brk')
36+
endif
37+
38+
call add(args , provider#node#Prog())
39+
40+
" let node_plugins = remote#host#PluginsForHost(a:host.name)
41+
42+
" for plugin in node_plugins
43+
" call add(args, plugin.path)
44+
" endfor
45+
46+
try
47+
let channel_id = jobstart(args, s:job_opts)
48+
if rpcrequest(channel_id, 'poll') ==# 'ok'
49+
return channel_id
50+
endif
51+
catch
52+
echomsg v:throwpoint
53+
echomsg v:exception
54+
for row in get(s:stderr, channel_id, [])
55+
echomsg row
56+
endfor
57+
endtry
58+
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_NODE_LOG_FILE')
59+
endfunction
60+
61+
function! provider#node#Call(method, args)
62+
if s:err != ''
63+
echoerr s:err
64+
return
65+
endif
66+
67+
if !exists('s:host')
68+
try
69+
let s:host = remote#host#Require('node')
70+
catch
71+
let s:err = v:exception
72+
echohl WarningMsg
73+
echomsg v:exception
74+
echohl None
75+
return
76+
endtry
77+
endif
78+
return call('rpcrequest', insert(insert(a:args, 'node_'.a:method), s:host))
79+
endfunction
80+
81+
82+
let s:err = ''
83+
let s:prog = provider#node#Detect()
84+
85+
if empty(s:prog)
86+
let s:err = 'Cannot find the neovim-client node package. Try :CheckHealth'
87+
endif
88+
89+
" call remote#host#RegisterClone('legacy-node-provider', 'node')
90+
call remote#host#RegisterPlugin('node-provider', 'node', [])

‎examples/README.md

-12
This file was deleted.

‎examples/demo_beautify_css.js/index.js

-12
This file was deleted.

‎examples/demo_beautify_css.js/package.json

-15
This file was deleted.

‎examples/demo_beautify_css.js/ugly.css

-1
This file was deleted.

‎gulpfile.js

-45
This file was deleted.

‎index.js

-91
This file was deleted.

‎lib/devnull.js

-14
This file was deleted.

‎lib/plugin.js

-145
This file was deleted.

‎package.json

-43
This file was deleted.

‎plugin/js_host.vim

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
let g:node_host_dir = expand('<sfile>:p:h:h')
2-
call remote#host#Register('node', '*.js', function('js_host#RequireJSHost'))
1+
call remote#host#Register('node', '*', function('provider#node#Require'))

‎test/.jshintrc

-25
This file was deleted.

‎test/rplugin/node/test.js/index.js

-27
This file was deleted.

‎test/rplugin/node/test.js/package.json

-11
This file was deleted.

‎test/test_devnull.js

-10
This file was deleted.

‎test/test_integration.js

-66
This file was deleted.

‎test/test_plugin.js

-49
This file was deleted.

0 commit comments

Comments
 (0)
This repository has been archived.