eckon / treesitter-current-functions

Quickly search through and jump to function-like structures in the current neovim buffer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

treesitter-current-functions

treesitter-current-functions (also tscf) is a neovim plugin that builds on top of treesitter to

  • show all functions or function-like structures in the current buffer
    • while trying to be language agnostic
  • open a selection tool (telescope, fzf, etc.)

to quickly jump to the wanted function location

Example

Examples might be outdated, please reference docs for more information like commands etc.

telescope with code preview

Example Usage of tscf with preview in telescope

Disclaimer

The repo is my first try at a plugin for vim/lua/treesitter. It can happen that a call will jump to an incorrect location or that it can not find all possible functions, but as it will only jump, nothing too critical (like deleting text) should be happening even in the worst case.

Not all languages are tested (by far) and not all ways of declaring functions are implemented, but it might still work with not tested languages, if the treesitter structure is similar to others.

Fuzzy finders might break, depending on which ones are used and tested (I will most likely only test one that I am using at the time).

The plugin was tested with neovim version 0.8.3 and up, but can possibly work with earlier versions as well (depends on the given neovim treesitter apis, which are still experimental and change a lot).

Install & Setup

  • Install this repo with your favourite plugin manager
    • Plug 'eckon/treesitter-current-functions'
  • Install Treesitter
  • Install one Selection tool
    • telescope (recommended)
      • this will most likely be more supported as I use telescope currently
    • fzf

An example (via lazy) could look something like:

{
  "eckon/treesitter-current-functions",
  dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-telescope/telescope.nvim" },
},

Quickly call the plugin, without any mappings:

:GetCurrentFunctions

The plugin does not add any mappings by itself. As an example following map could be added to your init.vim:

nmap <Leader>cf <CMD>GetCurrentFunctions<CR>

Information

For more information see

  • :help treesitter-current-functions
  • :help tscf
  • :help tscf-installation
  • :help tscf-usage

Some information about development of the plugin can be found here.

About

Quickly search through and jump to function-like structures in the current neovim buffer

License:MIT License


Languages

Language:Lua 64.9%Language:Vim Script 11.9%Language:C++ 11.1%Language:Shell 3.6%Language:Rust 3.2%Language:C 1.7%Language:JavaScript 1.3%Language:C# 1.3%Language:PHP 0.6%Language:Makefile 0.4%