diff options
| author | Steven Sojka <Steven.Sojka@tdameritrade.com> | 2020-09-16 07:03:22 -0500 |
|---|---|---|
| committer | Steven Sojka <steelsojka@gmail.com> | 2020-09-25 10:30:35 -0500 |
| commit | 82a8b859c6377a03e0c4d33b8b045548568c7aef (patch) | |
| tree | b9a2acd3adf5bb32f7a48951e92409d5b2bdf9b4 /lua | |
| parent | Improve the highlighting for class instantiation (diff) | |
| download | nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.tar nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.tar.gz nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.tar.bz2 nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.tar.lz nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.tar.xz nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.tar.zst nvim-treesitter-82a8b859c6377a03e0c4d33b8b045548568c7aef.zip | |
chore(modules): remove refactor module
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 35 | ||||
| -rw-r--r-- | lua/nvim-treesitter/refactor/highlight_current_scope.lua | 45 | ||||
| -rw-r--r-- | lua/nvim-treesitter/refactor/highlight_definitions.lua | 59 | ||||
| -rw-r--r-- | lua/nvim-treesitter/refactor/navigation.lua | 90 | ||||
| -rw-r--r-- | lua/nvim-treesitter/refactor/smart_rename.lua | 65 |
5 files changed, 0 insertions, 294 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index bb3a98bd1..b3877345d 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -46,41 +46,6 @@ local builtin_modules = { }, is_supported = queries.has_locals }, - refactor = { - highlight_definitions = { - module_path = 'nvim-treesitter.refactor.highlight_definitions', - enable = false, - disable = {}, - is_supported = queries.has_locals - }, - highlight_current_scope = { - module_path = 'nvim-treesitter.refactor.highlight_current_scope', - enable = false, - disable = {}, - is_supported = queries.has_locals, - }, - smart_rename = { - module_path = 'nvim-treesitter.refactor.smart_rename', - enable = false, - disable = {}, - is_supported = queries.has_locals, - keymaps = { - smart_rename = "grr" - } - }, - navigation = { - module_path = 'nvim-treesitter.refactor.navigation', - enable = false, - disable = {}, - is_supported = queries.has_locals, - keymaps = { - goto_definition = "gnd", - list_definitions = "gnD", - goto_next_usage = "<a-*>", - goto_previous_usage = "<a-#>", - } - } - }, textobjects = { select = { module_path = 'nvim-treesitter.textobjects.select', diff --git a/lua/nvim-treesitter/refactor/highlight_current_scope.lua b/lua/nvim-treesitter/refactor/highlight_current_scope.lua deleted file mode 100644 index e45286152..000000000 --- a/lua/nvim-treesitter/refactor/highlight_current_scope.lua +++ /dev/null @@ -1,45 +0,0 @@ --- This module highlights the current scope of at the cursor position - -local ts_utils = require'nvim-treesitter.ts_utils' -local locals = require'nvim-treesitter.locals' -local api = vim.api -local cmd = api.nvim_command - -local M = {} - -local current_scope_namespace = api.nvim_create_namespace('nvim-treesitter-current-scope') - -function M.highlight_current_scope(bufnr) - M.clear_highlights(bufnr) - - local node_at_point = ts_utils.get_node_at_cursor() - local current_scope = locals.containing_scope(node_at_point, bufnr) - - local start_line = current_scope:start() - - if current_scope and start_line ~= 0 then - ts_utils.highlight_node(current_scope, bufnr, current_scope_namespace, 'TSCurrentScope') - end -end - -function M.clear_highlights(bufnr) - api.nvim_buf_clear_namespace(bufnr, current_scope_namespace, 0, -1) -end - -function M.attach(bufnr) - cmd(string.format('augroup NvimTreesitterCurrentScope_%d', bufnr)) - cmd 'au!' - -- luacheck: push ignore 631 - cmd(string.format([[autocmd CursorMoved <buffer=%d> lua require'nvim-treesitter.refactor.highlight_current_scope'.highlight_current_scope(%d)]], bufnr, bufnr)) - cmd(string.format([[autocmd BufLeave <buffer=%d> lua require'nvim-treesitter.refactor.highlight_current_scope'.clear_highlights(%d)]], bufnr, bufnr)) - -- luacheck: pop - cmd 'augroup END' -end - -function M.detach(bufnr) - M.clear_highlights(bufnr) - cmd(string.format('autocmd! NvimTreesitterCurrentScope_%d CursorMoved', bufnr)) - cmd(string.format('autocmd! NvimTreesitterCurrentScope_%d BufLeave', bufnr)) -end - -return M diff --git a/lua/nvim-treesitter/refactor/highlight_definitions.lua b/lua/nvim-treesitter/refactor/highlight_definitions.lua deleted file mode 100644 index d430d38a6..000000000 --- a/lua/nvim-treesitter/refactor/highlight_definitions.lua +++ /dev/null @@ -1,59 +0,0 @@ --- This module highlights reference usages and the corresponding --- definition on cursor hold. - -local ts_utils = require'nvim-treesitter.ts_utils' -local locals = require'nvim-treesitter.locals' -local api = vim.api -local cmd = api.nvim_command - -local M = {} - -local usage_namespace = api.nvim_create_namespace('nvim-treesitter-usages') - -function M.highlight_usages(bufnr) - M.clear_usage_highlights(bufnr) - - local node_at_point = ts_utils.get_node_at_cursor() - local references = locals.get_references(bufnr) - - if not node_at_point or not vim.tbl_contains(references, node_at_point) then - return - end - - local def_node, scope = locals.find_definition(node_at_point, bufnr) - local usages = locals.find_usages(def_node, scope, bufnr) - - for _, usage_node in ipairs(usages) do - if usage_node ~= node_at_point then - ts_utils.highlight_node(usage_node, bufnr, usage_namespace, 'TSDefinitionUsage') - end - end - - if def_node ~= node_at_point then - ts_utils.highlight_node(def_node, bufnr, usage_namespace, 'TSDefinition') - end -end - -function M.clear_usage_highlights(bufnr) - api.nvim_buf_clear_namespace(bufnr, usage_namespace, 0, -1) -end - -function M.attach(bufnr) - cmd(string.format('augroup NvimTreesitterUsages_%d', bufnr)) - cmd 'au!' - -- luacheck: push ignore 631 - cmd(string.format([[autocmd CursorHold <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.highlight_usages(%d)]], bufnr, bufnr)) - cmd(string.format([[autocmd CursorMoved <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.clear_usage_highlights(%d)]], bufnr, bufnr)) - cmd(string.format([[autocmd InsertEnter <buffer=%d> lua require'nvim-treesitter.refactor.highlight_definitions'.clear_usage_highlights(%d)]], bufnr, bufnr)) - -- luacheck: pop - cmd 'augroup END' -end - -function M.detach(bufnr) - M.clear_usage_highlights(bufnr) - cmd(string.format('autocmd! NvimTreesitterUsages_%d CursorHold', bufnr)) - cmd(string.format('autocmd! NvimTreesitterUsages_%d CursorMoved', bufnr)) - cmd(string.format('autocmd! NvimTreesitterUsages_%d InsertEnter', bufnr)) -end - -return M diff --git a/lua/nvim-treesitter/refactor/navigation.lua b/lua/nvim-treesitter/refactor/navigation.lua deleted file mode 100644 index 112a1e412..000000000 --- a/lua/nvim-treesitter/refactor/navigation.lua +++ /dev/null @@ -1,90 +0,0 @@ --- Definition based navigation module - -local ts_utils = require'nvim-treesitter.ts_utils' -local utils = require'nvim-treesitter.utils' -local locals = require'nvim-treesitter.locals' -local configs = require'nvim-treesitter.configs' -local api = vim.api - -local M = {} - -function M.goto_definition(bufnr, fallback_function) - local bufnr = bufnr or api.nvim_get_current_buf() - local node_at_point = ts_utils.get_node_at_cursor() - - if not node_at_point then return end - - local definition = locals.find_definition(node_at_point, bufnr) - - if fallback_function and definition.id == node_at_point.id then - fallback_function() - else - ts_utils.goto_node(definition) - end -end - -function M.goto_definition_lsp_fallback(bufnr) M.goto_definition(bufnr, vim.lsp.buf.definition) end - -function M.list_definitions(bufnr) - local bufnr = bufnr or api.nvim_get_current_buf() - local definitions = locals.get_definitions(bufnr) - - if #definitions < 1 then return end - - local qf_list = {} - - for _, def in ipairs(definitions) do - locals.recurse_local_nodes(def, function(_, node, _, match) - local lnum, col, _ = node:start() - - table.insert(qf_list, { - bufnr = bufnr, - lnum = lnum + 1, - col = col + 1, - text = ts_utils.get_node_text(node)[1] or "", - kind = match and match:sub(1, 1) or "" - }) - end) - end - - vim.fn.setqflist(qf_list, 'r') - api.nvim_command('copen') -end - -function M.goto_adjacent_usage(bufnr, delta) - local bufnr = bufnr or api.nvim_get_current_buf() - local node_at_point = ts_utils.get_node_at_cursor() - if not node_at_point then return end - - local def_node, scope = locals.find_definition(node_at_point, bufnr) - local usages = locals.find_usages(def_node, scope, bufnr) - - local index = utils.index_of(usages, node_at_point) - if not index then return end - - local target_index = (index + delta + #usages - 1) % #usages + 1 - ts_utils.goto_node(usages[target_index]) -end - -function M.goto_next_usage(bufnr) return M.goto_adjacent_usage(bufnr, 1) end -function M.goto_previous_usage(bufnr) return M.goto_adjacent_usage(bufnr, -1) end - -function M.attach(bufnr) - local config = configs.get_module('refactor.navigation') - - for fn_name, mapping in pairs(config.keymaps) do - local cmd = string.format([[:lua require'nvim-treesitter.refactor.navigation'.%s(%d)<CR>]], fn_name, bufnr) - - api.nvim_buf_set_keymap(bufnr, 'n', mapping, cmd, { silent = true, noremap = true }) - end -end - -function M.detach(bufnr) - local config = configs.get_module('refactor.navigation') - - for _, mapping in pairs(config.keymaps) do - api.nvim_buf_del_keymap(bufnr, 'n', mapping) - end -end - -return M diff --git a/lua/nvim-treesitter/refactor/smart_rename.lua b/lua/nvim-treesitter/refactor/smart_rename.lua deleted file mode 100644 index 711ab993a..000000000 --- a/lua/nvim-treesitter/refactor/smart_rename.lua +++ /dev/null @@ -1,65 +0,0 @@ --- Binds a keybinding to smart rename definitions and usages. --- Can be used directly using the `smart_rename` function. - -local ts_utils = require'nvim-treesitter.ts_utils' -local locals = require'nvim-treesitter.locals' -local configs = require'nvim-treesitter.configs' -local utils = require'nvim-treesitter.utils' -local api = vim.api - -local M = {} - -function M.smart_rename(bufnr) - local bufnr = bufnr or api.nvim_get_current_buf() - local node_at_point = ts_utils.get_node_at_cursor() - - if not node_at_point then - utils.print_warning("No node to rename!") - return - end - - local node_text = ts_utils.get_node_text(node_at_point)[1] - local new_name = vim.fn.input('New name: ', node_text or '') - - -- Empty name cancels the interaction or ESC - if not new_name or #new_name < 1 then return end - - local definition, scope = locals.find_definition(node_at_point, bufnr) - local nodes_to_rename = locals.find_usages(definition, scope, bufnr) - - if not vim.tbl_contains(nodes_to_rename, node_at_point) then - table.insert(nodes_to_rename, node_at_point) - end - - if not vim.tbl_contains(nodes_to_rename, definition) then - table.insert(nodes_to_rename, definition) - end - - local edits = {} - - for _, node in ipairs(nodes_to_rename) do - local lsp_range = ts_utils.node_to_lsp_range(node) - local text_edit = { range = lsp_range, newText = new_name } - table.insert(edits, text_edit) - end - vim.lsp.util.apply_text_edits(edits, bufnr) -end - -function M.attach(bufnr) - local config = configs.get_module('refactor.smart_rename') - - for fn_name, mapping in pairs(config.keymaps) do - local cmd = string.format([[:lua require'nvim-treesitter.refactor.smart_rename'.%s(%d)<CR>]], fn_name, bufnr) - api.nvim_buf_set_keymap(bufnr, 'n', mapping, cmd, { silent = true, noremap = true }) - end -end - -function M.detach(bufnr) - local config = configs.get_module('refactor.smart_rename') - - for _, mapping in pairs(config.keymaps) do - api.nvim_buf_del_keymap(bufnr, 'n', mapping) - end -end - -return M |
