Skip to content

Commit e32271c

Browse files
committed
feat(surround)!: make use_nvim_treesitter=false treesitter() default
Details: - It was originally present because it was more capable than built-in `vim.treesitter`. Now this is not the case, so it is not needed anymore. Making it default to `false` is the first step towards deprecating it completely (after the next release). Besides, 'nvim-treesitter/nvim-treesitter' is actively moving towards making `main` branch default which doesn't have necessary capabilities that `master` branch has.
1 parent 50cc629 commit e32271c

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ There are following change types:
5959

6060
- "Paste" action now supports special registers: `<C-w>` (word at cursor), `<C-a>` (WORD at cursor), `<C-l>` (line at cursor), `<C-f>` (filename at cursor).
6161

62+
## mini.surround
63+
64+
### Refine
65+
66+
- Update `gen_spec.inpuf.treesitter()` to have `use_nvim_treesitter = false` as default option value (instead of `true`). It used to implement more advanced behavior, but as built-in `vim.treesitter` is capable enough, there is no need in extra dependency. The option will be removed after the release.
67+
6268
## mini.test
6369

6470
### Refine

doc/mini-surround.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,6 @@ Example configuration for function definition textobject with
819819
})
820820
<
821821
Notes:
822-
- By default query is done using 'nvim-treesitter' plugin if it is present
823-
(falls back to builtin methods otherwise). This allows for a more
824-
advanced features (like multiple buffer languages, custom directives, etc.).
825-
See `opts.use_nvim_treesitter` for how to disable this.
826822
- Be sure that query files don't contain unknown |treesitter-directives|
827823
(like `#make-range!`, for example). Otherwise surrounding with such captures
828824
might not be found as |vim.treesitter| won't treat them as captures. Verify
@@ -841,9 +837,11 @@ Parameters ~
841837
should be a string capture starting with `'@'`.
842838
{opts} `(table|nil)` Options. Possible values:
843839
- <use_nvim_treesitter> - whether to try to use 'nvim-treesitter' plugin
844-
(if present) to do the query. It implements more advanced behavior at
845-
cost of increased execution time. Provides more coherent experience if
846-
'nvim-treesitter-textobjects' queries are used. Default: `true`.
840+
(if present) to do the query. It used to implement more advanced behavior
841+
and more coherent experience if 'nvim-treesitter-textobjects' queries are
842+
used. However, as |lua-treesitter-core| methods are more capable now,
843+
the option will soon be removed. Only present for backward compatibility.
844+
Default: `false`.
847845

848846
Return ~
849847
`(function)` Function which returns array of current buffer region pairs
@@ -852,7 +850,7 @@ Return ~
852850
See also ~
853851
|MiniSurround-surround-specification| for how this type of
854852
surrounding specification is processed.
855-
|get_query()| for how query is fetched in case of no 'nvim-treesitter'.
853+
|vim.treesitter.get_query()| for how query is fetched.
856854
|Query:iter_captures()| for how all query captures are iterated in case of
857855
no 'nvim-treesitter'.
858856
|MiniAi.gen_spec.treesitter()| for similar 'mini.ai' generator.

lua/mini/surround.lua

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,6 @@ MiniSurround.gen_spec = { input = {}, output = {} }
10111011
--- })
10121012
--- <
10131013
--- Notes:
1014-
--- - By default query is done using 'nvim-treesitter' plugin if it is present
1015-
--- (falls back to builtin methods otherwise). This allows for a more
1016-
--- advanced features (like multiple buffer languages, custom directives, etc.).
1017-
--- See `opts.use_nvim_treesitter` for how to disable this.
10181014
--- - Be sure that query files don't contain unknown |treesitter-directives|
10191015
--- (like `#make-range!`, for example). Otherwise surrounding with such captures
10201016
--- might not be found as |vim.treesitter| won't treat them as captures. Verify
@@ -1032,21 +1028,24 @@ MiniSurround.gen_spec = { input = {}, output = {} }
10321028
--- should be a string capture starting with `'@'`.
10331029
---@param opts table|nil Options. Possible values:
10341030
--- - <use_nvim_treesitter> - whether to try to use 'nvim-treesitter' plugin
1035-
--- (if present) to do the query. It implements more advanced behavior at
1036-
--- cost of increased execution time. Provides more coherent experience if
1037-
--- 'nvim-treesitter-textobjects' queries are used. Default: `true`.
1031+
--- (if present) to do the query. It used to implement more advanced behavior
1032+
--- and more coherent experience if 'nvim-treesitter-textobjects' queries are
1033+
--- used. However, as |lua-treesitter-core| methods are more capable now,
1034+
--- the option will soon be removed. Only present for backward compatibility.
1035+
--- Default: `false`.
10381036
---
10391037
---@return function Function which returns array of current buffer region pairs
10401038
--- representing differences between outer and inner captures.
10411039
---
10421040
---@seealso |MiniSurround-surround-specification| for how this type of
10431041
--- surrounding specification is processed.
1044-
--- |get_query()| for how query is fetched in case of no 'nvim-treesitter'.
1042+
--- |vim.treesitter.get_query()| for how query is fetched.
10451043
--- |Query:iter_captures()| for how all query captures are iterated in case of
10461044
--- no 'nvim-treesitter'.
10471045
--- |MiniAi.gen_spec.treesitter()| for similar 'mini.ai' generator.
10481046
MiniSurround.gen_spec.input.treesitter = function(captures, opts)
1049-
opts = vim.tbl_deep_extend('force', { use_nvim_treesitter = true }, opts or {})
1047+
-- TODO: Remove after releasing 'mini.nvim' 0.17.0
1048+
opts = vim.tbl_deep_extend('force', { use_nvim_treesitter = false }, opts or {})
10501049
captures = H.prepare_captures(captures)
10511050

10521051
return function()

tests/test_surround.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,13 @@ T['gen_spec']['input']['treesitter()']['respects `opts.use_nvim_treesitter`'] =
303303
O = {
304304
input = MiniSurround.gen_spec.input.treesitter(
305305
{ outer = '@plugin_other.outer', inner = '@plugin_other.inner' },
306-
{ use_nvim_treesitter = false }
306+
{ use_nvim_treesitter = true }
307307
)
308308
},
309309
}]])
310310
local lines = get_lines()
311311

312-
-- By default it should be `true` but fall back to builtin if no
313-
-- 'nvim-treesitter' is found
312+
-- By default it should be `false`
314313
validate_find(lines, { 9, 0 }, { { 10, 12 }, { 11, 2 }, { 7, 6 }, { 8, 1 } }, type_keys, 'sf', 'F')
315314
validate_no_find(lines, { 1, 0 }, type_keys, 'sf', 'o')
316315
validate_no_find(lines, { 1, 0 }, type_keys, 'sf', 'O')
@@ -319,10 +318,8 @@ T['gen_spec']['input']['treesitter()']['respects `opts.use_nvim_treesitter`'] =
319318
-- Should prefer range from metadata instead of node itself. This is useful,
320319
-- for example, with `#offset!` directive to create more precise captures.
321320
validate_find(lines, { 9, 0 }, { { 10, 12 }, { 11, 2 }, { 7, 6 }, { 8, 1 } }, type_keys, 'sf', 'F')
322-
validate_find(lines, { 1, 0 }, { { 1, 5 }, { 1, 0 } }, type_keys, 'sf', 'o')
323-
324-
-- Should respect `false` value
325-
validate_no_find(lines, { 1, 0 }, type_keys, 'sf', 'O')
321+
validate_no_find(lines, { 1, 0 }, type_keys, 'sf', 'o')
322+
validate_find(lines, { 1, 0 }, { { 1, 5 }, { 1, 0 } }, type_keys, 'sf', 'O')
326323
end
327324

328325
T['gen_spec']['input']['treesitter()']['respects plugin options'] = function()

0 commit comments

Comments
 (0)