Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add more filter examples #509

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion docs/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

A simple filter is a table whose keys are item attributes.
The following filter keeps items with attribute `buf = 0` **and** `ft = 'lua'`,
i.e., diagnostics with severity error to the current buffer when its filetype is `lua`.
i.e., diagnostics from the current buffer with filetype `lua`.

```lua
{
Expand Down Expand Up @@ -79,6 +79,30 @@ The following filter **keeps** diagnostics for the current buffer **or** diagnos
}
```

### Cascading diagnostics

The following filter **keeps** the most severe diagnostics.
Once those diagnostics are resolved,
less severe entries are shown.

```lua
{
modes = {
my_diagnostics = {
mode = 'diagnostics',
filter = function(items)
local severity = vim.iter(items):fold(
vim.diagnostic.severity.HINT,
function(r, v) return math.min(r, v.severity) end)
return vim.tbl_filter(
function(item) return item.severity == severity end,
items)
end,
},
},
}
```

## Item attributes

Item attributes are documented in `lua/trouble/item.lua`
Expand Down
Loading