SkillAgentSearch skills...

Navigator.lua

Code analysis & navigation plugin for Neovim. Navigate codes like a breeze🎐 Exploring LSP and 🌲Treesitter symbols a piece of 🍰 Take control like a boss 🦍

Install / Use

/learn @ray-x/Navigator.lua

README

Navigator

  • Source code analysis and navigate tool

  • Easy code navigation, view diagnostic errors, see relationships of functions, variables

  • A plugin combines the power of LSP and 🌲🏡 Treesitter together. Not only provides a better highlight but also help you analyse symbol context effectively.

  • ctags fuzzy search & build ctags symbols

a short intro of navigator

Here are some examples:

Example: Javascript closure

The screenshot below shows javascript call tree 🌲 for variable browser within a closure. This feature parallels the LSP 'incoming & outgoing calls' feature. It is designed for the symbol analysis.

navigator

Explanation:

  • The topmost entry in the floating window indicates there are 3 references for the symbol <span style="color:red"> browser </span> within closure.js
  • The first reference of browser is an assignment, an emoji 📝 indicates the value is modified in this line. In many cases, we search for references to find out when the value changed.
  • The second reference of browser is inside function displayName and displayName sit inside makeFunc, So you will see displayName{} <- makeFunc{}
  • The next occurrence of browser is located within the function displayName, which is nested inside makeFunc. Hence, the display reads displayName{} <- makeFunc{}.
  • The final reference is akin to the previous one, except that since browser appears on the right side of the =, its value remains unaltered, and consequently, no emoji is displayed.

Example: C++ definition

C++ example: search reference and definition

cpp_ref

You may find a 🦕 dinosaur(d) on the line of Rectangle rect, which means there is a definition (d for def) of rect in this line.

<- f main() means the definition is inside function main().

Features

  • LSP easy setup. Support the most commonly used lsp clients setup. Dynamic lsp activation based on buffer type. This also enables you to handle workspace with mixed types of codes (e.g. Go + javascript + yml).

  • Out of box experience. 10 lines of minimum init.lua can turn your neovim into a full-featured LSP & Treesitter powered IDE

  • UI with floating windows, navigator provides a visual way to manage and navigate through symbols, diagnostic errors, references etc. It covers all features(handler) provided by LSP from commonly used search reference, to less commonly used search for interface implementation.

  • Edit your code in preview window

  • Async (Luv async thread and tasks) request with lsp.buf_request for better performance

  • Treesitter symbol search. It is handy for large files (Some of LSP e.g. lua_ls, there is a 100kb file size limitation?). Also as LSP trying to hide details behind, Treesitter allows you to access all AST semantics.

  • FZY search with either native C (if gcc installed) or Lua-JIT

  • LSP multiple symbols highlight/marker and hop between document references

  • Preview definition/references

  • Better navigation for diagnostic errors, Navigate through all files/buffers that contain errors/warnings

  • Grouping references/implementation/incoming/outgoing based on file names.

  • Treesitter based variable/function context analysis. It is 10x times faster compared to purely rely on LSP. In most of the case, it takes treesitter less than 4 ms to read and render all nodes for a file of 1,000 LOC.

  • The first plugin, IMO, allows you to search in all treesitter symbols in the workspace.

  • Optimize display (remove trailing bracket/space), display the caller of reference, de-duplicate lsp results (e.g reference in the same line). Using treesitter for file preview highlighter etc

  • ccls call hierarchy (Non-standard ccls/call API) supports

  • Advanced folding capabilities:

    • Incorporates a tailored folding algorithm based on treesitter & LSP_fold, providing a user experience comparable to Visual Studio Code.
      • Visible Closing Brackets: Ensures that end or closing brackets stay visible even when code is folded.
      • Collapsible Comments: Allows users to fold and unfold comment sections.
      • Fold Indicator: Displays indicators for lines that are folded.
      • Highlighted Folded Lines: Applies syntax highlighting to folded lines (supported in Neovim v0.10.x+).
  • Treesitter symbols sidebar, LSP document symbol sidebar. Both with preview and folding

  • Calltree: Display and expand Lsp incoming/outgoing calls hierarchy-tree with sidebar

  • Fully support LSP CodeAction, CodeLens, CodeLens action. Help you improve code quality.

  • Lazy loader friendly

  • Multigrid support (different font and detachable)

  • Side panel (sidebar) and floating windows

Why a new plugin

I'd like to go beyond what the system is offering.

Similar projects / special mentions

Showcases and Screenshots

For more showcases, please check showcases.md

Install

Require nvim-0.9 or above, nightly (0.10 or greater) preferred

You can remove your lspconfig setup and use this plugin. The plugin depends on lspconfig and guihua.lua, which provides GUI and fzy support(migrate from romgrk's project).

Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' }
Plug 'ray-x/navigator.lua'

Note: Highly recommend: 'nvim-treesitter/nvim-treesitter'

Packer

use({
    'ray-x/navigator.lua',
    requires = {
        { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' },
        { 'neovim/nvim-lspconfig' },
    },
})

Setup

Easy setup BOTH lspconfig and navigator with one liner. Navigator covers around 20 most used LSP setup.

lua require'navigator'.setup()

Sample vimrc turning your neovim into a full-featured IDE

call plug#begin('~/.vim/plugged')

Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' }
Plug 'ray-x/navigator.lua'

" Plug 'hrsh7th/nvim-cmp' and other plugins you commenly use...

" optional, if you need treesitter symbol support
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

call plug#end()

" No need for require('lspconfig'), navigator will configure it for you
lua <<EOF
require'navigator'.setup()
EOF

You can remove your lspconfig.lua and use the hooks of navigator.lua. As the navigator will bind keys and handler for you. The LSP will be loaded lazily based on filetype.

A treesitter only mode. In some cases LSP is buggy or not available, you can also use treesitter standalone

call plug#begin('~/.vim/plugged')

Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' }
Plug 'ray-x/navigator.lua'

" Plug 'hrsh7th/nvim-compe' and other plugins you commenly use...

" optional, if you need treesitter symbol support
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" optional:
Plug 'nvim-treesitter/nvim-treesitter-refactor' " this provides "go to def" etc

call plug#end()

lua <<EOF
require'navigator'.setup()
EOF

Work with nvim-cmp and nvim-autopairs

The buffer type of navigator floating windows is guihua I would suggest disable guihua for autocomplete. e.g.

require('nvim-autopairs').setup{
disable_filetype = { "TelescopePrompt" , "guihua", "guihua_rust", "clap_input" },

if vim.o.ft == 'clap_input' and vim.o.ft == 'guihua' and vim.o.ft == 'guihua_rust' then
  require'cmp'.setup.buffer { completion = {enable = false} }
end

-- or with autocmd
vim.cmd("autocmd FileType guihua lua require('cmp').setup.buffer { enabled = false }")
vim.cmd("autocmd FileType guihua_rust lua require('cmp').setup.buffer { enabled = false }")

...
}

All configure options

Nondefault configuration example:

require'navigator'.setup({
  debug = false, -- log output, set to true and log path: ~/.cache/nvim/gh.log
                 -- slowdownd startup and some actions
  width = 0.75, -- max width ratio (number of cols for the floating window) / (window width)
  height = 0.3, -- max list window height, 0.3 by default
  preview_height = 0.35, -- max height of preview windows
  border = {"╭", "─", "╮", "│", "╯", "─", "╰", "│"}, -- border style, can be one of 'none', 'single', 'double',
                                                     -- 'shadow', or a list of chars which defines the border
  on_attach = function(client, bufnr) -- no longer supported for nvim > 0.

Related Skills

View on GitHub
GitHub Stars1.4k
CategoryDevelopment
Updated1h ago
Forks65

Languages

Lua

Security Score

100/100

Audited on Mar 28, 2026

No findings