Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): handle cases where brackets are not children of container #37

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# nvim-trevJ.lua

:warning: *This plugin is in an early stage and docs is a bit sparse. Feel free to try it out though and let me know if you have any problems/suggestions.*

Nvim-plugin for doing the opposite of join-line (J) of arguments, powered by treesitter.
The intention of the plugin is the same as [`revJ`](https://github.com/AckslD/nvim-revJ.lua).
However `trevJ` uses treesitter to figure out the formatting and in general does everything much more efficient and better, while not polluting registers, last visual selection etc.
Expand Down
9 changes: 9 additions & 0 deletions lua/trevj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ local settings = {
parameter_list = make_default_opts(),
parameter_call_list = make_default_opts(),
},
r = {
arguments = make_no_final_sep_opts(),
},
}, make_javascript_typescript_containers()),
}

Expand Down Expand Up @@ -226,7 +229,13 @@ M.format_at_cursor = function()
new_lines[#new_lines] = new_lines[#new_lines] .. table.remove(lines, 1)
vim.list_extend(new_lines, lines)
elseif child:named() then
if #new_lines == 0 then
new_lines = { "" }
end
vim.list_extend(new_lines, indent_lines(lines, indent + shiftwidth))
if opts.final_end_line and i == #children then
vim.list_extend(new_lines, { "" })
end
else
if opts.final_end_line and i == #children then
vim.list_extend(new_lines, indent_lines(lines, indent))
Expand Down
Loading