Skip to content

Commit

Permalink
document select.
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 committed Sep 17, 2023
1 parent 20287de commit e232c3e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,20 @@ The first argument has to be a table, which defines at least `trig` and
* `match_captures`, `string|string[]`: The capture(s) to use for determining
the actual prefix (so the node that should be immediately in front of the
trigger). This defaults to just `"prefix"`.
* `select`, `string?|fun(): LuaSnip.extra.MatchSelector`: Since there may be
multiple matching captures in front of the cursor, there has to be some
way to select the node that will actually be used.
If this is a string, it has to be one of "any", "shortest", or "longest",
which mean that any, the shortest, or the longest match is used.
If it is a function, it must return a table with two fields, `record` and
`retrieve`. `record` is called with a TSMatch and a potential node for the
ts-match, and may return `true` to abort the selection-procedure.
`retrieve` must return either a TSMatch-TSNode-tuple (which is used as the
match) or `nil`, to signify that there is no match.
`lua/luasnip/extras/_treesitter.lua` contains the table
`builtin_tsnode_selectors`, which contains the implementations for
any/shortest/longest, which can be used as examples for more complicated
custom-selectors.

The text of the matched node can be accessed as `snip.env.LS_TSMATCH`.
The text of the nodes returned as `NamedTSMatch` can be accessed as
Expand Down

0 comments on commit e232c3e

Please sign in to comment.