-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathfidget-api.txt
487 lines (318 loc) · 19.3 KB
/
fidget-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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
*fidget-api.txt* For Neovim version 0.8+ Last change: see Git log
==============================================================================
Table of Contents *fidget.api.toc*
Notification subsystem ··································· |fidget.notification|
LSP progress subsystem ······································· |fidget.progress|
Neovim LSP shim layer ···································· |fidget.progress.lsp|
Non-LSP progress messages ····························· |fidget.progress.handle|
Spinner animations ············································ |fidget.spinner|
*fidget.api*
This file contains generated documentation for Fidget's Lua API, though of
course you will also find plenty more detail documented in the source code.
For help setting up this plugin, see |fidget.txt| and |fidget-option.txt|.
fidget.setup({opts}) *fidget.setup*
Set up Fidget plugin.
Parameters: ~
{opts} (table) Plugin options. See |fidget-options| or |fidget-option.txt|.
fidget.notify({msg}, {level}, {opts}) *fidget.notify*
Alias for |fidget.notification.notify|.
Parameters: ~
{msg} (string|nil) Content of the notification to show to the user.
{level} (Level|nil) How to format the notification.
{opts} (Options|nil) Optional parameters (see |fidget.notification.Options|).
==============================================================================
Notification subsystem *fidget.notification*
Key *fidget.notification.Key*
Used to determine the identity of notification items and groups.
Type: ~
any
Level *fidget.notification.Level*
Second (level) parameter passed to |fidget.notification.notify|.
`string` indicates highlight group name; otherwise, `number` indicates
the |vim.log.levels| value (that will resolve to a highlight group as
determined by the |fidget.notification.Config|).
Type: ~
number|string
Options *fidget.notification.Options*
Third (opts) parameter passed to |fidget.notification.notify|.
Fields: ~
{key} (Key|nil) Replace existing notification item of the same key
{group} (Key|nil) Group that this notification item belongs to
{annote} (string|nil) Optional single-line title that accompanies the message
{hidden} (boolean|nil) Whether this item should be shown
{ttl} (number|nil) How long after a notification item should exist; pass 0 to use default value
{update_only} (boolean|nil) If true, don't create new notification items
{skip_history} (boolean|nil) If true, don't include in notifications history
{data} (any|nil) Arbitrary data attached to notification item
Display *fidget.notification.Display*
Something that can be displayed in a |fidget.notification.Group|.
If a callable `function`, it is invoked every render cycle with the items
list; useful for rendering animations and other dynamic content.
Type: ~
string|fun(now:number,items:Item[]):string
Config *fidget.notification.Config*
Used to configure the behavior of notification groups.
If both name and icon are nil, then no group header is rendered.
The `update_hook` function can be used to dynamically adjust fields of
a |fidget.notification.Item|, e.g., to set the `hidden` field according to
the message. If set to `false`, nothing is done when an item is updated.
Note that the actual |fidget.notification.default_config| defines a few
more defaults than what is documented here, which pertain to the fallback
used if the corresponding field in the `default` config table is `nil`.
Fields: ~
{name} (Display|nil) Name of the group
{icon} (Display|nil) Icon of the group
{icon_on_left} (boolean|nil) If `true`, icon is rendered on the left instead of right
{annote_separator} (string|nil) Separator between message from annote; defaults to `" "`
{ttl} (number|nil) How long a notification item should exist; defaults to `5`
{render_limit} (number|nil) How many notification items to show at once
{group_style} (string|nil) Style used to highlight group name; defaults to `"Title"`
{icon_style} (string|nil) Style used to highlight icon; if nil, use `group_style`
{annote_style} (string|nil) Default style used to highlight item annotes; defaults to `"Question"`
{debug_style} (string|nil) Style used to highlight debug item annotes
{info_style} (string|nil) Style used to highlight info item annotes
{warn_style} (string|nil) Style used to highlight warn item annotes
{error_style} (string|nil) Style used to highlight error item annotes
{debug_annote} (string|nil) Default annotation for debug items
{info_annote} (string|nil) Default annotation for info items
{warn_annote} (string|nil) Default annotation for warn items
{error_annote} (string|nil) Default annotation for error items
{priority} (number|nil) Order in which group should be displayed; defaults to `50`
{skip_history} (boolean|nil) Whether messages should be preserved in history
{update_hook} (fun(item:Item)|false|nil) Called when an item is updated; defaults to `false`
Item *fidget.notification.Item*
Notification element containing a message and optional annotation.
Fields: ~
{key} (Key) Identity of this item (for in-place updates)
{content_key} (Key) What to deduplicate items by (do not deduplicate if `nil`)
{message} (string) Displayed message for the item
{annote} (string|nil) Optional title that accompanies the message
{style} (string) Style used to render the annote/title, if any
{hidden} (boolean) Whether this item should be shown
{expires_at} (number) What time this item should be removed; math.huge means never
{last_updated} (number) What time this item was last updated
{skip_history} (boolean) Whether this item should be included in history
{data} (any|nil) Arbitrary data attached to notification item
HistoryItem : Item *fidget.notification.HistoryItem*
A notification element in the notifications history.
Fields: ~
{removed} (boolean) Whether this item is deleted
{group_key} (Key) Key of the group this item belongs to
{group_name} (string|nil) Title of the group this item belongs to
{group_icon} (string|nil) Icon of the group this item belongs to
{last_updated} (number) What time this item was last updated, in seconds since Jan 1, 1970
HistoryFilter *fidget.notification.HistoryFilter*
Filter options when querying for notifications history.
Note that filters are conjunctive; all specified predicates need to be true.
Fields: ~
{group_key} (Key|nil) Items from this group
{before} (number|nil) Only items last updated at least this long ago
{since} (number|nil) Only items last updated at most this long ago
{include_removed} (boolean|nil) Include items that have been removed (default: true)
{include_active} (boolean|nil) Include items that have not been removed (default: true)
notification.default_config *fidget.notification.default_config*
Default notification configuration.
Exposed publicly because it might be useful for users to integrate for when
they are adding their own configs.
To see the default values, run:
>vim
:lua print(vim.inspect(require("fidget.notification").default_config))
<
Note that the default `update_hook` function performs a few book-keeping
tasks, e.g., calling |fidget.notification.set_content_key| to keep its
`content_key` up to date. You may want to do the same if writing your own;
check the source code to see what it's doing.
See also:~
|fidget.notification.Config|
Type: ~
(Config)
notification.set_content_key({item}) *fidget.notification.set_content_key*
Sets a |fidget.notification.Item|'s `content_key`, for deduplication.
This default implementation sets an item's `content_key` to its `message`,
appended with its `annote` (or a null byte if it has no `annote`), a rough
"hash" of its contents. You can write your own `update_hook` that "hashes"
the message differently, e.g., only considering the `message`, or taking the
`data` or style fields into account.
If you would like to disable message deduplication, don't call this
function, leaving the `content_key` field as `nil`. Assuming you're not
using the `update_hook` for anything else, you can achieve this by simply
the option to `false`, e.g.:
>lua
{ -- In options table
notification = {
configs = {
-- Opt out of deduplication by default, i.e., in default config
default = vim.tbl_extend("force", require('fidget.notification').default_config, {
update_hook = false,
},
},
},
}
<
Parameters: ~
{item} (Item)
*fidget.notification.notify*
notification.notify({msg}, {level}, {opts})
Send a notification to the Fidget notifications subsystem.
Can be used to override `vim.notify()`, e.g.,
>lua
vim.notify = require("fidget.notification").notify
<
Parameters: ~
{msg} (string|nil) Content of the notification to show to the user.
{level} (Level|nil) How to format the notification.
{opts} (Options|nil) Optional parameters (see |fidget.notification.Options|).
notification.close() *fidget.notification.close*
Close the notification window.
Note that it the window will pop open again as soon as there is any reason
to (e.g., if another notification or LSP progress message is received).
To temporarily stop the window from opening, see |fidget.notification.suppress|.
Returns: ~
(boolean) Whether the window closed successfully.
notification.clear({group_key}) *fidget.notification.clear*
Clear active notifications.
If the given `group_key` is `nil`, then all groups are cleared. Otherwise,
only that notification group is cleared.
Parameters: ~
{group_key} (Key|nil) Which group to clear
notification.clear_history({filter}) *fidget.notification.clear_history*
Clear notifications history, according to the specified filter.
Parameters: ~
{filter} (HistoryFilter|Key|nil) What to clear
notification.reset() *fidget.notification.reset*
Reset notification subsystem state.
Note that this function does not set any Fidget notification window state,
in particular, the `x_offset`.
*fidget.notification.set_config*
notification.set_config({key}, {config}, {overwrite})
Dynamically add, overwrite, or delete a notification configuration.
Inherits missing keys from the default config.
Parameters: ~
{key} (Key) Which config to set.
{config} (Config|nil) What to set as config.
{overwrite} (boolean) Whether to overwrite existing config, if any.
See: ~
|fidget.notification.Config|
notification.suppress({suppress}) *fidget.notification.suppress*
Suppress whether the notification window is shown.
Pass `true` as argument to turn on suppression, or `false` to turn it off.
If no argument is given, suppression state is toggled.
Parameters: ~
{suppress} (boolean|nil) Whether to suppress or toggle suppression
*fidget.notification.remove*
notification.remove({group_key}, {item_key})
Remove an item from a particular group.
Parameters: ~
{group_key} (Key)
{item_key} (Key)
Returns: ~
(boolean) successfully_removed
notification.get_history({filter}) *fidget.notification.get_history*
Query notifications history, according to an optional filter.
Note that this function may return more than |fidget.options.history_size|
items, since it will also include current notifications, unless
`filter.include_active` is set to `false`.
Parameters: ~
{filter} (HistoryFilter|Key|nil) options or group_key for filtering history
Returns: ~
(HistoryItem[]) history
notification.show_history({filter}) *fidget.notification.show_history*
Show the notifications history in the |nvim_echo()| buffer.
Parameters: ~
{filter} (HistoryFilter|Key|nil) options or group_key for filtering history
notification.group_keys() *fidget.notification.group_keys*
Get list of active notification group keys.
Returns: ~
(Key[]) keys
==============================================================================
LSP progress subsystem *fidget.progress*
progress.poll() *fidget.progress.poll*
Poll for progress messages once.
Potentially useful if you're planning on "driving" Fidget yourself.
progress.suppress({suppress}) *fidget.progress.suppress*
Suppress consumption of progress messages.
Pass `false` as argument to turn off suppression.
If no argument is given, suppression state is toggled.
Parameters: ~
{suppress} (boolean|nil) Whether to suppress or toggle suppression
==============================================================================
Neovim LSP shim layer *fidget.progress.lsp*
ProgressMessage *fidget.progress.lsp.ProgressMessage*
Fields: ~
{token} (Key) Unique identifier used to accumulate updates
{title} (string|nil) Name of the task in progress
{message} (string|nil) Message describing the progress
{percentage} (number|nil) How much of the progress is complete (out of 100)
{done} (boolean) Whether this progress completed; ignore `percentage` if `done` is `true`
{cancellable} (boolean) Whether this task can be canceled (though doing so is unsupported with Fidget)
{lsp_client} (table) LSP client table this message came from
M.poll_for_messages() *fidget.progress.lsp.poll_for_messages*
Consumes LSP progress messages from each client.progress ring buffer.
Based on vim.lsp.status(), except this implementation does not format the
reports into strings.
Returns: ~
(ProgressMessage[]) progress_messages
See: ~
|fidget.progress.lsp.ProgressMessage|
==============================================================================
Non-LSP progress messages *fidget.progress.handle*
ProgressHandle : ProgressMessage *fidget.progress.handle.ProgressHandle*
A handle for a progress message, reactive to changes
Fields: ~
{cancel} (fun(self:ProgressHandle)) Cancel the task
{finish} (fun(self:ProgressHandle)) Mark the task as complete
{report} (fun(self:ProgressHandle,msg:ProgressMessage|table<string,any>)) Update one or more properties of the progress message
handle.create({message}) *fidget.progress.handle.create*
Create a new progress message, and return a handle to it for updating.
The handle is a reactive object, so you can update its properties and the
message will be updated accordingly. You can also use the `report` method to
update multiple properties at once.
Example:
>lua
local progress = require("fidget.progress")
local handle = progress.handle.create({
title = "My Task",
message = "Doing something...",
lsp_client = { name = "my_fake_lsp" },
percentage = 0,
})
-- You can update properties directly and the
-- progress message will be updated accordingly
handle.message = "Doing something else..."
-- Or you can use the `report` method to bulk-update
-- properties.
handle:report({
title = "The task status changed"
message = "Doing another thing...",
percentage = 50,
})
-- You can also cancel the task (errors if not cancellable)
handle:cancel()
-- Or mark it as complete (updates percentage to 100 automatically)
handle:finish()
<
Parameters: ~
{message} (ProgressMessage|table<string,any>) The initial progress message
Returns: ~
(ProgressHandle) @nodiscard
==============================================================================
Spinner animations *fidget.spinner*
Manga *fidget.spinner.Manga*
A Manga is a table specifying an Anime to generate.
The period is specified in seconds; if omitted, it defaults to 1.
Type: ~
{pattern:string[]|string,period:number|nil}|
Anime *fidget.spinner.Anime*
An Anime is a function that takes a timestamp and renders a frame (string).
Note that Anime is a subtype of Display.
Type: ~
fun(now:number):string
spinner.animate({pattern}, {period}) *fidget.spinner.animate*
Generate an Anime function that can be polled for spinner animation frames.
The period is specified in seconds; if omitted, it defaults to 1.
Parameters: ~
{pattern} (string[]|string) Either an array of frames, or the name of a known pattern
{period} (number|nil) How long one cycle of the animation should take, in seconds
Returns: ~
(Anime) Call this function to compute the frame at some timestamp
vim:tw=78:ts=8:noet:ft=help:norl: