forked from nvim-treesitter/nvim-treesitter-textobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvim-treesitter-textobjects.lua
73 lines (68 loc) · 1.96 KB
/
nvim-treesitter-textobjects.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local configs = require "nvim-treesitter.configs"
local utils = require "nvim-treesitter.utils"
local M = {}
M.has_textobjects = function(lang)
return vim.treesitter.query.get_query_files(lang, "textobjects") ~= nil
end
local function has_some_textobject_mapping(lang)
for _, v in pairs(configs.get_module("textobjects.select").keymaps) do
if type(v) == "table" then
if v[lang] then
return true
end
end
end
return false
end
function M.init()
require("nvim-treesitter").define_modules {
textobjects = {
select = {
module_path = "nvim-treesitter.textobjects.select",
enable = false,
disable = {},
is_supported = function(lang)
return M.has_textobjects(lang) or has_some_textobject_mapping(lang)
end,
lookahead = false,
lookbehind = false,
keymaps = {},
selection_modes = {},
},
move = {
module_path = "nvim-treesitter.textobjects.move",
enable = false,
disable = {},
is_supported = M.has_textobjects,
set_jumps = true,
goto_next_start = {},
goto_next_end = {},
goto_previous_start = {},
goto_previous_end = {},
goto_next = {},
goto_previous = {},
},
swap = {
module_path = "nvim-treesitter.textobjects.swap",
enable = false,
disable = {},
is_supported = M.has_textobjects,
swap_next = {},
swap_previous = {},
},
lsp_interop = {
module_path = "nvim-treesitter.textobjects.lsp_interop",
enable = false,
border = "none",
floating_preview_opts = {},
disable = {},
is_supported = M.has_textobjects,
peek_definition_code = {},
},
},
}
for _, m in ipairs { "select", "move", "repeatable_move", "swap", "lsp_interop" } do
utils.setup_commands("textobjects." .. m, require("nvim-treesitter.textobjects." .. m).commands)
end
end
return M