-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathneopyter-api.txt
325 lines (221 loc) · 9.96 KB
/
neopyter-api.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
==============================================================================
Neopyter module: Jupyterlab *neopyter-jupyterlab-api*
Neopyter provide a global `jupyterlab` represent remote `JupyterLab` instance,
which provides some RPC-based API to control remote `JupyterLab` instance. You
could obtain `neopyter.Notebook` instance to control notebook via `JupyterLab`
Example: >lua
require("neopyter.async").run(function()
-- async context
local lab = require("neopyter.jupyter")
local notebook = lab:get_notebook(0) -- Get notebook via buffer
notebook:scroll_to_item(0) -- Scroll to first cell
end)
<
NOTICE: Most API is need a async context, but neopyter provide a wrapped async
context automatically
*neopyter.JupyterOption*
Fields: ~
• {auto_activate_file}? (`boolean`)
• {scroll}? (`{enable?: boolean, align?: neopyter.ScrollToAlign}`)
JupyterLab:attach() *JupyterLab:attach()*
attach autocmd
JupyterLab:connect({address}) *JupyterLab:connect()*
connect server
Parameters: ~
• {address} (`string?`) address of neopyter server
JupyterLab:current_ipynb() *JupyterLab:current_ipynb()*
get current notebook of jupyter lab
Return: ~
(`string`)
JupyterLab:detach() *JupyterLab:detach()*
detach jupyterlab, delete autocmd and disconnect with jupyterlab
JupyterLab:disconnect() *JupyterLab:disconnect()*
disconnect with jupyterlab
JupyterLab:echo({msg}) *JupyterLab:echo()*
test connection will return `hello: {msg}` as response
Parameters: ~
• {msg} (`string`)
Return: ~
(`string?`)
*JupyterLab:execute_command()*
JupyterLab:execute_command({command}, {args})
execute jupyter lab's commands
Parameters: ~
• {command} (`string`)
• {args} (`table<string, any>?`)
Return: ~
(`any`) *View documents*
*JupyterLab:get_jupyterlab_extension_version()*
JupyterLab:get_jupyterlab_extension_version()
get neopyter (jupyterlab extension) version
Return: ~
(`string`)
JupyterLab:get_notebook({buf}) *JupyterLab:get_notebook()*
get notebook via buffer
Parameters: ~
• {buf} (`integer`)
Return: ~
(`neopyter.Notebook?`)
*JupyterLab:get_nvim_plugin_version()*
JupyterLab:get_nvim_plugin_version()
get neopyter (nvim plugin) version
Return: ~
(`string`)
JupyterLab:is_attached() *JupyterLab:is_attached()*
get status of jupyterlab
Return: ~
(`boolean`)
JupyterLab:is_connecting() *JupyterLab:is_connecting()*
whether connecting with `jupyterlab`
Return: ~
(`boolean`)
==============================================================================
Neopyter module: Notebook *neopyter-notebook-api*
Neopyter provide `neopyter.Notebook` represent remote `Notebook` instance,
which provides some RPC-based API to control remote `Notebook` instance.
Obtain notebook refer to `neopyter-jupyterlab-api`
Notebook:activate() *Notebook:activate()*
active notebook in jupyterlab @async
Notebook:activate_cell() *Notebook:activate_cell()*
active cell
Notebook:attach() *Notebook:attach()*
attach autocmd. While connecting with jupyterlab, will full sync
Notebook:complete({options}) *Notebook:complete()*
code completion
Parameters: ~
• {options} (`neopyter.CompletionParams`)
Return: ~
(`neopyter.CompletionItem[]`)
Notebook:detach() *Notebook:detach()*
detach autocmd
Notebook:full_sync() *Notebook:full_sync()*
Notebook:get_cell({row}, {col}) *Notebook:get_cell()*
get cell by pose
Parameters: ~
• {row} (`integer?`)
• {col} (`integer?`)
Notebook:get_cell_num() *Notebook:get_cell_num()*
Notebook:get_cell_source({index}) *Notebook:get_cell_source()*
get cell source code
Parameters: ~
• {index} (`integer`)
Return: ~
(`string?`)
Notebook:get_cursor_cell_pos() *Notebook:get_cursor_cell_pos()*
get current cell of cursor position, start from 1
Return (multiple): ~
(`number`) index of cell
(`number`) row of cursor in cell, 0-based
(`number`) col of cursor in cell, 0-based
Notebook:get_cursor_pos() *Notebook:get_cursor_pos()*
get cursor pos
Return (multiple): ~
(`integer`) 0-index
(`integer`) 0-index
Notebook:get_parser() *Notebook:get_parser()*
Notebook:is_attached() *Notebook:is_attached()*
check attach status
Return: ~
(`boolean`)
Notebook:is_connecting() *Notebook:is_connecting()*
Notebook:is_exist() *Notebook:is_exist()*
is exist corresponding notebook in remote server
Notebook:is_open() *Notebook:is_open()*
whether corresponding `.ipynb` file opened in jupyter lab or not
Return: ~
(`boolean`)
*Notebook:kernel_complete()*
Notebook:kernel_complete({source}, {offset})
code completion, but kernel complete only
Parameters: ~
• {source} (`string`)
• {offset} (`number`)
Return: ~
(`{label: string, type: string, insertText:string, source: string}[]`)
Notebook:open() *Notebook:open()*
Notebook:open_or_reveal() *Notebook:open_or_reveal()*
Notebook:parse() *Notebook:parse()*
*Notebook:partial_sync()*
Notebook:partial_sync({start_row}, {old_end_row}, {new_end_row})
partial sync
Parameters: ~
• {start_row} (`integer`)
• {old_end_row} (`integer`)
• {new_end_row} (`integer`)
Notebook:restart_kernel() *Notebook:restart_kernel()*
Notebook:restart_run_all() *Notebook:restart_run_all()*
Notebook:run_all() *Notebook:run_all()*
Notebook:run_all_above() *Notebook:run_all_above()*
Notebook:run_all_below() *Notebook:run_all_below()*
Notebook:run_selected_cell() *Notebook:run_selected_cell()*
Notebook:safe_sync() *Notebook:safe_sync()*
Notebook:save() *Notebook:save()*
save ipynb, same as `Ctrl+S` on jupyter lab
Return: ~
(`boolean`)
*Notebook:scroll_to_item()*
Notebook:scroll_to_item({idx}, {align}, {margin})
scroll to item
Parameters: ~
• {idx} (`number`)
• {align} (`neopyter.ScrollToAlign?`)
• {margin} (`number?`)
Return: ~
(`unknown?`)
Notebook:set_cursor_pos({pos}) *Notebook:set_cursor_pos()*
Parameters: ~
• {pos} (`integer[]`) (row, col) tuple representing the new position
Notebook:set_mode({mode}) *Notebook:set_mode()*
set notebook mode
Parameters: ~
• {mode} (`"command"|"edit"`)
==============================================================================
Neopyter module: Treesitter *neopyter-treesitter-api*
Neopyter don't depend on `nvim-treesitter`, this module provides some utility
related to `treesitter`, such as capture and match.
Example: >lua
local ts = require("neopyter.treesitter")
ts.get_buf_lang(0)
<
get_buf_lang() *neopyter-treesitter-get_buf_lang*
*neopyter-treesitter-include_whitespace*
include_whitespace({bufnr}, {textobject}, {selection_mode})
include surrounding whitespace
Parameters: ~
• {bufnr} (`number`)
• {textobject} (`number[]`) (start_row, start_col, end_row,
end_col) tuple for textobject position,
TSNode:range() like
• {selection_mode} (`'linewise'|'charwise'`)
Return: ~
(`table`)
*neopyter-treesitter-iter_captures*
iter_captures({query}, {source}, {capture}, {start}, {stop}, {loop})
get captures
Parameters: ~
• {query} (`vim.treesitter.Query`)
• {source} (`vim.treesitter.LanguageTree|number|string|(string[])`)
• {capture} (`string`)
• {start} (`integer?`)
• {stop} (`integer?`)
• {loop} (`boolean?`)
Return: ~
(`Iter`)
*neopyter-treesitter-iter_matches*
iter_matches({query}, {source}, {start}, {stop}, {loop})
get captures
Parameters: ~
• {query} (`vim.treesitter.Query`)
• {source} (`vim.treesitter.LanguageTree|number|string|(string[])`)
• {start} (`integer?`)
• {stop} (`integer?`)
• {loop} (`boolean?`)
Return: ~
(`Iter`)
load_query({query}, {lang}, {name}) *neopyter-treesitter-load_query*
load query to RTP
Parameters: ~
• {query} (`string`)
• {lang} (`string?`) language (default python)
• {name} (`string?`) the prefix name
vim:tw=78:ts=8:sw=4:sts=4:et:ft=help:norl: