Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add context jump function #260

Merged
merged 3 commits into from
May 11, 2023
Merged

Conversation

alisnic
Copy link
Contributor

@alisnic alisnic commented May 2, 2023

return contexts
end

function M.previous_context()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really comfortable exposing the internals of the context object. Can we add functions for simple navigation instead?

Copy link
Contributor Author

@alisnic alisnic May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! how do you see the API? something like M.go_next_context and M.go_to_previous_context?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto_next doesn't make much sense since that information isn't available. I think just go_to_previous_context() (no arguments).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated and rebased.

@alisnic alisnic changed the title feat: add context helper functions feat: add context jump function May 11, 2023
@@ -65,6 +65,9 @@ local ns = api.nvim_create_namespace('nvim-treesitter-context')
--- @type TSNode[]?
local previous_nodes

--- @type Context[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be per buffer.

Suggested change
--- @type Context[]
--- @type table<integer,Context[]>

@@ -803,6 +806,26 @@ function M.setup(options)
end
end

function M.go_to_previous_context()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second though a better name will be just go_to_context, since this won't work if the cursor isn't inside of a context.

E.g.

function foo()
  ....
end

<cursor>  -- go_to_previous_context() won't go to foo

return
end

vim.fn.setpos(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use vim.api.nvim_win_set_cursor.

@lewis6991 lewis6991 merged commit 1cce4b7 into nvim-treesitter:master May 11, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants