* fix: Jumping to wrong buffer (#261)
* fix: Go to last line and show warning when diagnostic is past the end of buffer (#262)
* fix: Get recent pipeline through other means (#266)
* feat: Add keymaps and linewise actions to layouts (#265)

This is a #MINOR release, because we are introducing new keybindings for the comment/note popups.

---------

Co-authored-by: Jakub F. Bortlík <jakub.bortlik@proton.me>
Co-authored-by: sunfuze <sunfuze.1989@gmail.com>
This commit is contained in:
Harrison (Harry) Cramer
2024-04-15 09:56:21 -04:00
committed by GitHub
parent 138b96baea
commit f906af0c3a
20 changed files with 358 additions and 103 deletions

View File

@@ -347,6 +347,11 @@ M.get_buffer_text = function(bufnr)
return text
end
---Returns the number of lines in the buffer. Returns 1 even for empty buffers.
M.get_buffer_length = function(bufnr)
return #vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
end
---Convert string to corresponding boolean
---@param str string
---@return boolean
@@ -371,6 +376,27 @@ M.bool_to_string = function(bool)
return "false"
end
---Toggle boolean value
---@param bool string
---@return string
M.toggle_string_bool = function(bool)
local string_bools = {
["true"] = "false",
["True"] = "False",
["TRUE"] = "FALSE",
["false"] = "true",
["False"] = "True",
["FALSE"] = "TRUE",
}
bool = bool:gsub("^%s+", ""):gsub("%s+$", "")
local toggled = string_bools[bool]
if toggled == nil then
M.notify(("Cannot toggle value '%s'"):format(bool), vim.log.levels.ERROR)
return bool
end
return toggled
end
M.string_starts = function(str, start)
return str:sub(1, #start) == start
end
@@ -630,37 +656,77 @@ M.make_comma_separated_readable = function(str)
return string.gsub(str, ",", ", ")
end
---@param remote? boolean
M.get_all_git_branches = function(remote)
local branches = {}
local handle = remote == true and io.popen("git branch -r 2>&1") or io.popen("git branch 2>&1")
---Return the name of the current branch
---@return string|nil
M.get_current_branch = function()
local handle = io.popen("git branch --show-current 2>&1")
if handle then
for line in handle:lines() do
local branch
if remote then
for res in line:gmatch("origin/([^\n]+)") do
branch = res -- Trim /origin
end
else
branch = line:gsub("^%s*%*?%s*", "") -- Trim leading whitespace and the "* " marker for the current branch
end
table.insert(branches, branch)
end
handle:close()
return handle:read()
else
M.notify("Error running 'git branch' command.", vim.log.levels.ERROR)
end
end
---Return the list of names of all remote-tracking branches
M.get_all_merge_targets = function()
local handle = io.popen("git branch -r 2>&1")
if not handle then
M.notify("Error running 'git branch' command.", vim.log.levels.ERROR)
return
end
local current_branch = M.get_current_branch()
if not current_branch then
return
end
local lines = {}
for line in handle:lines() do
table.insert(lines, line)
end
handle:close()
-- Trim "origin/" and don't include the HEAD pointer
local branches = List.new(lines)
:map(function(line)
return line:match("origin/(%S+)")
end)
:filter(function(branch)
return not branch:match("^HEAD$") and branch ~= current_branch
end)
return branches
end
---Select a git branch and perform callback with the branch as an argument
---@param cb function The callback to perform with the selected branch
M.select_target_branch = function(cb)
local all_branch_names = M.get_all_merge_targets()
if not all_branch_names then
return
end
vim.ui.select(all_branch_names, {
prompt = "Choose target branch for merge",
}, function(choice)
if choice then
cb(choice)
end
end)
end
M.basename = function(str)
local name = string.gsub(str, "(.*/)(.*)", "%2")
return name
end
M.get_web_url = function()
local web_url = require("gitlab.state").INFO.web_url
if web_url ~= nil then
return web_url
end
M.notify("Could not get Gitlab URL", vim.log.levels.ERROR)
end
---@param url string?
M.open_in_browser = function(url)
if vim.fn.has("mac") == 1 then