mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 11:50:09 -04:00
add winnr to get_node_at_cursor
This commit is contained in:
parent
cabe61ac19
commit
cf72524b2f
3 changed files with 5 additions and 4 deletions
|
|
@ -137,7 +137,7 @@ you can get some utility functions with
|
||||||
```lua
|
```lua
|
||||||
local ts_utils = require 'nvim-treesitter.ts_utils'
|
local ts_utils = require 'nvim-treesitter.ts_utils'
|
||||||
```
|
```
|
||||||
More information is available in neovim documentation (`:help nvim-treesitter-utils`).
|
More information is available in the help file (`:help nvim-treesitter-utils`).
|
||||||
|
|
||||||
## Supported Languages
|
## Supported Languages
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,8 @@ Nvim treesitter has some wrapper functions that you can retrieve with:
|
||||||
<
|
<
|
||||||
Methods
|
Methods
|
||||||
|
|
||||||
get_node_at_cursor() *ts_utils.get_node_at_cursor*
|
get_node_at_cursor(winnr) *ts_utils.get_node_at_cursor*
|
||||||
|
winnr will be 0 if nil
|
||||||
returns the node under the cursor
|
returns the node under the cursor
|
||||||
|
|
||||||
get_node_text(node, bufnr) *ts_utils.get_node_text*
|
get_node_text(node, bufnr) *ts_utils.get_node_text*
|
||||||
|
|
|
||||||
|
|
@ -206,8 +206,8 @@ function M.previous_scope(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_node_at_cursor()
|
function M.get_node_at_cursor(winnr)
|
||||||
local cursor = api.nvim_win_get_cursor(0)
|
local cursor = api.nvim_win_get_cursor(winnr or 0)
|
||||||
local root = parsers.get_parser().tree:root()
|
local root = parsers.get_parser().tree:root()
|
||||||
return root:named_descendant_for_range(cursor[1]-1,cursor[2],cursor[1]-1,cursor[2])
|
return root:named_descendant_for_range(cursor[1]-1,cursor[2],cursor[1]-1,cursor[2])
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue