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
You can do the similar for your statusline plugin of choice as long as you "refresh" it on `GuardFmt`.
54
-
55
-
## Writing advanced formatting logic
56
-
57
-
Guard exposes an api for writing advanced formatting logic:
58
-
59
-
```lua
60
-
require("guard.api").fmt_with({
61
-
cmd-- string: tool command
62
-
args-- table: command arugments
63
-
fname-- boolean: insert filename to args tail
64
-
stdin-- boolean: pass buffer contents into stdin
65
-
timeout-- integer
66
-
env-- table: environment variables passed to cmd (key value pair)
67
-
68
-
fn-- function: if fn is set other fields will not take effect
69
-
}, {
70
-
buf-- integer: buffer number
71
-
range-- table: {integer, integer} for range formatting
72
-
})
73
-
-- returns:
74
-
{
75
-
result-- table: list of formatted lines
76
-
stderr-- table: stderr output
77
-
exit_code-- integer: exit code
78
-
}
79
-
```
80
-
81
-
Note that fmt_with does not apply the format for you, YOU would have to apply it:
82
-
83
-
```lua
84
-
-- ...logic for checking exit code and stderr...
85
-
require("guard.api").apply_fmt({
86
-
bufnr, -- integer: buffer number
87
-
prev_lines, -- table: previous text
88
-
new_lines, -- table: format result
89
-
srow, -- integer: start row
90
-
erow, -- integer: end row
91
-
})
92
-
```
93
-
94
-
A bit of explanation: `prev_lines` if for using `vim.diff` to apply the minimal amount of changes to the buffer, if you choose to not pass this for some reason, you have to provide `erow` so that guard knows precisely what to replace.
95
-
96
-
Btw, you can get `prev_lines` using `require("guard.util").get_lines`
0 commit comments