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

feat: Allow desc to set snippet description #1005

Merged
merged 3 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ s({trig="trigger"}, {})
By default, "matches" means the text in front of the cursor matches the
trigger exactly, this behaviour can be modified through `trigEngine`
- `name`: string, can be used by e.g. `nvim-compe` to identify the snippet.
- `dscr`: string, description of the snippet, \n-separated or table
- `desc` (or `dscr`): string, description of the snippet, \n-separated or table
for multiple lines.
- `wordTrig`: boolean, if true, the snippet is only expanded if the word
(`[%w_]+`) before the cursor matches the trigger entirely.
Expand Down Expand Up @@ -254,7 +254,7 @@ s({trig="trigger"}, {})
read it for more examples.

- `docstring`: string, textual representation of the snippet, specified like
`dscr`. Overrides docstrings loaded from json.
`desc`. Overrides docstrings loaded from json.
- `docTrig`: string, used as `line_to_cursor` during docstring-generation.
This might be relevant if the snippet relies on specific values in the
capture-groups (for example, numbers, which won't work with the default
Expand Down
6 changes: 3 additions & 3 deletions doc/luasnip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ The most direct way to define snippets is `s`:
matches the trigger exactly, this behaviour can be modified through
`trigEngine`
- `name`: string, can be used by e.g. `nvim-compe` to identify the snippet.
- `dscr`: string, description of the snippet, -separated or table for multiple
lines.
- `desc` (or `dscr`): string, description of the snippet, -separated or table for
multiple lines.
- `wordTrig`: boolean, if true, the snippet is only expanded if the word
(`[%w_]+`) before the cursor matches the trigger entirely. True by default.
- `regTrig`: boolean, whether the trigger should be interpreted as a lua pattern.
Expand Down Expand Up @@ -322,7 +322,7 @@ The most direct way to define snippets is `s`:
<https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/nodes/util/trig_engines.lua>,
read it for more examples.
- `docstring`: string, textual representation of the snippet, specified like
`dscr`. Overrides docstrings loaded from json.
`desc`. Overrides docstrings loaded from json.
- `docTrig`: string, used as `line_to_cursor` during docstring-generation. This
might be relevant if the snippet relies on specific values in the
capture-groups (for example, numbers, which won’t work with the default
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/extras/snippet_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local function snip_info(snippet)
return {
name = snippet.name,
trigger = snippet.trigger,
description = snippet.dscr,
description = snippet.description,
wordTrig = snippet.wordTrig and true or false,
regTrig = snippet.regTrig and true or false,
docstring = snippet:get_docstring(),
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ local function default_snip_info(snip)
return {
name = snip.name,
trigger = snip.trigger,
description = snip.dscr,
description = snip.description,
wordTrig = snip.wordTrig and true or false,
regTrig = snip.regTrig and true or false,
}
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/loaders/from_snipmate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function parse_snipmate(buffer, filename)
local snip = sp(
{
trig = prefix,
dscr = description,
desc = description,
wordTrig = true,
priority = snipmate_opts.priority,
},
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/loaders/from_vscode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local function get_file_snippets(file)
-- context common to all snippets generated here.
local common_context = {
name = name,
dscr = parts.description or name,
desc = parts.description or name,
wordTrig = ls_conf.wordTrig,
priority = ls_conf.priority,
snippetType = ls_conf.autotrigger and "autosnippet" or "snippet",
Expand Down
8 changes: 6 additions & 2 deletions lua/luasnip/nodes/snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ local function init_snippet_context(context, opts)

effective_context.name = context.name or context.trig

-- context.dscr could be nil, string or table.
effective_context.dscr = util.to_line_table(context.dscr or context.trig)
-- context.{desc,dscr} could be nil, string or table.
-- (defaults to trigger)
effective_context.description =
util.to_line_table(context.desc or context.dscr or context.trig)
-- (keep dscr to avoid breaking downstream usages)
effective_context.dscr = effective_context.description

-- might be nil, but whitelisted in snippetProxy.
effective_context.priority = context.priority
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/snippet_basics_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,21 @@ describe("snippets_basic", function()
},
{ [[ s({trig="a"}, { t"justsometext" }) ]], "name", [["a"]] },

{
[[ s({trig="a", dscr = "thedescription"}, { t"justsometext" }) ]],
"description",
[[{"thedescription"}]],
},
{
[[ s({trig="a"}, { t"justsometext" }) ]],
"description",
[[{"a"}]],
},
{
[[ s({trig="a", dscr = "thedescription"}, { t"justsometext" }) ]],
"dscr",
[[{"thedescription"}]],
},
{ [[ s({trig="a"}, { t"justsometext" }) ]], "dscr", [[{"a"}]] },

{
[[ s({trig="a", docstring = "thedocstring"}, { t"justsometext" }) ]],
Expand Down
1 change: 1 addition & 0 deletions tests/unit/snippetProxy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe("snippetProxy", function()
".wordTrig",
".regTrig",
".dscr",
".description",
".filetype",
".name",
".callbacks",
Expand Down