Skip to content

Commit

Permalink
improve structure and issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Willem Jan Noort committed Jun 11, 2024
1 parent 738c96a commit eef7937
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 34 deletions.
19 changes: 19 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---@diagnostic disable-next-line lowercase-global
std = {
globals = { "vim" },
read_globals = {
"require",
"error",
"table",
"unpack",
"pairs",
"ipairs",
"setmetatable",
"assert",
"tostring",
"string",
"type",
"os",
"pcall",
},
}
30 changes: 10 additions & 20 deletions lua/ado.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,16 @@ function M.ado_pure(opts)
subcommand.impl(args, opts)
end

vim.api.nvim_create_user_command("AdoPure", M.ado_pure, {
nargs = "*",
range = true,
desc = "Azure DevOps Pull Request command.",
complete = function(arg_lead, cmdline, _)
local subcmd_key, subcmd_arg_lead = cmdline:match("^AdoPure*%s(%S+)%s(.*)$")
if
subcmd_key
and subcmd_arg_lead
and subcommand_tbl[subcmd_key]
and subcommand_tbl[subcmd_key].complete_args
then
return completer(subcommand_tbl[subcmd_key].complete_args, subcmd_arg_lead)
end
function M.auto_completer(arg_lead, cmdline, _)
local subcmd_key, subcmd_arg_lead = cmdline:match("^AdoPure*%s(%S+)%s(.*)$")
if subcmd_key and subcmd_arg_lead and subcommand_tbl[subcmd_key] and subcommand_tbl[subcmd_key].complete_args then
return completer(subcommand_tbl[subcmd_key].complete_args, subcmd_arg_lead)
end

if cmdline:match("^AdoPure*%s+%w*$") then
local subcommand_keys = vim.tbl_keys(subcommand_tbl)
return completer(subcommand_keys, arg_lead)
end
end,
})
if cmdline:match("^AdoPure*%s+%w*$") then
local subcommand_keys = vim.tbl_keys(subcommand_tbl)
return completer(subcommand_keys, arg_lead)
end
end

return M
2 changes: 1 addition & 1 deletion lua/ado/pickers/pull_request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function M.create_auto_wrap_preview()
return vim.api.nvim_create_autocmd("User", {
pattern = "TelescopePreviewerLoaded",
-- group = augroup,
callback = function(args)
callback = function(_)
vim.wo.wrap = true
end,
})
Expand Down
1 change: 1 addition & 0 deletions lua/ado/pickers/thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local function handle_choice(prompt_bufnr)
require("telescope.actions").close(prompt_bufnr)
---@type ThreadEntry
local selection = require("telescope.actions.state").get_selected_entry()
vim.notify(vim.inspect(selection))
-- Do something with selection
end

Expand Down
4 changes: 3 additions & 1 deletion lua/ado/previews/thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ function M.thread_preview(bufnr, thread)
" - "
)
table.insert(preview_content, title .. ":")
table.insert(preview_content, "> " .. tostring(comment.content))
for _, line in pairs(vim.split(comment.content, "\n")) do
table.insert(preview_content, '>' .. line)
end
table.insert(preview_content, "")
end
end
Expand Down
6 changes: 3 additions & 3 deletions lua/ado/render.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local M = {}
BUFFER_NAME = "ado.nvim]"
local buffer_name = "ado.nvim]"

function M.rightsize_window(namespace)
local extmarks = vim.api.nvim_buf_get_extmarks(0, namespace, 0, -1, { details = true })
Expand Down Expand Up @@ -61,10 +61,10 @@ end

local function new_or_clear_ado_window(namespace)
local bufnr = vim.api.nvim_get_current_buf()
if not vim.api.nvim_buf_get_name(0):match(BUFFER_NAME .. "$") then
if not vim.api.nvim_buf_get_name(0):match(buffer_name .. "$") then
M.open_split(namespace)
bufnr = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_name(0, "[" .. bufnr .. "-" .. BUFFER_NAME)
vim.api.nvim_buf_set_name(0, "[" .. bufnr .. "-" .. buffer_name)
end
for _, extmark in pairs(vim.api.nvim_buf_get_extmarks(bufnr, namespace, 0, -1, {})) do
local extmark_id = extmark[1]
Expand Down
9 changes: 1 addition & 8 deletions lua/ado/review.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,10 @@ function M.get_vote_from_value(vote_value)
return nil, "No vote found for this value;"
end

local function vote_options()
local result = {}
for key, value in pairs(M.pull_request_vote) do
table.insert(result, key)
end
return result
end
---Submit vote of choice on pull request
---@param state AdoState
function M.submit_vote(state)
vim.ui.select((vote_options()), { prompt = "Select vote;" }, function(vote)
vim.ui.select(vim.tbl_keys(M.pull_request_vote), { prompt = "Select vote;" }, function(vote)
if not vote then
vim.notify("No vote chosen;", 2)
return
Expand Down
11 changes: 10 additions & 1 deletion plugin/init.lua
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
require("ado")
vim.api.nvim_create_user_command("AdoPure", function(opts)
require("ado").ado_pure(opts)
end, {
nargs = "*",
range = true,
desc = "Azure DevOps Pull Request command.",
complete = function(arg_lead, cmdline, _)
return require("ado").auto_completer(arg_lead, cmdline, _)
end,
})

0 comments on commit eef7937

Please sign in to comment.