summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Sojka <Steven.Sojka@tdameritrade.com>2020-09-16 07:03:22 -0500
committerSteven Sojka <steelsojka@gmail.com>2020-09-25 10:30:35 -0500
commit82a8b859c6377a03e0c4d33b8b045548568c7aef (patch)
treeb9a2acd3adf5bb32f7a48951e92409d5b2bdf9b4
parent98c12ec23a6df2f2f505304b61c4b2eefc0a568f (diff)
chore(modules): remove refactor module
-rw-r--r--README.md83
-rw-r--r--doc/nvim-treesitter.txt144
-rw-r--r--lua/nvim-treesitter/configs.lua35
-rw-r--r--lua/nvim-treesitter/refactor/highlight_current_scope.lua45
-rw-r--r--lua/nvim-treesitter/refactor/highlight_definitions.lua59
-rw-r--r--lua/nvim-treesitter/refactor/navigation.lua90
-rw-r--r--lua/nvim-treesitter/refactor/smart_rename.lua65
-rw-r--r--plugin/nvim-treesitter.vim5
8 files changed, 8 insertions, 518 deletions
diff --git a/README.md b/README.md
index 8096aea4..1976ea23 100644
--- a/README.md
+++ b/README.md
@@ -118,7 +118,7 @@ EOF
Check [`:h nvim-treesitter-modules`](doc/nvim-treesitter.txt)
for a list of available modules and its options.
-# Available Modules
+# Available modules
## Highlight
@@ -158,80 +158,6 @@ require'nvim-treesitter.configs'.setup {
EOF
```
-## Refactor: highlight definitions
-
-Highlights definition and usages of the current symbol under the cursor.
-
-```lua
-lua <<EOF
-require'nvim-treesitter.configs'.setup {
- refactor = {
- highlight_definitions = { enable = true },
- },
-}
-EOF
-```
-
-## Refactor: highlight current scope
-
-Highlights the block from the current scope where the cursor is.
-
-```lua
-lua <<EOF
-require'nvim-treesitter.configs'.setup {
- refactor = {
- highlight_current_scope = { enable = true },
- },
-}
-EOF
-```
-
-## Refactor: smart rename
-
-Renames the symbol under the cursor within the current scope (and current file).
-
-```lua
-lua <<EOF
-require'nvim-treesitter.configs'.setup {
- refactor = {
- smart_rename = {
- enable = true,
- keymaps = {
- smart_rename = "grr",
- },
- },
- },
-}
-EOF
-```
-
-## Refactor: navigation
-
-Provides "go to definition" for the symbol under the cursor,
-and lists the definitions from the current file. If you use
-`goto_definition_lsp_fallback` instead of `goto_definition` in the config below
-`vim.lsp.buf.definition` is used if nvim-treesitter can not resolve the variable.
-`goto_next_usage`/`goto_previous_usage` go to the next usage of the identifier under the cursor.
-
-
-```lua
-lua <<EOF
-require'nvim-treesitter.configs'.setup {
- refactor = {
- navigation = {
- enable = true,
- keymaps = {
- goto_definition = "gnd",
- list_definitions = "gnD",
- goto_next_usage = "<a-*>",
- goto_previous_usage = "<a-#>",
- },
- },
- },
-}
-EOF
-```
-
## Text objects: select
Define your own text objects mappings
@@ -321,6 +247,13 @@ require'nvim-treesitter.configs'.setup {
EOF
```
+# External modules
+
+Other modules can be installed as plugins.
+
+- [refactor](https://github.com/nvim-treesitter/refactor) - Refactoring and definition modules
+- [playground](https://github.com/nvim-treesitter/playground) - Treesitter integrated playground
+
# Extra features
## Syntax based code folding
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index 24e984d1..3d7fc04c 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -64,11 +64,6 @@ Each module corresponds to an entry in the dictionary passed to the
-- Modules and its options go here
highlight = { enable = true },
incremental_selection = { enable = true },
- refactor = {
- highlight_definitions = { enable = true },
- smart_rename = { enable = true },
- navigation = { enable = true },
- },
textobjects = { enable = true },
}
EOF
@@ -159,124 +154,6 @@ Supported options:
}
EOF
<
-
-------------------------------------------------------------------------------
-REFACTOR *nvim-treesitter-refactor-mod*
-
- *nvim-treesitter-highlight-definitions-submod*
-Highlight definitions~
-
-Highlights definition and usages of the current symbol under the cursor.
-
-Query files: `locals.scm`.
-Supported options:
-- enable: `true` or `false`.
-- disable: list of languages.
-
->
- lua <<EOF
- require'nvim-treesitter.configs'.setup {
- refactor = {
- highlight_definitions = { enable = true },
- },
- }
- EOF
-<
-
-Note: this makes use of the |CursorHold| event, so the highlight is
-triggered after 'updatetime'.
-
- *nvim-treesitter-highlight-current-scope-submod*
-Highlight current scope~
-
-Highlights the block from the current scope where the cursor is.
-
-Query files: `locals.scm`.
-Supported options:
-- enable: `true` or `false`.
-- disable: list of languages.
-
->
- lua <<EOF
- require'nvim-treesitter.configs'.setup {
- refactor = {
- highlight_current_scope = { enable = true },
- },
- }
- EOF
-<
-
- *nvim-treesitter-smart-rename-submod*
-Smart rename~
-
-Renames the symbol under the cursor within the current scope (and current file).
-
-Query files: `locals.scm`.
-Supported options:
-- enable: `true` or `false`.
-- disable: list of languages.
-- keymaps:
- - smart_rename: rename symbol under the cursor.
- Defaults to `grr`.
-
->
- lua <<EOF
- require'nvim-treesitter.configs'.setup {
- refactor = {
- smart_rename = {
- enable = true,
- keymaps = {
- smart_rename = "grr",
- },
- },
- },
- }
- EOF
-<
-
- *nvim-treesitter-navigation-submod*
-Navigation~
-
-Provides "go to definition" for the symbol under the cursor,
-and lists the definitions from the current file.
-
-Query files: `locals.scm`.
-Supported options:
-- enable: `true` or `false`.
-- disable: list of languages.
-- keymaps:
- - goto_definition: go to the definition of the symbol under the cursor.
- Defaults to `gnd`.
- - goto_definition_lsp_fallback: go to the definition of the symbol under
- the cursor or use vim.lsp.buf.definition if the symbol can not be
- resolved. You can use your own fallback function if create a mapping for
- `lua require'nvim-treesitter.refactor.navigation(nil, fallback_function)<cr>` .
- No default mapping
- - list_definitions: list all definitions from the current file.
- Defaults to `gnD`.
- - goto_next_usage: go to next usage of identifier under the cursor.
- Defaults to `<a-*>`.
- - goto_previous_usage: go to previous usage of identifier.
- Defaults to `<a-#>`.
-
->
- lua <<EOF
- require'nvim-treesitter.configs'.setup {
- refactor = {
- navigation = {
- enable = true,
- keymaps = {
- goto_definition = "gnd",
- list_definitions = "gnD",
- goto_next_usage = "<a-*>",
- goto_previous_usage = "<a-#>",
- },
- },
- },
- }
- EOF
-<
-
------------------------------------------------------------------------------
TEXT OBJECTS *nvim-treesitter-textobjects-mod*
@@ -745,27 +622,6 @@ Any variable name that does not have another highlight.
Variable names that are defined by the languages, like `this` or `self`.
==============================================================================
-MODULE-HIGHLIGHTS *nvim-treesitter-module-highlights*
-
-Apart from the general purpose highlights in |nvim-treesitter-highlights|,
-some submodules use their own highlight groups to visualize additional
-information.
-
-`TSDefinition`
- *hl-TSDefinition*
-Used by refactor.highlight_definitions to highlight the definition of the
-symbol under the cursor.
-
-`TSDefinitionUsage`
- *hl-TSDefinitionUsage*
-Used by refactor.highlight_definitions to highlight usages of the symbol under
-the cursor.
-
-`TSCurrentScope`
- *hl-TSCurrentScope*
-Used by refactor.highlight_current_scope to highlight the current scope.
-
-==============================================================================
PERFORMANCE *nvim-treesitter-performance*
`nvim-treesitter` checks the 'runtimepath' on startup in order to discover
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index bb3a98bd..b3877345 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 e4528615..00000000
--- 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 d430d38a..00000000
--- 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 112a1e41..00000000
--- 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 711ab993..00000000
--- 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
diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim
index e103b876..59954f21 100644
--- a/plugin/nvim-treesitter.vim
+++ b/plugin/nvim-treesitter.vim
@@ -59,11 +59,6 @@ highlight default link TSInclude Include
highlight default link TSVariable TSNone
highlight default link TSVariableBuiltin Special
-highlight default link TSDefinitionUsage Visual
-highlight default link TSDefinition Search
-
-highlight default link TSCurrentScope CursorLine
-
highlight default link TSText TSNone
highlight default TSStrong term=bold cterm=bold gui=bold
highlight default TSEmphasis term=italic cterm=italic gui=italic