1
- *luasnip.txt* For NVIM v0.8.0 Last change: 2023 March 13
1
+ *luasnip.txt* For NVIM v0.8.0 Last change: 2023 March 19
2
2
3
3
==============================================================================
4
4
Table of Contents *luasnip-table-of-contents*
@@ -36,6 +36,7 @@ Table of Contents *luasnip-table-of-contents*
36
36
- Filetype-Functions | luasnip-extras-filetype-functions |
37
37
- Postfix-Snippet | luasnip-extras-postfix-snippet |
38
38
- Snippet List | luasnip-extras-snippet-list |
39
+ - Snippet Location | luasnip-extras-snippet-location |
39
40
16. Extend Decorator | luasnip-extend-decorator |
40
41
17. LSP-Snippets | luasnip-lsp-snippets |
41
42
- Snipmate Parser | luasnip-lsp-snippets-snipmate-parser |
@@ -56,8 +57,9 @@ Table of Contents *luasnip-table-of-contents*
56
57
24. Events | luasnip-events |
57
58
25. Cleanup | luasnip-cleanup |
58
59
26. Logging | luasnip-logging |
59
- 27. Config-Options | luasnip-config-options |
60
- 28. API | luasnip-api |
60
+ 27. Source | luasnip-source |
61
+ 28. Config-Options | luasnip-config-options |
62
+ 29. API | luasnip-api |
61
63
>
62
64
__ ____
63
65
/\ \ /\ _`\ __
@@ -1674,6 +1676,26 @@ Let’s recreate the custom display example above:
1674
1676
<
1675
1677
1676
1678
1679
+ SNIPPET LOCATION *luasnip-extras-snippet-location*
1680
+
1681
+ This module can consume a snippets | luasnip-source | , more specifically, jump to
1682
+ the location referred by it. This is primarily implemented for snippet which
1683
+ got their source from one of the loaders, but might also work for snippets
1684
+ where the source was set manually.
1685
+
1686
+ `require (" luasnip.extras.snip_location" )` : *
1687
+ `snip_location.jump_to_snippet(snip, opts)` Jump to the definition of `snip` . *
1688
+ `snip` : a snippet with attached source-data. * `opts` : `nil|table` , optional
1689
+ arguments, valid keys are: * `hl_duration_ms` : `number ` , duration for which the
1690
+ definition should be highlighted, in milliseconds. 0 disables the highlight. *
1691
+ `edit_fn` : `function (file )` , this function will be called with the file the
1692
+ snippet is located in, and is responsible for jumping to it. We assume that
1693
+ after it has returned, the current buffer contains `file ` . *
1694
+ `snip_location.jump_to_active_snippet (opts)` Jump to definition of active
1695
+ snippet. * `opts` : `nil|table` , accepts the same keys as the `opts` -parameter
1696
+ of `jump_to_snippet` .
1697
+
1698
+
1677
1699
==============================================================================
1678
1700
16. Extend Decorator *luasnip-extend-decorator*
1679
1701
@@ -2762,7 +2784,43 @@ print a short message to the log.
2762
2784
2763
2785
2764
2786
==============================================================================
2765
- 27. Config-Options *luasnip-config-options*
2787
+ 27. Source *luasnip-source*
2788
+
2789
+ It is possible to attach, to a snippet, information about its source. This can
2790
+ be done either by the various loaders (if it is enabled in `ls .setup`
2791
+ (| luasnip-config-options | , `loaders_store_source` )), or manually. The attached
2792
+ data can be used by | luasnip-extras-snippet-location | to jump to the definition
2793
+ of a snippet.
2794
+
2795
+ It is also possible to get/set the source of a snippet via API:
2796
+
2797
+ `ls .snippet_source` :
2798
+
2799
+
2800
+ - `get(snippet) -> source_data`:
2801
+ Retrieve the source-data of `snippet` . `source_data` always contains the key
2802
+ `file ` , the file in which the snippet was defined, and may additionally
2803
+ contain `line ` or `line_end` , the first and last line of the definition.
2804
+ - `set(snippet, source)`:
2805
+ Set the source of a snippet.
2806
+ - `snippet` : a snippet which was added via `ls .add_snippets` .
2807
+ - `source ` : a `source ` -object, obtained from either `from_debuginfo` or
2808
+ `from_location` .
2809
+ - `from_location(file, opts) -> source`:
2810
+ - `file ` : `string ` , The path to the file in which the snippet is defined.
2811
+ - `opts` : `table|nil` , optional parameters for the source.
2812
+ - `line ` : `number ` , the first line of the definition. 1-indexed.
2813
+ - `line_end` : `number ` , the final line of the definition. 1-indexed.
2814
+ - `from_debuginfo(debuginfo) -> source`:
2815
+ Generates source from the table returned by `debug .getinfo` (from now on
2816
+ referred to as `debuginfo` ). `debuginfo` has to be of a frame of a function
2817
+ which is backed by a file, and has to contain this information, ie. has to be
2818
+ generated by `debug.get_info(*, "Sl")` (at least `" Sl" ` , it may also contain
2819
+ more info).
2820
+
2821
+
2822
+ ==============================================================================
2823
+ 28. Config-Options *luasnip-config-options*
2766
2824
2767
2825
These are the settings you can provide to `luasnip.setup ()` :
2768
2826
@@ -2829,10 +2887,14 @@ These are the settings you can provide to `luasnip.setup()`:
2829
2887
warnings, consider adding the undefined globals to the globals recognized by
2830
2888
`lua - language - server` or add `---@diagnostic disable: undefined-global`
2831
2889
somewhere in the affected files.
2890
+ - `loaders_store_source` , boolean, whether loaders should store the source of the
2891
+ loaded snippets. Enabling this means that the definition of any snippet can be
2892
+ jumped to via | luasnip-extras-snippet-location | , but also entails slightly
2893
+ increased memory consumption (and load-time, but it’s not really noticeable).
2832
2894
2833
2895
2834
2896
==============================================================================
2835
- 28 . API *luasnip-api*
2897
+ 29 . API *luasnip-api*
2836
2898
2837
2899
`require (" luasnip" )` :
2838
2900
0 commit comments