You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-56Lines changed: 70 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,19 @@ See below for a quickstart example that you can copy and run immediately.
21
21
22
22
The `neovim` package provides these functions:
23
23
24
-
-`findNvim`: Tries to find a usable `nvim` binary on the current system.
25
-
-`attach`: The primary interface. Takes a process, socket, or pair of write/read streams and returns a `NeovimClient` connected to an `nvim` process.
24
+
-`attach()`: The primary interface. Takes a process, socket, or pair of write/read streams and returns a `NeovimClient` connected to an `nvim` process.
25
+
-`findNvim()`: Tries to find a usable `nvim` binary on the current system.
26
+
27
+
### Logging
28
+
29
+
- At load-time, the `neovim` module replaces ("monkey patches") `console` with its `logger`
30
+
interface, so `console.log` will call `logger.info` instead of writing to stdout (which would
31
+
break the stdio RPC channel).
32
+
- To skip this patching of `console.log`, pass a custom `logger` to `attach()`.
33
+
- Best practice in any case is to use the `logger` available from the `NeovimClient` returned by
34
+
`attach()`, instead of `console` logging functions.
35
+
- Set the `$NVIM_NODE_LOG_FILE` env var to (also) write logs to a file.
36
+
- Set the `$ALLOW_CONSOLE` env var to (also) write logs to stdout.
26
37
27
38
### Quickstart: connect to Nvim
28
39
@@ -34,53 +45,54 @@ Following is a complete, working example.
34
45
```
35
46
2. Paste the script below into a `demo.mjs` file and run it!
36
47
```
37
-
node demo.mjs
48
+
ALLOW_CONSOLE=1 node demo.mjs
38
49
```
39
-
40
-
```js
41
-
import*aschild_processfrom'node:child_process'
42
-
import*asassertfrom'node:assert'
43
-
import { attach, findNvim } from'neovim'
44
-
45
-
// Find `nvim` on the system and open a channel to it.
@@ -94,8 +106,6 @@ The plugin must export a function which takes a `NvimPlugin` object as its only
94
106
**Avoid heavy initialisation or async functions at this stage,** because Nvim may only be collecting information about your plugin without wishing to actually use it.
95
107
Instead, wait for one of your autocmds, commands or functions to be called before starting any processing.
96
108
97
-
The host replaces `console` with a `winston` interface, so `console.log` will call `winston.info`.
98
-
99
109
### Remote plugin examples
100
110
101
111
See [`examples/`](https://github.com/neovim/node-client/tree/master/examples) for remote plugin examples.
@@ -169,7 +179,7 @@ For debugging and configuring logging, you can set the following environment var
169
179
170
180
- `NVIM_NODE_HOST_DEBUG`: Spawns the node process that calls `neovim-client-host` with `--inspect-brk` so you can have a debugger.
171
181
Pair that with this [Node Inspector Manager Chrome plugin](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj?hl=en)
172
-
- Logging: Logging is done using `winston` through the `logger` module. Plugins have `console` replaced with this interface.
182
+
- Logging: Logging is done using `winston` through the `logger` module. This package replaces `console` with this interface.
173
183
- `NVIM_NODE_LOG_LEVEL`: Sets the logging level for winston. Default is `debug`.
174
184
Available levels: `{ error:0, warn:1, info:2, verbose:3, debug:4, silly:5 }`
175
185
- `NVIM_NODE_LOG_FILE`: Sets the log file path.
@@ -190,6 +200,14 @@ For debugging and configuring logging, you can set the following environment var
190
200
191
201
See the tests and [`scripts`](https://github.com/neovim/node-client/tree/master/packages/neovim/scripts) for more examples.
192
202
203
+
## Develop
204
+
205
+
After cloning the repo, run `npm install` to install dev dependencies. The main `neovim` library is in `packages/neovim`.
206
+
207
+
### Run tests
208
+
209
+
npm run build && NVIM_NODE_LOG_FILE=log npm run test
210
+
193
211
## Maintain
194
212
195
213
### Release
@@ -232,11 +250,7 @@ git commit -m 'publish docs'
232
250
git push origin HEAD:gh-pages
233
251
```
234
252
235
-
## Contributing
236
-
237
-
After cloning the repo, run `npm install` to install dev dependencies. The main `neovim` library is in `packages/neovim`.
238
-
239
-
### Contributors
253
+
## Contributors
240
254
241
255
* [@billyvg](https://github.com/billyvg) for rewrite
242
256
* [@mhartington](https://github.com/mhartington) for TypeScript rewrite
0 commit comments