1- *luasnip.txt* For NVIM v0.5.0 Last change: 2022 August 30
1+ *luasnip.txt* For NVIM v0.5.0 Last change: 2022 September 02
22
33==============================================================================
44Table of Contents *luasnip-table-of-contents*
@@ -1340,11 +1340,15 @@ If `jsregexp` is not available, transformation are replaced by a simple copy.
13401340==============================================================================
1341134117. VARIABLES *luasnip-variables*
13421342
1343- All `TM_something` -variables are supported with two additions: `SELECT_RAW` and
1344- `SELECT_DEDENT` . These were introduced because `TM_SELECTED_TEXT` is designed
1345- to be compatible with vscodes’ behavior, which can be counterintuitive when
1346- the snippet can be expanded at places other than the point where selection
1347- started (or when doing transformations on selected text).
1343+ All `TM_something` -variables are supported with two additions: `LS_SELECT_RAW`
1344+ and `LS_SELECT_DEDENT` . These were introduced because `TM_SELECTED_TEXT` is
1345+ designed to be compatible with vscodes’ behavior, which can be
1346+ counterintuitive when the snippet can be expanded at places other than the
1347+ point where selection started (or when doing transformations on selected text).
1348+ Besides those we also provide `LS_TRIGGER` which contains the trigger of the
1349+ snippet, and `LS_CAPTURE_n` (where n is a positive integer) that contains the
1350+ n-th capture when using a regex with capture groups as `trig` in the snippet
1351+ definition.
13481352
13491353All variables can be used outside of lsp-parsed snippets as their values are
13501354stored in a snippets’ `snip.env` -table:
@@ -1353,7 +1357,7 @@ stored in a snippets’ `snip.env`-table:
13531357 s("selected_text", f(function(args, snip)
13541358 local res, env = {}, snip.env
13551359 table.insert(res, "Selected Text (current line is " .. env.TM_LINE_NUMBER .. "):")
1356- for _, ele in ipairs(env.SELECT_RAW ) do table.insert(res, ele) end
1360+ for _, ele in ipairs(env.LS_SELECT_RAW ) do table.insert(res, ele) end
13571361 return res
13581362 end, {}))
13591363<
@@ -1376,9 +1380,11 @@ where:
13761380 Is a function that receives a string and returns a value for the var with that name
13771381 or a table from var name to a value
13781382 (in this case, if the value is a function it will be executed lazily once per snippet expansion).
1379- - `init` : `fn(pos: pair[int] )->map[string, EnvVal]` Takes the 0-based position of the cursor and returns
1383+ - `init` : `fn(info: table )->map[string, EnvVal]` Returns
13801384 a table of variables that will set to the environment of the snippet on expansion,
13811385 use this for vars that have to be calculated in that moment or that depend on each other.
1386+ The `info` table argument contains `pos` (0-based position of the cursor on expansion),
1387+ the `trigger` of the snippet and the `captures` list.
13821388 - `eager` : `list [string ]` names of variables that will be taken from `vars` and appended eagerly (like those in init)
13831389 - `multiline_vars` : `(fn(name:string)->bool)| map[sting, bool] | bool|string[]` Says if certain vars are a table or just a string,
13841390 can be a function that get’s the name of the var and returns true if the var is a key,
@@ -1405,7 +1411,7 @@ A simple example to make it more clear:
14051411
14061412 -- then you can use $SYS_HOME which was eagerly initialized but also $SYS_USER (or any other system environment var) in your snippets
14071413
1408- lsp.env_namespace("POS", {init=function(pos ) return {"VAL": vim.inspect(pos)}} end)
1414+ lsp.env_namespace("POS", {init=function(info ) return {"VAL": vim.inspect(info. pos)}} end)
14091415
14101416 -- then you can use $POS_VAL in your snippets
14111417
0 commit comments