Skip to content

Commit b7cd548

Browse files
committed
docs: add gotchas for float source/suffix mangling a multi-line box
open_float runs `format` first and only then prepends the source and appends the suffix, so both land on a finished box and knock its first or last line off the gutter. Neither is something the plugin can defend against from inside `format`, so document the shape of the fix — including that opts passed directly to open_float override vim.diagnostic.config entirely.
1 parent 45893bb commit b7cd548

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,43 @@ If you want to see the plugin wired up end-to-end (float format, sign icons, spo
259259

260260
<https://github.com/rashedInt32/lazyvim-config>
261261

262+
## Gotchas
263+
264+
The boxes are multi-line, and `vim.diagnostic` was built for one-line messages. Two float options will happily splice text onto a box and knock it off its own gutter — neither is something this plugin can defend against, so they're worth knowing.
265+
266+
**`source = true` shifts the box's first line.** `open_float` runs your `format` function *first* and only *then* prepends the source, so the source lands on line 1 of the finished box and nothing else:
267+
268+
```
269+
ts: ╭─ ⚠ Effect — Unhandled Errors ← pushed right by #"ts: "
270+
│ ← the gutter below it is not
271+
```
272+
273+
Set `source = false` and add it back yourself for the messages that aren't boxed:
274+
275+
```lua
276+
format = function(diagnostic)
277+
local rendered = require("effect-error-pretty").float_format(diagnostic)
278+
if rendered then
279+
return rendered -- a box speaks for itself
280+
end
281+
local src = diagnostic.source and (diagnostic.source .. ": ") or ""
282+
return src .. diagnostic.message
283+
end,
284+
```
285+
286+
**`suffix` lands after the closing `╰─`.** Same cause, other end. Suppress it when the message is already a box — note that by the time `suffix` runs, `format` has replaced `diagnostic.message` with the rendered box, so check that rather than re-running the formatter:
287+
288+
```lua
289+
suffix = function(diagnostic)
290+
if diagnostic.message:sub(1, #"") == "" then
291+
return "", ""
292+
end
293+
return string.format(" [%s]", diagnostic.code or ""), "Comment"
294+
end,
295+
```
296+
297+
**Opts passed to `open_float` beat your config.** If a keymap does `vim.diagnostic.open_float(nil, { source = "always" })`, that wins over `vim.diagnostic.config({ float = { source = false } })` and the prefix comes back — no matter how carefully the global config is set. Worth grepping for if a box looks misaligned even after the above.
298+
262299
## Options
263300

264301
| Option | Default | Description |

0 commit comments

Comments
 (0)