Skip to content

smit4k/graphite.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphite.nvim

Visualize the structure of your codebase as an interactive dependency graph inside Neovim.

Installation

Prerequisites: Neovim >= 0.90

Use your favorite package manager!

{
  "smit4k/graphite.nvim",
  config = function()
    require("graphite").setup()
  end,
}

Configuration

All options are optional — the plugin works with zero configuration.

require("graphite").setup({
  -- Maximum number of files to scan (prevents hangs on huge monorepos)
  max_files = 1000,

  -- When true, :GraphiteOpen always rescans instead of reusing the cache
  auto_refresh = false,

  -- Layout algorithm:
  -- "tree"      -> hierarchical ASCII list
  -- "graph"     -> routed graph view + node list
  layout = "tree",

  -- Lua patterns for paths that should be excluded from scanning
  ignore_patterns = {
    "node_modules", "%.git", "%.cache", "dist", "build", "vendor",
  },
})

Commands

Command Description
:GraphiteOpen Scan the project and open the graph window
:GraphiteRefresh Force a full rescan and re-render
:GraphiteFocus Show only the current file and its direct neighbours
:GraphiteFunctions Show the function-level call graph (requires Tree-sitter grammars)

Keybindings (inside the graph window)

Key Action
j / k Move to the next / previous node
l Jump to the first dependency of the selected node
h Jump to the first node that imports the selected node
t Toggle layout (treegraph)
<Enter> Open the selected file in the editor
q / <Esc> Close the graph window

Supported Languages

Language Detected patterns
Lua require("module")
JavaScript / TypeScript import … from "…", require("…")
Python import foo, from foo import bar
Rust mod name;, use crate::…
Go import "…", import ( … )
Java / Kotlin / Scala import a.b.C
Ruby require, require_relative
PHP use Foo\Bar, require/include
C# / Swift using / import
Zig @import("…")
C / C++ #include "…", #include <…>
Elixir alias/import/require/use

This plugin is in its early stages, expect support for more languages soon

How It Works

  1. Scanutil.scan_dir recursively enumerates files via vim.fn.glob, skipping ignored paths and capping at max_files.
  2. Parseparser.parse_file runs a language-specific regex parser and returns raw dependency identifiers.
  3. Resolvegraph.build maps each identifier to an actual project file (handles Lua dot-paths, JS relative paths, Python dotted modules, Rust mod names, etc.).
  4. Renderrenderer.render assigns BFS layers and renders either a tree view (layout = "tree") or a routed graph view (layout = "graph"), returning a node-position map for navigation.
  5. Displayui.open creates a rounded floating window, applies syntax highlights, and wires up keyboard navigation.

Project Structure

lua/
  graphite/
    init.lua       ← public API & setup()
    commands.lua   ← :Graphite* user commands
    graph.lua      ← graph building, caching, focus mode
    parser.lua     ← language-specific dependency parsers
    renderer.lua   ← ASCII renderer & node-position map
    ui.lua         ← floating window, keymaps, highlights
    util.lua       ← file scanning & path utilities
plugin/
  graphite.lua     ← auto-loaded entry point

About

Visualize the structure of your codebase as an interactive dependency graph inside of Neovim

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors