Skip to content

Commit 6a4d5c2

Browse files
committed
Merge branch 'master' into add-MANY-types
2 parents 31c78eb + a62e108 commit 6a4d5c2

12 files changed

Lines changed: 63 additions & 74 deletions

File tree

DOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@ these files.
30723072
By default, the names from [`luasnip.config.snip_env`][snip-env-src] will be used, but it's
30733073
possible to customize them by setting `snip_env` in `setup`.
30743074

3075-
[snip-env-src]: https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/config.lua#L22-L48
3075+
[snip-env-src]: https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/default_config.lua#L22-L104
30763076

30773077

30783078
**Example**:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ Neovim >= 0.7 (extmarks)
6666
> specify the `CC` variable in the build command: `make install_jsregexp
6767
> CC=your_compiler_program`. Also, make sure `%GIT%/bin` directory is added in
6868
> the `$PATH` so that `make` can use `%GIT%/bin/sh.exe`.
69+
>
70+
> On FreeBSD (and/or systems that do not install the GNU make package as the default)
71+
> make commands will fail as the Makefile does not align with the expected syntax of the
72+
> BSD variant of make. The solution is to install the GNU variant of make:
73+
> 'pkg install gmake' on FreeBSD.
6974
7075
## Keymaps
7176
In Vim script, with `<Tab>` for jumping forward/expanding a snippet, `<Shift-Tab>` for

data/DOC-template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,7 @@ these files.
30373037
By default, the names from [`luasnip.config.snip_env`][snip-env-src] will be used, but it's
30383038
possible to customize them by setting `snip_env` in `setup`.
30393039

3040-
[snip-env-src]: https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/config.lua#L22-L48
3040+
[snip-env-src]: https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/default_config.lua#L22-L104
30413041

30423042

30433043
**Example**:

doc/luasnip.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*luasnip.txt* For NeoVim 0.7-0.11 Last change: 2026 January 10
1+
*luasnip.txt* For NeoVim 0.7-0.11 Last change: 2026 April 05
22

33
==============================================================================
44
Table of Contents *luasnip-table-of-contents*
@@ -123,7 +123,7 @@ As noted in the |luasnip-loaders-lua|-section:
123123

124124

125125
By default, the names from
126-
[`luasnip.config.snip_env`](https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/config.lua#L22-L48)
126+
[`luasnip.config.snip_env`](https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/default_config.lua#L22-L104)
127127
will be used, but it’s possible to customize them by setting `snip_env` in
128128
`setup`.
129129
Furthermore, note that while this document assumes you have defined `ls` to be
@@ -2982,7 +2982,7 @@ There are two ways to add snippets:
29822982
As defining all of the snippet constructors (`s`, `c`, `t`, …) in every file
29832983
is rather cumbersome, LuaSnip will bring some globals into scope for executing
29842984
these files. By default, the names from
2985-
[`luasnip.config.snip_env`](https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/config.lua#L22-L48)
2985+
[`luasnip.config.snip_env`](https://github.com/L3MON4D3/LuaSnip/blob/master/lua/luasnip/default_config.lua#L22-L104)
29862986
will be used, but it’s possible to customize them by setting `snip_env` in
29872987
`setup`.
29882988

lua/luasnip/extras/_treesitter.lua

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ local function get_lang(bufnr)
77
return lang
88
end
99

10+
---Returns the parser for a specific buffer and attaches it to the buffer
11+
---
12+
---If needed, this will create the parser.
13+
---
14+
---If no parser can be created, nil (and an error message) is returned.
15+
---
16+
---This is a wrapper around Neovim's `vim.treesitter.get_parser()`, to normalize
17+
---the behavior of the old and new versions. The old version threw errors, the
18+
---new version returns them as values. This wrapper normalizes both to the new
19+
---version.
20+
---@param bufnr integer|nil Buffer the parser should be tied to (default: current buffer)
21+
---@param lang string|nil Language of this parser (default: from buffer filetype)
22+
---@param opts table|nil Options to pass to the created language tree
23+
---@return vim.treesitter.LanguageTree? object to use for parsing
24+
---@return string? error message, if applicable
25+
local function get_parser(bufnr, lang, opts)
26+
local has_parser, parser_or_err, err =
27+
pcall(vim.treesitter.get_parser, bufnr, lang, opts)
28+
if not has_parser then
29+
return nil, tostring(parser_or_err)
30+
end
31+
32+
return parser_or_err, err
33+
end
34+
1035
-- Inspect node
1136
---@param node TSNode?
1237
---@return string
@@ -29,7 +54,7 @@ end
2954

3055
---@param bufnr number
3156
---@param region LuaSnip.MatchRegion
32-
---@return LanguageTree, string
57+
---@return vim.treesitter.LanguageTree, string
3358
local function reparse_buffer_after_removing_match(bufnr, region)
3459
local lang = get_lang(bufnr)
3560

@@ -45,7 +70,7 @@ local function reparse_buffer_after_removing_match(bufnr, region)
4570

4671
local source = table.concat(lines, "\n")
4772

48-
---@type LanguageTree
73+
---@type vim.treesitter.LanguageTree
4974
local parser = vim.treesitter.get_string_parser(source, lang, nil)
5075
if parser then
5176
parser:parse()
@@ -85,13 +110,12 @@ function FixBufferContext:enter()
85110
{ "" }
86111
)
87112

88-
local parser, source =
89-
vim.treesitter.get_parser(self.ori_bufnr), self.ori_bufnr
113+
local parser = get_parser(self.ori_bufnr)
90114
if parser then
91115
parser:parse()
92116
end
93117

94-
return parser, source
118+
return parser, self.ori_bufnr
95119
end
96120

97121
function FixBufferContext:leave()
@@ -113,12 +137,11 @@ function FixBufferContext:leave()
113137
{ self.region.row + 1, self.region.col_range[2] }
114138
)
115139

116-
local parser, source =
117-
vim.treesitter.get_parser(self.ori_bufnr), self.ori_bufnr
140+
local parser = get_parser(self.ori_bufnr)
118141
if parser then
119142
parser:parse()
120143
end
121-
return parser, source
144+
return parser, self.ori_bufnr
122145
end
123146

124147
local function capture_to_node(capture)
@@ -260,12 +283,12 @@ local builtin_tsnode_selectors = {
260283
}
261284

262285
---@class LuaSnip.extra.TSParser
263-
---@field parser LanguageTree
286+
---@field parser vim.treesitter.LanguageTree
264287
---@field source string|number
265288
local TSParser = {}
266289

267290
---@param bufnr number?
268-
---@param parser LanguageTree
291+
---@param parser vim.treesitter.LanguageTree
269292
---@param source string|number
270293
---@return LuaSnip.extra.TSParser?
271294
function TSParser.new(bufnr, parser, source)
@@ -439,6 +462,7 @@ end
439462

440463
return {
441464
get_lang = get_lang,
465+
get_parser = get_parser,
442466
reparse_buffer_after_removing_match = reparse_buffer_after_removing_match,
443467
TSParser = TSParser,
444468
FixBufferContext = FixBufferContext,

lua/luasnip/extras/filetype_functions.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ local function fts_from_ts_lang(lang)
1212
end
1313

1414
local function from_cursor_pos()
15-
-- get_parser errors if parser not present (no grammar for language).
16-
local has_parser, parser = pcall(vim.treesitter.get_parser)
15+
local parser = require("luasnip.extras._treesitter").get_parser()
1716

18-
if has_parser then
17+
if parser then
1918
local cursor = require("luasnip.util.util").get_cursor_0ind()
2019
-- assumption: languagetree uses 0-indexed byte-ranges.
2120
local lang = parser

lua/luasnip/extras/snip_location.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ local M = {}
1212
-- return: 4-tuple, {start_line, start_col, end_line, end_col}, range of
1313
-- function-call.
1414
local function lua_find_function_call_node_at(bufnr, line)
15-
local has_parser, parser = pcall(vim.treesitter.get_parser, bufnr, "lua")
16-
if not has_parser then
17-
error("Error while getting parser: " .. parser)
15+
local parser, err =
16+
require("luasnip.extras._treesitter").get_parser(bufnr, "lua")
17+
if not parser then
18+
error("Error while getting parser: " .. err)
1819
end
1920

2021
local root = parser:parse()[1]:root()
@@ -56,9 +57,10 @@ local function range_highlight(line_start, line_end, hl_duration_ms)
5657
end
5758

5859
local function json_find_snippet_definition(bufnr, filetype, snippet_name)
59-
local parser_ok, parser = pcall(vim.treesitter.get_parser, bufnr, filetype)
60-
if not parser_ok then
61-
error("Error while getting parser: " .. parser)
60+
local parser, err =
61+
require("luasnip.extras._treesitter").get_parser(bufnr, filetype)
62+
if not parser then
63+
error("Error while getting parser: " .. err)
6264
end
6365

6466
local root = parser:parse()[1]:root()

lua/luasnip/extras/treesitter_postfix.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ local function make_reparse_enter_and_leave_func(
7777
end
7878
else
7979
return function()
80-
local parser = vim.treesitter.get_parser(bufnr)
80+
local parser =
81+
require("luasnip.extras._treesitter").get_parser(bufnr)
8182
if parser then
8283
parser:parse()
8384
end
@@ -137,7 +138,7 @@ local function generate_resolve_expand_param(match_tsnode, user_resolver)
137138
---@param line_to_cursor string
138139
---@param matched_trigger string
139140
---@param captures any
140-
---@param parser LanguageTree
141+
---@param parser vim.treesitter.LanguageTree
141142
---@param source number|string
142143
---@param bufnr number
143144
---@param pos { [1]: number, [2]: number }

lua/luasnip/util/extend_decorator.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040
--- {key = "and opts1 with this"}
4141
--- )
4242
--- ```
43-
---@return T The decorated function.
43+
---@return T _ The decorated function.
4444
function M.apply(fn, ...)
4545
local extend_properties = function_properties[fn]
4646
assert(

lua/luasnip/util/mark.lua

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -130,37 +130,6 @@ function Mark:copy_pos_gravs(opts)
130130
return mark(pos_beg, pos_end, opts)
131131
end
132132

133-
--- Update the extmark with the given opts & positions.
134-
---
135-
--- note: opts as first arg because positions are pretty likely to stay the same.
136-
---
137-
---@param opts vim.api.keyset.set_extmark
138-
---@param pos_begin LuaSnip.RawPos0
139-
---@param pos_end LuaSnip.RawPos0
140-
function Mark:update(opts, pos_begin, pos_end)
141-
-- if one is changed, the other is likely as well.
142-
if not pos_begin then
143-
-- FIXME(@bew): old_pos_begin & old_pos_end don't exist??
144-
pos_begin = old_pos_begin
145-
if not pos_end then
146-
pos_end = old_pos_end
147-
end
148-
end
149-
-- override with new.
150-
self.opts = vim.tbl_extend("force", self.opts, opts)
151-
vim.api.nvim_buf_set_extmark(
152-
0,
153-
session.ns_id,
154-
pos_begin[1],
155-
pos_begin[2],
156-
vim.tbl_extend(
157-
"force",
158-
self.opts,
159-
{ id = self.id, end_line = pos_end[1], end_col = pos_end[2] }
160-
)
161-
)
162-
end
163-
164133
---@param opts vim.api.keyset.set_extmark
165134
function Mark:set_opts(opts)
166135
local pos_begin, pos_end = self:pos_begin_end_raw()

0 commit comments

Comments
 (0)