AST implementation for neovim text editor.
- Abstract Syntax Tree (AST), is a tree that represents the code in an abstract way, which will help you understand the code better.
- Especially when you are working on someone else's codebase
- It's also helpful to move around in a file quickly
- Install NerdFont for displaying icons in right format.
- Treesitter plugin
- Plenary plugin
Using your favorite plugin manager, install this plugin with its dependencies.
Here is an example for packer package manager.
use{
"ydkulks/AST.nvim",
requires = {
"nvim-treesitter/nvim-treesitter",
"nvim-lua/plenary.nvim"
},
config = function()
require("AST")
end
}
Type :ASTToggle
in vim command-line to toggle the window
- Toggle the window
- Navigate to the node which you would like to jump to and hit enter
- Hit enter key
- Go to a node to jump to that coordinate. This will close window before jumping.
- Hit
q
inNormal
mode when the window is open
You can view the defaults here and customize them according to your needs
The M.nodeTypeRequired
variable in config.lua
takes "buffer type" (key) and a table of nodes and its icons.
So to configure, call setup()
and pass your configuration
require("AST").setup({
nodeTypeRequired = {
rust = {
{ "function_declaration", " " },
{ "if_statement", " " },
{ "for_statement", " " },
{ "while_statement", " " }
}
}
})
Note: You can get the node type value from inspecting the buffer using
:InspectTree
or by installing treesitter's playground plugin.
The vim command :ASTToggle
will toggle the pop-up. Map this command to some keys to toggle the window.
-- For example:
-- Mapped <leader>t to toggle the pop-up window
vim.keymap.set("n","<leader>t",":ASTToggle<CR>")
In this file,
some highlight groups
have been created. Which can be changed in your configuration.
-- Here is an example to configure highlight groups
vim.api.nvim_set_hl(0, 'ASTIcon', { fg = "#98C379", ctermfg = 114 })
- Submissions are welcome. Just open a pull-request under a branch named after your name.
- DO NOT MAKE CHANGES TO MAIN BRANCH
- If you find a bug, please create an issue.