Skip to content

AST.nvim is Abstract Syntax Tree (AST) implementation for neovim

License

Notifications You must be signed in to change notification settings

ydkulks/AST.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AST.nvim

AST implementation for neovim text editor.

Motivation

  • 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

Demo

Requirements

Quick Start

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
}

Usage

Toggle window

Type :ASTToggle in vim command-line to toggle the window

Jumping

  • Toggle the window
  • Navigate to the node which you would like to jump to and hit enter
  • Hit enter key

Exiting window

  1. Go to a node to jump to that coordinate. This will close window before jumping.
  2. Hit q in Normal mode when the window is open

Defaults

You can view the defaults here and customize them according to your needs

Customization

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.

User Mappings

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>")

Color Scheme

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 })

Contribute

  • 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.

About

AST.nvim is Abstract Syntax Tree (AST) implementation for neovim

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages