Displays Clojure test structure in a sidebar using clojure-lsp.
- Neovim >= 0.8.0
- clojure-lsp with
experimental.testTreeenabled
Using lazy.nvim:
{
"jozura/clojure-test-tree.nvim",
ft = "clojure",
config = function()
require("clojure-test-tree").setup()
end,
}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"}
},
})| 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 |
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.
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.
:ClojureTestTreeToggle- Toggle the test tree window
Global:
<leader>tt- Toggle test tree
In test tree window:
<CR>- Jump to test locationv- Jump to test location in vertical splits- Jump to test location in horizontal split<Tab>- Toggle collapse/expand<leader>ca- Toggle collapse/expand all deftests
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)")MIT
