mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
Update documentation for new modules 'refactor'/'textobjects'
This commit is contained in:
parent
5e83307a43
commit
d351c9b342
3 changed files with 72 additions and 2 deletions
31
README.md
31
README.md
|
|
@ -133,6 +133,34 @@ require'nvim-treesitter.configs'.setup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
textobjects = { -- syntax-aware textobjects
|
||||||
|
enable = true,
|
||||||
|
disable = {},
|
||||||
|
keymaps = {
|
||||||
|
["iL"] = { -- you can define your own textobjects directly here
|
||||||
|
python = "(function_definition) @function",
|
||||||
|
cpp = "(function_definition) @function",
|
||||||
|
c = "(function_definition) @function",
|
||||||
|
java = "(method_declaration) @function"
|
||||||
|
},
|
||||||
|
-- or you use the queries from supported languages with textobjects.scm
|
||||||
|
["af"] = "@function.outer",
|
||||||
|
["if"] = "@function.inner",
|
||||||
|
["aC"] = "@class.outer",
|
||||||
|
["iC"] = "@class.inner",
|
||||||
|
["ac"] = "@conditional.outer",
|
||||||
|
["ic"] = "@conditional.inner",
|
||||||
|
["ae"] = "@block.outer",
|
||||||
|
["ie"] = "@block.inner",
|
||||||
|
["al"] = "@loop.outer",
|
||||||
|
["il"] = "@loop.inner",
|
||||||
|
["is"] = "@statement.inner",
|
||||||
|
["as"] = "@statement.outer",
|
||||||
|
["ad"] = "@comment.outer",
|
||||||
|
["am"] = "@call.outer",
|
||||||
|
["im"] = "@call.inner"
|
||||||
|
}
|
||||||
|
},
|
||||||
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -171,6 +199,7 @@ The roadmap and all features of this plugin are open to change, and any suggesti
|
||||||
- `refactor.navigation`: Syntax based definition listing and navigation.
|
- `refactor.navigation`: Syntax based definition listing and navigation.
|
||||||
* List all definitions
|
* List all definitions
|
||||||
* Go to definition
|
* Go to definition
|
||||||
|
- `textobjects`: Vim textobjects defined by treesitter queries
|
||||||
|
|
||||||
## Defining Modules
|
## Defining Modules
|
||||||
|
|
||||||
|
|
@ -217,7 +246,7 @@ More information is available in the help file (`:help nvim-treesitter-utils`).
|
||||||
|
|
||||||
## Supported Languages
|
## Supported Languages
|
||||||
|
|
||||||
For treesitter to work, we need to use query files such as those you can find in
|
For `nvim-treesitter` to work, we need to use query files such as those you can find in
|
||||||
`queries/{lang}/{locals,highlights,textobjects}.scm`
|
`queries/{lang}/{locals,highlights,textobjects}.scm`
|
||||||
|
|
||||||
We are looking for maintainers to write query files for their languages.
|
We are looking for maintainers to write query files for their languages.
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,48 @@ By default, everything is disabled. To enable support for features, in your `ini
|
||||||
node_decremental = "grm", -- decrement to the previous node
|
node_decremental = "grm", -- decrement to the previous node
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
refactor = {
|
||||||
|
highlight_defintions = {
|
||||||
|
enable = true
|
||||||
|
},
|
||||||
|
smart_rename = {
|
||||||
|
enable = true,
|
||||||
|
smart_rename = "grr" -- mapping to rename reference under cursor
|
||||||
|
},
|
||||||
|
navigation = {
|
||||||
|
enable = true,
|
||||||
|
goto_definition = "gnd", -- mapping to go to definition of symbol under cursor
|
||||||
|
list_definitions = "gnD" -- mapping to list all definitions in current file
|
||||||
|
}
|
||||||
|
},
|
||||||
|
textobjects = { -- syntax-aware textobjects
|
||||||
|
enable = true,
|
||||||
|
disable = {},
|
||||||
|
keymaps = {
|
||||||
|
["iL"] = { -- you can define your own textobjects directly here
|
||||||
|
python = "(function_definition) @function",
|
||||||
|
cpp = "(function_definition) @function",
|
||||||
|
c = "(function_definition) @function",
|
||||||
|
java = "(method_declaration) @function"
|
||||||
|
},
|
||||||
|
-- or you use the queries from supported languages with textobjects.scm
|
||||||
|
["af"] = "@function.outer",
|
||||||
|
["if"] = "@function.inner",
|
||||||
|
["aC"] = "@class.outer",
|
||||||
|
["iC"] = "@class.inner",
|
||||||
|
["ac"] = "@conditional.outer",
|
||||||
|
["ic"] = "@conditional.inner",
|
||||||
|
["ae"] = "@block.outer",
|
||||||
|
["ie"] = "@block.inner",
|
||||||
|
["al"] = "@loop.outer",
|
||||||
|
["il"] = "@loop.inner",
|
||||||
|
["is"] = "@statement.inner",
|
||||||
|
["as"] = "@statement.outer",
|
||||||
|
["ad"] = "@comment.outer",
|
||||||
|
["am"] = "@call.outer",
|
||||||
|
["im"] = "@call.inner"
|
||||||
|
}
|
||||||
|
},
|
||||||
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ function M.select_textobject(query_string)
|
||||||
local root = parser:parse():root()
|
local root = parser:parse():root()
|
||||||
local start_row, _, end_row, _ = root:range()
|
local start_row, _, end_row, _ = root:range()
|
||||||
|
|
||||||
local nested = {}
|
|
||||||
local query = ts.parse_query(lang, query_string)
|
local query = ts.parse_query(lang, query_string)
|
||||||
for m in queries.iter_prepared_matches(query, root, bufnr, start_row, end_row) do
|
for m in queries.iter_prepared_matches(query, root, bufnr, start_row, end_row) do
|
||||||
for _, n in pairs(m) do
|
for _, n in pairs(m) do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue