nvim-treesitter-context icon indicating copy to clipboard operation
nvim-treesitter-context copied to clipboard

Expose context positions

Open romgrk opened this issue 3 years ago • 1 comments

This PR exposes the required API to implement https://github.com/ggandor/leap.nvim/issues/29

We don't have a documented public API, but the 2 functions added here can be considered stable.

-- Get the window & buffer IDs for this context
-- `winid` is not relevant at the moment, but it might be required if
-- we support more than 1 context window instance eventually
-- @param winid number The window id the context refs are for
-- @returns table
function M.get_context(winid)

Example:

require'treesitter-context'.get_context(vim.api.nvim_get_current_win())
-- result
{                                                                                                                                                                                                                    
  context_bufnr = 16,                                                                                                                                                                                                
  context_winid = 1079,                                                                                                                                                                                              
  gutter_bufnr = 17,                                                                                                                                                                                                 
  gutter_winid = 1078                                                                                                                                                                                                
}
-- Map a context window position to the corresponding buffer position
-- Same note as above for `winid`
-- @param winid number The window id the context refs are for
-- @param row number Zero-indexed row number
-- @param col number Zero-indexed col number
-- @returns table or nil
function M.context_position_to_buffer_position(windid, row, col)

Example:

require'treesitter-context'.context_position_to_buffer_position(vim.api.nvim_get_current_win(), 0, 9)
-- result
{14, 4}

cc @ggandor

romgrk avatar Jul 10 '22 12:07 romgrk

Awesome, this seems to provide all that is needed for the feature. Some further tweaks are necessary on our side, because the label and the target are located in different buffers now, which is a new situation. I will report back once it's done.

ggandor avatar Jul 24 '22 18:07 ggandor

This has rotted quite a bit so closing.

lewis6991 avatar Aug 27 '23 12:08 lewis6991