Skip to content

jozura/clojure-test-tree.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clojure-test-tree.nvim

Displays Clojure test structure in a sidebar using clojure-lsp.

Demo

Requirements

  • Neovim >= 0.8.0
  • clojure-lsp with experimental.testTree enabled

Installation

Using lazy.nvim:

{
  "jozura/clojure-test-tree.nvim",
  ft = "clojure",
  config = function()
    require("clojure-test-tree").setup()
  end,
}

Configuration

Configure clojure-lsp to enable testTree support:

require('lspconfig').clojure_lsp.setup{
  capabilities = (function()
    local capabilities = vim.lsp.protocol.make_client_capabilities()
    capabilities.experimental = capabilities.experimental or {}
    capabilities.experimental.testTree = true
    return capabilities
  end)(),
}

require("clojure-test-tree").setup({
  position = "right", -- "top", "bottom", "left", "right"
  size = 30,          -- percentage of editor width/height
  collapse_by_default = true, -- collapse deftests by default
  icons = {
    namespace = "📦",
    deftest = "",
    testing = "",
    fallback = "",
    collapsed = "",
    expanded = "",
  },
  -- Path mapping from source files to test files
  mappings = {
    {
      pattern = "^src/(.*)%.clj$",
      target = "test/%1_test.clj"
    }
  },
  -- Markers to identify project root
  root_markers = {
    file = {"deps.edn", "project.clj", "build.boot"},
    directory = {".git"}
  },
})

Options

Option Default Description
position "right" Window position: "top", "bottom", "left", or "right"
size 30 Window size as percentage of editor width/height
collapse_by_default true Collapse deftests by default when tree is first loaded
mappings See below List of pattern-target mappings to convert source file paths to test file paths
root_markers.file {} List of files that indicate project root (e.g., "deps.edn", "project.clj")
root_markers.directory {} List of directories that indicate project root (e.g., ".git")
icons.namespace "📦" Icon for namespaces
icons.deftest "✓" Icon for deftest blocks
icons.testing "○" Icon for testing blocks
icons.fallback "•" Icon for unknown types
icons.collapsed "▶ " Collapsed indicator
icons.expanded "▼ " Expanded indicator

Advanced Configuration

Path Mappings

The mappings option defines how source file paths are converted to test file paths. Each mapping consists of:

  • pattern: A Lua pattern to match against the source file path (relative to project root)
  • target: The replacement pattern for the test file path, where %1, %2, etc. refer to captures from the pattern

Default mapping (if not specified):

mappings = {
  {
    pattern = "src/(.*)%.(clj[sc]?)$",
    target = "test/%1_test.%2"
  }
}

This default handles .clj, .cljs, and .cljc files automatically.

Project Root Markers

Specify markers that identify your project root:

root_markers = {
  file = {"deps.edn", "project.clj", "build.boot", "shadow-cljs.edn"},
  directory = {".git", ".hg"}
}

The plugin searches upward from the current file until it finds one of these markers, establishing the project root for resolving relative paths in the mappings.

Usage

Commands

  • :ClojureTestTreeToggle - Toggle the test tree window

Default Keybindings

Global:

  • <leader>tt - Toggle test tree

In test tree window:

  • <CR> - Jump to test location
  • v - Jump to test location in vertical split
  • s - Jump to test location in horizontal split
  • <Tab> - Toggle collapse/expand
  • <leader>ca - Toggle collapse/expand all deftests

Plug Mappings

For custom keybindings, use these <Plug> mappings:

-- In test tree buffer
vim.keymap.set("n", "your_key", "<Plug>(ClojureTestTreeJump)")
vim.keymap.set("n", "your_key", "<Plug>(ClojureTestTreeJumpVsplit)")
vim.keymap.set("n", "your_key", "<Plug>(ClojureTestTreeJumpSplit)")
vim.keymap.set("n", "your_key", "<Plug>(ClojureTestTreeToggleCollapse)")
vim.keymap.set("n", "your_key", "<Plug>(ClojureTestTreeToggleAllCollapse)")

License

MIT

About

A Neovim UI for the clojure-lsp experimental.testTree feature

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages