neovim configuration using rocks.nvim plugin manager
1local treesj = require("treesj")
2local lang_utils = require("treesj.langs.utils")
3
4---@param parent_kind string
5---@param node_kind string
6local function splitjoin_attribute_value(parent_kind, node_kind)
7 return {
8 both = {
9 enable = function(tsn)
10 return tsn:parent():type() == parent_kind
11 end,
12 },
13 split = {
14 format_tree = function(tsj)
15 local str = tsj:child(node_kind)
16 local words = vim.split(str:text(), " ")
17 tsj:remove_child(node_kind)
18 for i, word in ipairs(words) do
19 tsj:create_child({ text = word }, i + 1)
20 end
21 end,
22 },
23 }
24end
25
26treesj.setup({
27 use_default_keymaps = false,
28 max_join_length = 240,
29 langs = {
30 html = lang_utils.merge_preset(require("treesj.langs.html"), {
31 ["quoted_attribute_value"] = splitjoin_attribute_value("attribute", "attribute_value"),
32 }),
33 javascript = lang_utils.merge_preset(require("treesj.langs.javascript"), {
34 ["string"] = splitjoin_attribute_value("jsx_attribute", "string_fragment"),
35 }),
36 },
37})
38
39vim.keymap.set("n", "<leader>j", treesj.toggle)