neovim configuration using rocks.nvim plugin manager
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(plugin/treesj): add html attribute split/join option.

+32
+32
lua/plugins/treesj.lua
··· 1 1 local treesj = require("treesj") 2 + local lang_utils = require("treesj.langs.utils") 3 + 4 + ---@param parent_kind string 5 + ---@param node_kind string 6 + local 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 + } 24 + end 2 25 3 26 treesj.setup({ 4 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 + }, 5 37 }) 6 38 7 39 vim.keymap.set("n", "<leader>j", treesj.toggle)