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

feat: add mini.comment support #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use {
"SmiteshP/nvim-navic",
"MunifTanjim/nui.nvim",
"numToStr/Comment.nvim", -- Optional
"echasnovski/mini.comment", -- Optional
"nvim-telescope/telescope.nvim" -- Optional
}
}
Expand All @@ -38,6 +39,7 @@ Plug "neovim/nvim-lspconfig"
Plug "SmiteshP/nvim-navic"
Plug "MunifTanjim/nui.nvim"
Plug "numToStr/Comment.nvim", " Optional
Plug "echasnovski/mini.comment", " Optional
Plug "nvim-telescope/telescope.nvim" " Optional
Plug "SmiteshP/nvim-navbuddy"
```
Expand Down
3 changes: 2 additions & 1 deletion doc/navbuddy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Requires :

Optional requirements :
- Comment.nvim: `https://github.com/numToStr/Comment.nvim`
- mini.comment: `https://github.com/echasnovski/mini.nvim`
- telescope.nvim: `https://github.com/nvim-telescope/telescope.nvim`

=============================================================================
Expand Down Expand Up @@ -304,7 +305,7 @@ actions.fold_delete ()
Delete fold for current scope. Requires fold methos to be "manual".

actions.comment ()
Comment selected scope. Require Comment.nvim plugin to be installed.
Comment selected scope. Require Comment.nvim or mini.comment plugin to be installed.

actions.move_down ()
Move currently focued node down. Copies entire lines and works only in case
Expand Down
61 changes: 38 additions & 23 deletions lua/nvim-navbuddy/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -425,32 +425,47 @@ end

function actions.comment()
local callback = function(display)
local status_ok, comment = pcall(require, "Comment.api")
if not status_ok then
vim.notify("Comment.nvim not found", vim.log.levels.ERROR)
local status_ok_comment, comment = pcall(require, "Comment.api")
if status_ok_comment then
fix_end_character_position(display.for_buf, display.focus_node.scope)
display.state.leaving_window_for_action = true
vim.api.nvim_set_current_win(display.for_win)
vim.api.nvim_buf_set_mark(
display.for_buf,
"<",
display.focus_node.scope["start"].line,
display.focus_node.scope["start"].character,
{}
)
vim.api.nvim_buf_set_mark(
display.for_buf,
">",
display.focus_node.scope["end"].line,
display.focus_node.scope["end"].character,
{}
)
comment.locked("toggle.linewise")("v")
vim.api.nvim_set_current_win(display.mid.winid)
display.state.leaving_window_for_action = false
return
end

fix_end_character_position(display.for_buf, display.focus_node.scope)
display.state.leaving_window_for_action = true
vim.api.nvim_set_current_win(display.for_win)
vim.api.nvim_buf_set_mark(
display.for_buf,
"<",
display.focus_node.scope["start"].line,
display.focus_node.scope["start"].character,
{}
)
vim.api.nvim_buf_set_mark(
display.for_buf,
">",
display.focus_node.scope["end"].line,
display.focus_node.scope["end"].character,
{}
)
comment.locked("toggle.linewise")("v")
vim.api.nvim_set_current_win(display.mid.winid)
display.state.leaving_window_for_action = false
local status_ok_mini, mini_comment = pcall(require, "mini.comment")
if status_ok_mini then
local start_line = display.focus_node.scope["start"].line
local end_line = display.focus_node.scope["end"].line

display.state.leaving_window_for_action = true
vim.api.nvim_set_current_win(display.for_win)

mini_comment.toggle_lines(start_line, end_line, {})

vim.api.nvim_set_current_win(display.mid.winid)
display.state.leaving_window_for_action = false
return
end

vim.notify("Neither Comment.nvim nor mini.comment found", vim.log.levels.ERROR)
end

return {
Expand Down