adding initial base config from astrovim
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
local is_available = astronvim.is_available
|
||||
local user_plugin_opts = astronvim.user_plugin_opts
|
||||
local namespace = vim.api.nvim_create_namespace
|
||||
local cmd = vim.api.nvim_create_autocmd
|
||||
local augroup = vim.api.nvim_create_augroup
|
||||
local create_command = vim.api.nvim_create_user_command
|
||||
|
||||
vim.on_key(function(char)
|
||||
if vim.fn.mode() == "n" then
|
||||
local new_hlsearch = vim.tbl_contains({ "<CR>", "n", "N", "*", "#", "?", "/" }, vim.fn.keytrans(char))
|
||||
if vim.opt.hlsearch:get() ~= new_hlsearch then vim.opt.hlsearch = new_hlsearch end
|
||||
end
|
||||
end, namespace "auto_hlsearch")
|
||||
|
||||
if vim.g.heirline_bufferline then
|
||||
local bufferline_group = augroup("bufferline", { clear = true })
|
||||
cmd({ "BufAdd", "BufEnter" }, {
|
||||
desc = "Update buffers when adding new buffers",
|
||||
group = bufferline_group,
|
||||
callback = function(args)
|
||||
if not vim.t.bufs then vim.t.bufs = {} end
|
||||
local bufs = vim.t.bufs
|
||||
if not vim.tbl_contains(bufs, args.buf) then
|
||||
table.insert(bufs, args.buf)
|
||||
vim.t.bufs = bufs
|
||||
end
|
||||
vim.t.bufs = vim.tbl_filter(astronvim.is_valid_buffer, vim.t.bufs)
|
||||
end,
|
||||
})
|
||||
cmd("BufDelete", {
|
||||
desc = "Update buffers when deleting buffers",
|
||||
group = bufferline_group,
|
||||
callback = function(args)
|
||||
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||
local bufs = vim.t[tab].bufs
|
||||
if bufs then
|
||||
for i, bufnr in ipairs(bufs) do
|
||||
if bufnr == args.buf then
|
||||
table.remove(bufs, i)
|
||||
vim.t[tab].bufs = bufs
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
vim.t.bufs = vim.tbl_filter(astronvim.is_valid_buffer, vim.t.bufs)
|
||||
vim.cmd.redrawtabline()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
cmd({ "VimEnter", "FileType", "BufEnter", "WinEnter" }, {
|
||||
desc = "URL Highlighting",
|
||||
group = augroup("highlighturl", { clear = true }),
|
||||
pattern = "*",
|
||||
callback = function() astronvim.set_url_match() end,
|
||||
})
|
||||
|
||||
cmd("TextYankPost", {
|
||||
desc = "Highlight yanked text",
|
||||
group = augroup("highlightyank", { clear = true }),
|
||||
pattern = "*",
|
||||
callback = function() vim.highlight.on_yank() end,
|
||||
})
|
||||
|
||||
cmd("FileType", {
|
||||
desc = "Unlist quickfist buffers",
|
||||
group = augroup("unlist_quickfist", { clear = true }),
|
||||
pattern = "qf",
|
||||
callback = function() vim.opt_local.buflisted = false end,
|
||||
})
|
||||
|
||||
cmd("BufEnter", {
|
||||
desc = "Quit AstroNvim if more than one window is open and only sidebar windows are list",
|
||||
group = augroup("auto_quit", { clear = true }),
|
||||
callback = function()
|
||||
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||
-- Both neo-tree and aerial will auto-quit if there is only a single window left
|
||||
if #wins <= 1 then return end
|
||||
local sidebar_fts = { aerial = true, ["neo-tree"] = true }
|
||||
for _, winid in ipairs(wins) do
|
||||
if vim.api.nvim_win_is_valid(winid) then
|
||||
local bufnr = vim.api.nvim_win_get_buf(winid)
|
||||
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
-- If any visible windows are not sidebars, early return
|
||||
if not sidebar_fts[filetype] then
|
||||
return
|
||||
-- If the visible window is a sidebar
|
||||
else
|
||||
-- only count filetypes once, so remove a found sidebar from the detection
|
||||
sidebar_fts[filetype] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if #vim.api.nvim_list_tabpages() > 1 then
|
||||
vim.cmd.tabclose()
|
||||
else
|
||||
vim.cmd.qall()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
if is_available "alpha-nvim" then
|
||||
local group_name = augroup("alpha_settings", { clear = true })
|
||||
cmd("User", {
|
||||
desc = "Disable status and tablines for alpha",
|
||||
group = group_name,
|
||||
pattern = "AlphaReady",
|
||||
callback = function()
|
||||
local prev_showtabline = vim.opt.showtabline
|
||||
local prev_status = vim.opt.laststatus
|
||||
vim.opt.laststatus = 0
|
||||
vim.opt.showtabline = 0
|
||||
vim.opt_local.winbar = nil
|
||||
cmd("BufUnload", {
|
||||
pattern = "<buffer>",
|
||||
callback = function()
|
||||
vim.opt.laststatus = prev_status
|
||||
vim.opt.showtabline = prev_showtabline
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
cmd("VimEnter", {
|
||||
desc = "Start Alpha when vim is opened with no arguments",
|
||||
group = group_name,
|
||||
callback = function()
|
||||
local should_skip = false
|
||||
if vim.fn.argc() > 0 or vim.fn.line2byte "$" ~= -1 or not vim.o.modifiable then
|
||||
should_skip = true
|
||||
else
|
||||
for _, arg in pairs(vim.v.argv) do
|
||||
if arg == "-b" or arg == "-c" or vim.startswith(arg, "+") or arg == "-S" then
|
||||
should_skip = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not should_skip then
|
||||
if is_available "bufferline.nvim" then pcall(require, "bufferline") end -- TODO v3: remove this line
|
||||
require("alpha").start(true)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if is_available "neo-tree.nvim" then
|
||||
cmd("BufEnter", {
|
||||
desc = "Open Neo-Tree on startup with directory",
|
||||
group = augroup("neotree_start", { clear = true }),
|
||||
callback = function()
|
||||
local stats = vim.loop.fs_stat(vim.api.nvim_buf_get_name(0))
|
||||
if stats and stats.type == "directory" then require("neo-tree.setup.netrw").hijack() end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if is_available "nvim-dap-ui" then
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
desc = "Make q close dap floating windows",
|
||||
group = vim.api.nvim_create_augroup("dapui", { clear = true }),
|
||||
pattern = "dap-float",
|
||||
callback = function() vim.keymap.set("n", "q", "<cmd>close!<cr>") end,
|
||||
})
|
||||
end
|
||||
|
||||
cmd({ "VimEnter", "ColorScheme" }, {
|
||||
desc = "Load custom highlights from user configuration",
|
||||
group = augroup("astronvim_highlights", { clear = true }),
|
||||
callback = function()
|
||||
if vim.g.colors_name then
|
||||
for _, module in ipairs { "init", vim.g.colors_name } do
|
||||
for group, spec in pairs(user_plugin_opts("highlights." .. module)) do
|
||||
vim.api.nvim_set_hl(0, group, spec)
|
||||
end
|
||||
end
|
||||
end
|
||||
astronvim.event "ColorScheme"
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("BufRead", {
|
||||
group = vim.api.nvim_create_augroup("git_plugin_lazy_load", { clear = true }),
|
||||
callback = function()
|
||||
vim.fn.system("git -C " .. vim.fn.expand "%:p:h" .. " rev-parse")
|
||||
if vim.v.shell_error == 0 then
|
||||
vim.api.nvim_del_augroup_by_name "git_plugin_lazy_load"
|
||||
local packer = require "packer"
|
||||
vim.tbl_map(function(plugin) packer.loader(plugin) end, astronvim.git_plugins)
|
||||
end
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ "BufRead", "BufWinEnter", "BufNewFile" }, {
|
||||
group = vim.api.nvim_create_augroup("file_plugin_lazy_load", { clear = true }),
|
||||
callback = function(args)
|
||||
if not (vim.fn.expand "%" == "" or vim.api.nvim_buf_get_option(args.buf, "buftype") == "nofile") then
|
||||
vim.api.nvim_del_augroup_by_name "file_plugin_lazy_load"
|
||||
local packer = require "packer"
|
||||
vim.tbl_map(function(plugin) packer.loader(plugin) end, astronvim.file_plugins)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
create_command(
|
||||
"AstroUpdatePackages",
|
||||
function() astronvim.updater.update_packages() end,
|
||||
{ desc = "Update Packer and Mason" }
|
||||
)
|
||||
create_command("AstroUpdate", function() astronvim.updater.update() end, { desc = "Update AstroNvim" })
|
||||
create_command("AstroReload", function() astronvim.updater.reload() end, { desc = "Reload AstroNvim" })
|
||||
create_command("AstroVersion", function() astronvim.updater.version() end, { desc = "Check AstroNvim Version" })
|
||||
create_command("AstroChangelog", function() astronvim.updater.changelog() end, { desc = "Check AstroNvim Changelog" })
|
||||
create_command("ToggleHighlightURL", function() astronvim.ui.toggle_url_match() end, { desc = "Toggle URL Highlights" })
|
||||
@@ -0,0 +1,4 @@
|
||||
astronvim.initialize_packer()
|
||||
|
||||
local colorscheme = astronvim.user_plugin_opts("colorscheme", nil, false)
|
||||
vim.cmd.colorscheme(vim.tbl_contains(vim.fn.getcompletion("", "color"), colorscheme) and colorscheme or "default_theme")
|
||||
@@ -0,0 +1,43 @@
|
||||
local signs = {
|
||||
{ name = "DiagnosticSignError", text = astronvim.get_icon "DiagnosticError" },
|
||||
{ name = "DiagnosticSignWarn", text = astronvim.get_icon "DiagnosticWarn" },
|
||||
{ name = "DiagnosticSignHint", text = astronvim.get_icon "DiagnosticHint" },
|
||||
{ name = "DiagnosticSignInfo", text = astronvim.get_icon "DiagnosticInfo" },
|
||||
{ name = "DiagnosticSignError", text = astronvim.get_icon "DiagnosticError" },
|
||||
{ name = "DapStopped", text = astronvim.get_icon "DapStopped", texthl = "DiagnosticWarn" },
|
||||
{ name = "DapBreakpoint", text = astronvim.get_icon "DapBreakpoint", texthl = "DiagnosticInfo" },
|
||||
{ name = "DapBreakpointRejected", text = astronvim.get_icon "DapBreakpointRejected", texthl = "DiagnosticError" },
|
||||
{ name = "DapBreakpointCondition", text = astronvim.get_icon "DapBreakpointCondition", texthl = "DiagnosticInfo" },
|
||||
{ name = "DapLogPoint", text = astronvim.get_icon "DapLogPoint", texthl = "DiagnosticInfo" },
|
||||
}
|
||||
|
||||
for _, sign in ipairs(signs) do
|
||||
if not sign.texthl then sign.texthl = sign.name end
|
||||
vim.fn.sign_define(sign.name, sign)
|
||||
end
|
||||
|
||||
astronvim.lsp.diagnostics = {
|
||||
off = {
|
||||
underline = false,
|
||||
virtual_text = false,
|
||||
signs = false,
|
||||
update_in_insert = false,
|
||||
},
|
||||
on = astronvim.user_plugin_opts("diagnostics", {
|
||||
virtual_text = true,
|
||||
signs = { active = signs },
|
||||
update_in_insert = true,
|
||||
underline = true,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
focused = false,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
source = "always",
|
||||
header = "",
|
||||
prefix = "",
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
vim.diagnostic.config(astronvim.lsp.diagnostics[vim.g.diagnostics_enabled and "on" or "off"])
|
||||
@@ -0,0 +1,46 @@
|
||||
return {
|
||||
ActiveLSP = "",
|
||||
ActiveTS = "綠",
|
||||
ArrowLeft = "",
|
||||
ArrowRight = "",
|
||||
BufferClose = "",
|
||||
DapBreakpoint = "",
|
||||
DapBreakpointCondition = "",
|
||||
DapBreakpointRejected = "",
|
||||
DapLogPoint = ".>",
|
||||
DapStopped = "",
|
||||
DefaultFile = "",
|
||||
Diagnostic = "裂",
|
||||
DiagnosticError = "",
|
||||
DiagnosticHint = "",
|
||||
DiagnosticInfo = "",
|
||||
DiagnosticWarn = "",
|
||||
Ellipsis = "…",
|
||||
FileModified = "",
|
||||
FileReadOnly = "",
|
||||
FolderClosed = "",
|
||||
FolderEmpty = "",
|
||||
FolderOpen = "",
|
||||
Git = "",
|
||||
GitAdd = "",
|
||||
GitBranch = "",
|
||||
GitChange = "",
|
||||
GitConflict = "",
|
||||
GitDelete = "",
|
||||
GitIgnored = "◌",
|
||||
GitRenamed = "➜",
|
||||
GitStaged = "✓",
|
||||
GitUnstaged = "✗",
|
||||
GitUntracked = "★",
|
||||
LSPLoaded = "",
|
||||
LSPLoading1 = "",
|
||||
LSPLoading2 = "",
|
||||
LSPLoading3 = "",
|
||||
MacroRecording = "",
|
||||
NeovimClose = "", -- TODO v3: remove this icon
|
||||
Paste = "",
|
||||
Search = "",
|
||||
Selected = "❯",
|
||||
Spellcheck = "暈",
|
||||
TabClose = "",
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
return {
|
||||
ActiveLSP = "LSP:",
|
||||
ArrowLeft = "<",
|
||||
ArrowRight = ">",
|
||||
BufferClose = "x",
|
||||
DapBreakpoint = "B",
|
||||
DapBreakpointCondition = "C",
|
||||
DapBreakpointRejected = "R",
|
||||
DapLogPoint = "L",
|
||||
DapStopped = ">",
|
||||
DefaultFile = "[F]",
|
||||
DiagnosticError = "X",
|
||||
DiagnosticHint = "?",
|
||||
DiagnosticInfo = "i",
|
||||
DiagnosticWarn = "!",
|
||||
Ellipsis = "...",
|
||||
FileModified = "*",
|
||||
FileReadOnly = "[lock]",
|
||||
FolderClosed = "[D]",
|
||||
FolderEmpty = "[E]",
|
||||
FolderOpen = "[O]",
|
||||
GitAdd = "[+]",
|
||||
GitChange = "[/]",
|
||||
GitConflict = "[!]",
|
||||
GitDelete = "[-]",
|
||||
GitIgnored = "[I]",
|
||||
GitRenamed = "[R]",
|
||||
GitStaged = "[S]",
|
||||
GitUnstaged = "[U]",
|
||||
GitUntracked = "[?]",
|
||||
MacroRecording = "Recording:",
|
||||
NeovimClose = "X", -- TODO v3: remove this icon
|
||||
Paste = "[PASTE]",
|
||||
Search = "?",
|
||||
Selected = "*",
|
||||
Spellcheck = "[SPELL]",
|
||||
TabClose = "X",
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
local is_available = astronvim.is_available
|
||||
|
||||
local maps = { i = {}, n = {}, v = {}, t = {} }
|
||||
|
||||
-- Normal --
|
||||
-- Standard Operations
|
||||
maps.n["<leader>w"] = { "<cmd>w<cr>", desc = "Save" }
|
||||
maps.n["<leader>q"] = { "<cmd>q<cr>", desc = "Quit" }
|
||||
maps.n["<leader>h"] = { "<cmd>nohlsearch<cr>", desc = "No Highlight" } -- TODO: REMOVE IN v3
|
||||
maps.n["<leader>fn"] = { "<cmd>enew<cr>", desc = "New File" }
|
||||
maps.n["gx"] = { function() astronvim.system_open() end, desc = "Open the file under cursor with system app" }
|
||||
maps.n["<C-s>"] = { "<cmd>w!<cr>", desc = "Force write" }
|
||||
maps.n["<C-q>"] = { "<cmd>q!<cr>", desc = "Force quit" }
|
||||
maps.n["Q"] = "<Nop>"
|
||||
maps.n["|"] = { "<cmd>vsplit<cr>", desc = "Vertical Split" }
|
||||
maps.n["\\"] = { "<cmd>split<cr>", desc = "Horizontal Split" }
|
||||
|
||||
-- Packer
|
||||
maps.n["<leader>pc"] = { "<cmd>PackerCompile<cr>", desc = "Packer Compile" }
|
||||
maps.n["<leader>pi"] = { "<cmd>PackerInstall<cr>", desc = "Packer Install" }
|
||||
maps.n["<leader>ps"] = { "<cmd>PackerSync<cr>", desc = "Packer Sync" }
|
||||
maps.n["<leader>pS"] = { "<cmd>PackerStatus<cr>", desc = "Packer Status" }
|
||||
maps.n["<leader>pu"] = { "<cmd>PackerUpdate<cr>", desc = "Packer Update" }
|
||||
|
||||
-- AstroNvim
|
||||
maps.n["<leader>pa"] = { "<cmd>AstroUpdatePackages<cr>", desc = "Update Packer and Mason" }
|
||||
maps.n["<leader>pA"] = { "<cmd>AstroUpdate<cr>", desc = "AstroNvim Update" }
|
||||
maps.n["<leader>pv"] = { "<cmd>AstroVersion<cr>", desc = "AstroNvim Version" }
|
||||
maps.n["<leader>pl"] = { "<cmd>AstroChangelog<cr>", desc = "AstroNvim Changelog" }
|
||||
|
||||
-- Alpha
|
||||
if is_available "alpha-nvim" then
|
||||
maps.n["<leader>d"] = { function() require("alpha").start() end, desc = "Alpha Dashboard" }
|
||||
end
|
||||
|
||||
if vim.g.heirline_bufferline then
|
||||
-- Manage Buffers
|
||||
maps.n["<leader>c"] = { function() astronvim.close_buf(0) end, desc = "Close buffer" }
|
||||
maps.n["<leader>C"] = { function() astronvim.close_buf(0, true) end, desc = "Force close buffer" }
|
||||
maps.n["<S-l>"] = { function() astronvim.nav_buf(vim.v.count > 0 and vim.v.count or 1) end, desc = "Next buffer" }
|
||||
maps.n["<S-h>"] =
|
||||
{ function() astronvim.nav_buf(-(vim.v.count > 0 and vim.v.count or 1)) end, desc = "Previous buffer" }
|
||||
maps.n[">b"] =
|
||||
{ function() astronvim.move_buf(vim.v.count > 0 and vim.v.count or 1) end, desc = "Move buffer tab right" }
|
||||
maps.n["<b"] =
|
||||
{ function() astronvim.move_buf(-(vim.v.count > 0 and vim.v.count or 1)) end, desc = "Move buffer tab left" }
|
||||
|
||||
maps.n["<leader>bb"] = {
|
||||
function()
|
||||
astronvim.status.heirline.buffer_picker(function(bufnr) vim.api.nvim_win_set_buf(0, bufnr) end)
|
||||
end,
|
||||
desc = "Select buffer from tabline",
|
||||
}
|
||||
maps.n["<leader>bd"] = {
|
||||
function()
|
||||
astronvim.status.heirline.buffer_picker(function(bufnr) astronvim.close_buf(bufnr) end)
|
||||
end,
|
||||
desc = "Delete buffer from tabline",
|
||||
}
|
||||
maps.n["<leader>b\\"] = {
|
||||
function()
|
||||
astronvim.status.heirline.buffer_picker(function(bufnr)
|
||||
vim.cmd.split()
|
||||
vim.api.nvim_win_set_buf(0, bufnr)
|
||||
end)
|
||||
end,
|
||||
desc = "Horizontal split buffer from tabline",
|
||||
}
|
||||
maps.n["<leader>b|"] = {
|
||||
function()
|
||||
astronvim.status.heirline.buffer_picker(function(bufnr)
|
||||
vim.cmd.vsplit()
|
||||
vim.api.nvim_win_set_buf(0, bufnr)
|
||||
end)
|
||||
end,
|
||||
desc = "Vertical split buffer from tabline",
|
||||
}
|
||||
else -- TODO v3: remove this else block
|
||||
-- Bufdelete
|
||||
if is_available "bufdelete.nvim" then
|
||||
maps.n["<leader>c"] = { function() require("bufdelete").bufdelete(0, false) end, desc = "Close buffer" }
|
||||
maps.n["<leader>C"] = { function() require("bufdelete").bufdelete(0, true) end, desc = "Force close buffer" }
|
||||
else
|
||||
maps.n["<leader>c"] = { "<cmd>bdelete<cr>", desc = "Close buffer" }
|
||||
maps.n["<leader>C"] = { "<cmd>bdelete!<cr>", desc = "Force close buffer" }
|
||||
end
|
||||
|
||||
-- Navigate buffers
|
||||
if is_available "bufferline.nvim" then
|
||||
maps.n["<S-l>"] = { "<cmd>BufferLineCycleNext<cr>", desc = "Next buffer tab" }
|
||||
maps.n["<S-h>"] = { "<cmd>BufferLineCyclePrev<cr>", desc = "Previous buffer tab" }
|
||||
maps.n[">b"] = { "<cmd>BufferLineMoveNext<cr>", desc = "Move buffer tab right" }
|
||||
maps.n["<b"] = { "<cmd>BufferLineMovePrev<cr>", desc = "Move buffer tab left" }
|
||||
else
|
||||
maps.n["<S-l>"] = { "<cmd>bnext<cr>", desc = "Next buffer" }
|
||||
maps.n["<S-h>"] = { "<cmd>bprevious<cr>", desc = "Previous buffer" }
|
||||
end
|
||||
end
|
||||
|
||||
-- Navigate tabs
|
||||
maps.n["]t"] = { function() vim.cmd.tabnext() end, desc = "Next tab" }
|
||||
maps.n["[t"] = { function() vim.cmd.tabprevious() end, desc = "Previous tab" }
|
||||
|
||||
-- Comment
|
||||
if is_available "Comment.nvim" then
|
||||
maps.n["<leader>/"] = { function() require("Comment.api").toggle.linewise.current() end, desc = "Comment line" }
|
||||
maps.v["<leader>/"] = {
|
||||
"<esc><cmd>lua require('Comment.api').toggle.linewise(vim.fn.visualmode())<cr>",
|
||||
desc = "Toggle comment line",
|
||||
}
|
||||
end
|
||||
|
||||
-- GitSigns
|
||||
if is_available "gitsigns.nvim" then
|
||||
maps.n["<leader>gj"] = { function() require("gitsigns").next_hunk() end, desc = "Next Git hunk" }
|
||||
maps.n["<leader>gk"] = { function() require("gitsigns").prev_hunk() end, desc = "Previous Git hunk" }
|
||||
maps.n["<leader>gl"] = { function() require("gitsigns").blame_line() end, desc = "View Git blame" }
|
||||
maps.n["<leader>gp"] = { function() require("gitsigns").preview_hunk() end, desc = "Preview Git hunk" }
|
||||
maps.n["<leader>gh"] = { function() require("gitsigns").reset_hunk() end, desc = "Reset Git hunk" }
|
||||
maps.n["<leader>gr"] = { function() require("gitsigns").reset_buffer() end, desc = "Reset Git buffer" }
|
||||
maps.n["<leader>gs"] = { function() require("gitsigns").stage_hunk() end, desc = "Stage Git hunk" }
|
||||
maps.n["<leader>gu"] = { function() require("gitsigns").undo_stage_hunk() end, desc = "Unstage Git hunk" }
|
||||
maps.n["<leader>gd"] = { function() require("gitsigns").diffthis() end, desc = "View Git diff" }
|
||||
end
|
||||
|
||||
-- NeoTree
|
||||
if is_available "neo-tree.nvim" then
|
||||
maps.n["<leader>e"] = { "<cmd>Neotree toggle<cr>", desc = "Toggle Explorer" }
|
||||
maps.n["<leader>o"] = { "<cmd>Neotree focus<cr>", desc = "Focus Explorer" }
|
||||
end
|
||||
|
||||
-- Session Manager
|
||||
if is_available "neovim-session-manager" then
|
||||
maps.n["<leader>Sl"] = { "<cmd>SessionManager! load_last_session<cr>", desc = "Load last session" }
|
||||
maps.n["<leader>Ss"] = { "<cmd>SessionManager! save_current_session<cr>", desc = "Save this session" }
|
||||
maps.n["<leader>Sd"] = { "<cmd>SessionManager! delete_session<cr>", desc = "Delete session" }
|
||||
maps.n["<leader>Sf"] = { "<cmd>SessionManager! load_session<cr>", desc = "Search sessions" }
|
||||
maps.n["<leader>S."] =
|
||||
{ "<cmd>SessionManager! load_current_dir_session<cr>", desc = "Load current directory session" }
|
||||
end
|
||||
|
||||
-- Package Manager
|
||||
if is_available "mason.nvim" then
|
||||
maps.n["<leader>pI"] = { "<cmd>Mason<cr>", desc = "Mason Installer" }
|
||||
maps.n["<leader>pU"] = { "<cmd>MasonUpdateAll<cr>", desc = "Mason Update" }
|
||||
end
|
||||
|
||||
-- Smart Splits
|
||||
if is_available "smart-splits.nvim" then
|
||||
-- Better window navigation
|
||||
maps.n["<C-h>"] = { function() require("smart-splits").move_cursor_left() end, desc = "Move to left split" }
|
||||
maps.n["<C-j>"] = { function() require("smart-splits").move_cursor_down() end, desc = "Move to below split" }
|
||||
maps.n["<C-k>"] = { function() require("smart-splits").move_cursor_up() end, desc = "Move to above split" }
|
||||
maps.n["<C-l>"] = { function() require("smart-splits").move_cursor_right() end, desc = "Move to right split" }
|
||||
|
||||
-- Resize with arrows
|
||||
maps.n["<C-Up>"] = { function() require("smart-splits").resize_up() end, desc = "Resize split up" }
|
||||
maps.n["<C-Down>"] = { function() require("smart-splits").resize_down() end, desc = "Resize split down" }
|
||||
maps.n["<C-Left>"] = { function() require("smart-splits").resize_left() end, desc = "Resize split left" }
|
||||
maps.n["<C-Right>"] = { function() require("smart-splits").resize_right() end, desc = "Resize split right" }
|
||||
else
|
||||
maps.n["<C-h>"] = { "<C-w>h", desc = "Move to left split" }
|
||||
maps.n["<C-j>"] = { "<C-w>j", desc = "Move to below split" }
|
||||
maps.n["<C-k>"] = { "<C-w>k", desc = "Move to above split" }
|
||||
maps.n["<C-l>"] = { "<C-w>l", desc = "Move to right split" }
|
||||
maps.n["<C-Up>"] = { "<cmd>resize -2<CR>", desc = "Resize split up" }
|
||||
maps.n["<C-Down>"] = { "<cmd>resize +2<CR>", desc = "Resize split down" }
|
||||
maps.n["<C-Left>"] = { "<cmd>vertical resize -2<CR>", desc = "Resize split left" }
|
||||
maps.n["<C-Right>"] = { "<cmd>vertical resize +2<CR>", desc = "Resize split right" }
|
||||
end
|
||||
|
||||
-- SymbolsOutline
|
||||
if is_available "aerial.nvim" then
|
||||
maps.n["<leader>lS"] = { function() require("aerial").toggle() end, desc = "Symbols outline" }
|
||||
end
|
||||
|
||||
-- Telescope
|
||||
if is_available "telescope.nvim" then
|
||||
maps.n["<leader>fw"] = { function() require("telescope.builtin").live_grep() end, desc = "Search words" }
|
||||
maps.n["<leader>fW"] = {
|
||||
function()
|
||||
require("telescope.builtin").live_grep {
|
||||
additional_args = function(args) return vim.list_extend(args, { "--hidden", "--no-ignore" }) end,
|
||||
}
|
||||
end,
|
||||
desc = "Search words in all files",
|
||||
}
|
||||
maps.n["<leader>gt"] = { function() require("telescope.builtin").git_status() end, desc = "Git status" }
|
||||
maps.n["<leader>gb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" }
|
||||
maps.n["<leader>gc"] = { function() require("telescope.builtin").git_commits() end, desc = "Git commits" }
|
||||
maps.n["<leader>ff"] = { function() require("telescope.builtin").find_files() end, desc = "Search files" }
|
||||
maps.n["<leader>fF"] = {
|
||||
function() require("telescope.builtin").find_files { hidden = true, no_ignore = true } end,
|
||||
desc = "Search all files",
|
||||
}
|
||||
maps.n["<leader>fb"] = { function() require("telescope.builtin").buffers() end, desc = "Search buffers" }
|
||||
maps.n["<leader>fh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" }
|
||||
maps.n["<leader>fm"] = { function() require("telescope.builtin").marks() end, desc = "Search marks" }
|
||||
maps.n["<leader>fo"] = { function() require("telescope.builtin").oldfiles() end, desc = "Search history" }
|
||||
maps.n["<leader>fc"] =
|
||||
{ function() require("telescope.builtin").grep_string() end, desc = "Search for word under cursor" }
|
||||
maps.n["<leader>sb"] = { function() require("telescope.builtin").git_branches() end, desc = "Git branches" }
|
||||
maps.n["<leader>sh"] = { function() require("telescope.builtin").help_tags() end, desc = "Search help" }
|
||||
maps.n["<leader>sm"] = { function() require("telescope.builtin").man_pages() end, desc = "Search man" }
|
||||
maps.n["<leader>sr"] = { function() require("telescope.builtin").registers() end, desc = "Search registers" }
|
||||
maps.n["<leader>sk"] = { function() require("telescope.builtin").keymaps() end, desc = "Search keymaps" }
|
||||
maps.n["<leader>sc"] = { function() require("telescope.builtin").commands() end, desc = "Search commands" }
|
||||
if astronvim.is_available "nvim-notify" then
|
||||
maps.n["<leader>sn"] =
|
||||
{ function() require("telescope").extensions.notify.notify() end, desc = "Search notifications" }
|
||||
end
|
||||
maps.n["<leader>ls"] = {
|
||||
function()
|
||||
local aerial_avail, _ = pcall(require, "aerial")
|
||||
if aerial_avail then
|
||||
require("telescope").extensions.aerial.aerial()
|
||||
else
|
||||
require("telescope.builtin").lsp_document_symbols()
|
||||
end
|
||||
end,
|
||||
desc = "Search symbols",
|
||||
}
|
||||
maps.n["<leader>lD"] = { function() require("telescope.builtin").diagnostics() end, desc = "Search diagnostics" }
|
||||
end
|
||||
|
||||
-- Terminal
|
||||
if is_available "toggleterm.nvim" then
|
||||
local toggle_term_cmd = astronvim.toggle_term_cmd
|
||||
if vim.fn.executable "lazygit" == 1 then
|
||||
maps.n["<leader>gg"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" }
|
||||
maps.n["<leader>tl"] = { function() toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" }
|
||||
end
|
||||
if vim.fn.executable "node" == 1 then
|
||||
maps.n["<leader>tn"] = { function() toggle_term_cmd "node" end, desc = "ToggleTerm node" }
|
||||
end
|
||||
if vim.fn.executable "gdu" == 1 then
|
||||
maps.n["<leader>tu"] = { function() toggle_term_cmd "gdu" end, desc = "ToggleTerm gdu" }
|
||||
end
|
||||
if vim.fn.executable "btm" == 1 then
|
||||
maps.n["<leader>tt"] = { function() toggle_term_cmd "btm" end, desc = "ToggleTerm btm" }
|
||||
end
|
||||
if vim.fn.executable "python" == 1 then
|
||||
maps.n["<leader>tp"] = { function() toggle_term_cmd "python" end, desc = "ToggleTerm python" }
|
||||
end
|
||||
maps.n["<leader>tf"] = { "<cmd>ToggleTerm direction=float<cr>", desc = "ToggleTerm float" }
|
||||
maps.n["<leader>th"] = { "<cmd>ToggleTerm size=10 direction=horizontal<cr>", desc = "ToggleTerm horizontal split" }
|
||||
maps.n["<leader>tv"] = { "<cmd>ToggleTerm size=80 direction=vertical<cr>", desc = "ToggleTerm vertical split" }
|
||||
maps.n["<F7>"] = { "<cmd>ToggleTerm<cr>", desc = "Toggle terminal" }
|
||||
maps.t["<F7>"] = maps.n["<F7>"]
|
||||
maps.n["<C-'>"] = maps.n["<F7>"]
|
||||
maps.t["<C-'>"] = maps.n["<F7>"]
|
||||
end
|
||||
|
||||
if is_available "nvim-dap" then
|
||||
-- modified function keys found with `showkey -a` in the terminal to get key code
|
||||
-- run `nvim -V3log +quit` and search through the "Terminal info" in the `log` file for the correct keyname
|
||||
maps.n["<F5>"] = { function() require("dap").continue() end, desc = "Debugger: Start" }
|
||||
maps.n["<F17>"] = { function() require("dap").terminate() end, desc = "Debugger: Stop" } -- Shift+F5
|
||||
maps.n["<F29>"] = { function() require("dap").restart_frame() end, desc = "Debugger: Restart" } -- Control+F5
|
||||
maps.n["<F6>"] = { function() require("dap").pause() end, desc = "Debugger: Pause" }
|
||||
maps.n["<F9>"] = { function() require("dap").toggle_breakpoint() end, desc = "Debugger: Toggle Breakpoint" }
|
||||
maps.n["<F10>"] = { function() require("dap").step_over() end, desc = "Debugger: Step Over" }
|
||||
maps.n["<F11>"] = { function() require("dap").step_into() end, desc = "Debugger: Step Into" }
|
||||
maps.n["<F23>"] = { function() require("dap").step_out() end, desc = "Debugger: Step Out" } -- Shift+F11
|
||||
maps.n["<leader>Db"] = { function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint (F9)" }
|
||||
maps.n["<leader>DB"] = { function() require("dap").clear_breakpoints() end, desc = "Clear Breakpoints" }
|
||||
maps.n["<leader>Dc"] = { function() require("dap").continue() end, desc = "Start/Continue (F5)" }
|
||||
maps.n["<leader>Di"] = { function() require("dap").step_into() end, desc = "Step Into (F11)" }
|
||||
maps.n["<leader>Do"] = { function() require("dap").step_over() end, desc = "Step Over (F10)" }
|
||||
maps.n["<leader>DO"] = { function() require("dap").step_out() end, desc = "Step Out (S-F11)" }
|
||||
maps.n["<leader>Dq"] = { function() require("dap").close() end, desc = "Close Session" }
|
||||
maps.n["<leader>DQ"] = { function() require("dap").terminate() end, desc = "Terminate Session (S-F5)" }
|
||||
maps.n["<leader>Dp"] = { function() require("dap").pause() end, desc = "Pause (F6)" }
|
||||
maps.n["<leader>Dr"] = { function() require("dap").restart_frame() end, desc = "Restart (C-F5)" }
|
||||
maps.n["<leader>DR"] = { function() require("dap").repl.toggle() end, desc = "Toggle REPL" }
|
||||
if is_available "nvim-dap-ui" then
|
||||
maps.n["<leader>Du"] = { function() require("dapui").toggle() end, desc = "Toggle Debugger UI" }
|
||||
maps.n["<leader>Dh"] = { function() require("dap.ui.widgets").hover() end, desc = "Debugger Hover" }
|
||||
end
|
||||
end
|
||||
|
||||
-- Stay in indent mode
|
||||
maps.v["<"] = { "<gv", desc = "unindent line" }
|
||||
maps.v[">"] = { ">gv", desc = "indent line" }
|
||||
|
||||
-- Improved Terminal Navigation
|
||||
maps.t["<C-h>"] = { "<c-\\><c-n><c-w>h", desc = "Terminal left window navigation" }
|
||||
maps.t["<C-j>"] = { "<c-\\><c-n><c-w>j", desc = "Terminal down window navigation" }
|
||||
maps.t["<C-k>"] = { "<c-\\><c-n><c-w>k", desc = "Terminal up window navigation" }
|
||||
maps.t["<C-l>"] = { "<c-\\><c-n><c-w>l", desc = "Terminal right window navigation" }
|
||||
|
||||
-- Custom menu for modification of the user experience
|
||||
if is_available "nvim-autopairs" then
|
||||
maps.n["<leader>ua"] = { function() astronvim.ui.toggle_autopairs() end, desc = "Toggle autopairs" }
|
||||
end
|
||||
maps.n["<leader>ub"] = { function() astronvim.ui.toggle_background() end, desc = "Toggle background" }
|
||||
if is_available "nvim-cmp" then
|
||||
maps.n["<leader>uc"] = { function() astronvim.ui.toggle_cmp() end, desc = "Toggle autocompletion" }
|
||||
end
|
||||
if is_available "nvim-colorizer.lua" then
|
||||
maps.n["<leader>uC"] = { "<cmd>ColorizerToggle<cr>", desc = "Toggle color highlight" }
|
||||
end
|
||||
maps.n["<leader>uS"] = { function() astronvim.ui.toggle_conceal() end, desc = "Toggle conceal" }
|
||||
maps.n["<leader>ud"] = { function() astronvim.ui.toggle_diagnostics() end, desc = "Toggle diagnostics" }
|
||||
maps.n["<leader>ug"] = { function() astronvim.ui.toggle_signcolumn() end, desc = "Toggle signcolumn" }
|
||||
maps.n["<leader>ui"] = { function() astronvim.ui.set_indent() end, desc = "Change indent setting" }
|
||||
maps.n["<leader>ul"] = { function() astronvim.ui.toggle_statusline() end, desc = "Toggle statusline" }
|
||||
maps.n["<leader>un"] = { function() astronvim.ui.change_number() end, desc = "Change line numbering" }
|
||||
maps.n["<leader>us"] = { function() astronvim.ui.toggle_spell() end, desc = "Toggle spellcheck" }
|
||||
maps.n["<leader>up"] = { function() astronvim.ui.toggle_paste() end, desc = "Toggle paste mode" }
|
||||
maps.n["<leader>ut"] = { function() astronvim.ui.toggle_tabline() end, desc = "Toggle tabline" }
|
||||
maps.n["<leader>uu"] = { function() astronvim.ui.toggle_url_match() end, desc = "Toggle URL highlight" }
|
||||
maps.n["<leader>uw"] = { function() astronvim.ui.toggle_wrap() end, desc = "Toggle wrap" }
|
||||
maps.n["<leader>uy"] = { function() astronvim.ui.toggle_syntax() end, desc = "Toggle syntax highlight" }
|
||||
maps.n["<leader>uN"] = { function() astronvim.ui.toggle_ui_notifications() end, desc = "Toggle UI notifications" }
|
||||
|
||||
astronvim.set_mappings(astronvim.user_plugin_opts("mappings", maps))
|
||||
@@ -0,0 +1,72 @@
|
||||
vim.opt.shortmess:append { s = true, I = true } -- disable startup message
|
||||
astronvim.vim_opts(astronvim.user_plugin_opts("options", {
|
||||
opt = {
|
||||
backspace = vim.opt.backspace + { "nostop" }, -- Don't stop backspace at insert
|
||||
clipboard = "unnamedplus", -- Connection to the system clipboard
|
||||
cmdheight = 0, -- hide command line unless needed
|
||||
completeopt = { "menuone", "noselect" }, -- Options for insert mode completion
|
||||
copyindent = true, -- Copy the previous indentation on autoindenting
|
||||
cursorline = true, -- Highlight the text line of the cursor
|
||||
expandtab = true, -- Enable the use of space in tab
|
||||
fileencoding = "utf-8", -- File content encoding for the buffer
|
||||
fillchars = { eob = " " }, -- Disable `~` on nonexistent lines
|
||||
history = 100, -- Number of commands to remember in a history table
|
||||
ignorecase = true, -- Case insensitive searching
|
||||
laststatus = 3, -- globalstatus
|
||||
mouse = "a", -- Enable mouse support
|
||||
number = true, -- Show numberline
|
||||
preserveindent = true, -- Preserve indent structure as much as possible
|
||||
pumheight = 10, -- Height of the pop up menu
|
||||
relativenumber = true, -- Show relative numberline
|
||||
scrolloff = 8, -- Number of lines to keep above and below the cursor
|
||||
shiftwidth = 2, -- Number of space inserted for indentation
|
||||
showmode = false, -- Disable showing modes in command line
|
||||
showtabline = 2, -- always display tabline
|
||||
sidescrolloff = 8, -- Number of columns to keep at the sides of the cursor
|
||||
signcolumn = "yes", -- Always show the sign column
|
||||
smartcase = true, -- Case sensitivie searching
|
||||
splitbelow = true, -- Splitting a new window below the current one
|
||||
splitright = true, -- Splitting a new window at the right of the current one
|
||||
tabstop = 2, -- Number of space in a tab
|
||||
termguicolors = true, -- Enable 24-bit RGB color in the TUI
|
||||
timeoutlen = 300, -- Length of time to wait for a mapped sequence
|
||||
undofile = true, -- Enable persistent undo
|
||||
updatetime = 300, -- Length of time to wait before triggering the plugin
|
||||
wrap = false, -- Disable wrapping of lines longer than the width of window
|
||||
writebackup = false, -- Disable making a backup before overwriting a file
|
||||
},
|
||||
g = {
|
||||
highlighturl_enabled = true, -- highlight URLs by default
|
||||
mapleader = " ", -- set leader key
|
||||
zipPlugin = false, -- disable zip
|
||||
load_black = false, -- disable black
|
||||
loaded_2html_plugin = true, -- disable 2html
|
||||
loaded_getscript = true, -- disable getscript
|
||||
loaded_getscriptPlugin = true, -- disable getscript
|
||||
loaded_gzip = true, -- disable gzip
|
||||
loaded_logipat = true, -- disable logipat
|
||||
loaded_matchit = true, -- disable matchit
|
||||
loaded_netrwFileHandlers = true, -- disable netrw
|
||||
loaded_netrwPlugin = true, -- disable netrw
|
||||
loaded_netrwSettngs = true, -- disable netrw
|
||||
loaded_remote_plugins = true, -- disable remote plugins
|
||||
loaded_tar = true, -- disable tar
|
||||
loaded_tarPlugin = true, -- disable tar
|
||||
loaded_zip = true, -- disable zip
|
||||
loaded_zipPlugin = true, -- disable zip
|
||||
loaded_vimball = true, -- disable vimball
|
||||
loaded_vimballPlugin = true, -- disable vimball
|
||||
autoformat_enabled = true, -- enable or disable auto formatting at start (lsp.formatting.format_on_save must be enabled)
|
||||
lsp_handlers_enabled = true, -- enable or disable default vim.lsp.handlers (hover and signatureHelp)
|
||||
cmp_enabled = true, -- enable completion at start
|
||||
autopairs_enabled = true, -- enable autopairs at start
|
||||
diagnostics_enabled = true, -- enable diagnostics at start
|
||||
status_diagnostics_enabled = true, -- enable diagnostics in statusline
|
||||
icons_enabled = true, -- disable icons in the UI (disable if no nerd font is available)
|
||||
ui_notifications_enabled = true, -- disable notifications when toggling UI elements
|
||||
heirline_bufferline = false, -- enable heirline bufferline (TODO v3: remove this option and make it default)
|
||||
},
|
||||
t = {
|
||||
bufs = vim.tbl_filter(astronvim.is_valid_buffer, vim.api.nvim_list_bufs()), -- buffers in tab
|
||||
},
|
||||
}))
|
||||
@@ -0,0 +1,375 @@
|
||||
local astro_plugins = {
|
||||
-- Plugin manager
|
||||
["wbthomason/packer.nvim"] = {
|
||||
setup = function()
|
||||
astronvim.lazy_load_commands("packer.nvim", {
|
||||
"PackerSnapshot",
|
||||
"PackerSnapshotRollback",
|
||||
"PackerSnapshotDelete",
|
||||
"PackerInstall",
|
||||
"PackerUpdate",
|
||||
"PackerSync",
|
||||
"PackerClean",
|
||||
"PackerCompile",
|
||||
"PackerStatus",
|
||||
"PackerProfile",
|
||||
"PackerLoad",
|
||||
})
|
||||
end,
|
||||
config = function() require "core.plugins" end,
|
||||
},
|
||||
|
||||
-- Optimiser
|
||||
["lewis6991/impatient.nvim"] = {},
|
||||
|
||||
-- Lua functions
|
||||
["nvim-lua/plenary.nvim"] = { module = "plenary" },
|
||||
|
||||
-- Indent detection
|
||||
["Darazaki/indent-o-matic"] = {
|
||||
opt = true,
|
||||
setup = function() table.insert(astronvim.file_plugins, "indent-o-matic") end,
|
||||
config = function() require "configs.indent-o-matic" end,
|
||||
},
|
||||
|
||||
-- Notification Enhancer
|
||||
["rcarriga/nvim-notify"] = {
|
||||
module = "notify",
|
||||
setup = function() astronvim.load_plugin_with_func("nvim-notify", vim, "notify") end,
|
||||
config = function() require "configs.notify" end,
|
||||
},
|
||||
|
||||
-- Neovim UI Enhancer
|
||||
["stevearc/dressing.nvim"] = {
|
||||
opt = true,
|
||||
setup = function() astronvim.load_plugin_with_func("dressing.nvim", vim.ui, { "input", "select" }) end,
|
||||
config = function() require "configs.dressing" end,
|
||||
},
|
||||
|
||||
-- Smarter Splits
|
||||
["mrjones2014/smart-splits.nvim"] = {
|
||||
module = "smart-splits",
|
||||
config = function() require "configs.smart-splits" end,
|
||||
},
|
||||
|
||||
-- Icons
|
||||
["nvim-tree/nvim-web-devicons"] = {
|
||||
disable = not vim.g.icons_enabled,
|
||||
module = "nvim-web-devicons",
|
||||
config = function() require "configs.nvim-web-devicons" end,
|
||||
},
|
||||
|
||||
-- LSP Icons
|
||||
["onsails/lspkind.nvim"] = {
|
||||
disable = not vim.g.icons_enabled,
|
||||
module = "lspkind",
|
||||
config = function() require "configs.lspkind" end,
|
||||
},
|
||||
|
||||
-- Bufferline
|
||||
["akinsho/bufferline.nvim"] = { -- TODO v3: remove this plugin
|
||||
disable = vim.g.heirline_bufferline,
|
||||
module = "bufferline",
|
||||
event = "UIEnter",
|
||||
config = function() require "configs.bufferline" end,
|
||||
},
|
||||
|
||||
-- Better buffer closing
|
||||
["famiu/bufdelete.nvim"] = {
|
||||
module = "bufdelete",
|
||||
setup = function() astronvim.lazy_load_commands("bufdelete.nvim", { "Bdelete", "Bwipeout" }) end,
|
||||
},
|
||||
|
||||
["s1n7ax/nvim-window-picker"] = {
|
||||
tag = "v1.*",
|
||||
module = "window-picker",
|
||||
config = function() require "configs.window-picker" end,
|
||||
},
|
||||
|
||||
-- File explorer
|
||||
["nvim-neo-tree/neo-tree.nvim"] = {
|
||||
branch = "v2.x",
|
||||
module = "neo-tree",
|
||||
requires = { { "MunifTanjim/nui.nvim", module = "nui" } },
|
||||
setup = function()
|
||||
astronvim.lazy_load_commands("neo-tree.nvim", "Neotree")
|
||||
vim.g.neo_tree_remove_legacy_commands = true
|
||||
end,
|
||||
config = function() require "configs.neo-tree" end,
|
||||
},
|
||||
|
||||
-- Statusline
|
||||
["rebelot/heirline.nvim"] = { event = "VimEnter", config = function() require "configs.heirline" end },
|
||||
|
||||
-- Syntax highlighting
|
||||
["nvim-treesitter/nvim-treesitter"] = {
|
||||
module = "nvim-treesitter",
|
||||
setup = function()
|
||||
table.insert(astronvim.file_plugins, "nvim-treesitter")
|
||||
astronvim.lazy_load_commands("nvim-treesitter", {
|
||||
"TSBufDisable",
|
||||
"TSBufEnable",
|
||||
"TSBufToggle",
|
||||
"TSDisable",
|
||||
"TSEnable",
|
||||
"TSToggle",
|
||||
"TSInstall",
|
||||
"TSInstallInfo",
|
||||
"TSInstallSync",
|
||||
"TSModuleInfo",
|
||||
"TSUninstall",
|
||||
"TSUpdate",
|
||||
"TSUpdateSync",
|
||||
})
|
||||
end,
|
||||
run = function() require("nvim-treesitter.install").update { with_sync = true }() end,
|
||||
config = function() require "configs.treesitter" end,
|
||||
},
|
||||
|
||||
-- Parenthesis highlighting
|
||||
["p00f/nvim-ts-rainbow"] = { after = "nvim-treesitter" },
|
||||
|
||||
-- Autoclose tags
|
||||
["windwp/nvim-ts-autotag"] = { after = "nvim-treesitter" },
|
||||
|
||||
-- Context based commenting
|
||||
["JoosepAlviste/nvim-ts-context-commentstring"] = { after = "nvim-treesitter" },
|
||||
|
||||
-- Snippet collection
|
||||
["rafamadriz/friendly-snippets"] = { opt = true },
|
||||
|
||||
-- Snippet engine
|
||||
["L3MON4D3/LuaSnip"] = {
|
||||
module = "luasnip",
|
||||
wants = "friendly-snippets",
|
||||
config = function() require "configs.luasnip" end,
|
||||
},
|
||||
|
||||
-- Completion engine
|
||||
["hrsh7th/nvim-cmp"] = { event = "InsertEnter", config = function() require "configs.cmp" end },
|
||||
|
||||
-- Snippet completion source
|
||||
["saadparwaiz1/cmp_luasnip"] = {
|
||||
after = "nvim-cmp",
|
||||
config = function() astronvim.add_user_cmp_source "luasnip" end,
|
||||
},
|
||||
|
||||
-- Buffer completion source
|
||||
["hrsh7th/cmp-buffer"] = { after = "nvim-cmp", config = function() astronvim.add_user_cmp_source "buffer" end },
|
||||
|
||||
-- Path completion source
|
||||
["hrsh7th/cmp-path"] = { after = "nvim-cmp", config = function() astronvim.add_user_cmp_source "path" end },
|
||||
|
||||
-- LSP completion source
|
||||
["hrsh7th/cmp-nvim-lsp"] = { after = "nvim-cmp", config = function() astronvim.add_user_cmp_source "nvim_lsp" end },
|
||||
|
||||
-- Built-in LSP
|
||||
["neovim/nvim-lspconfig"] = {
|
||||
module = "lspconfig",
|
||||
setup = function() table.insert(astronvim.file_plugins, "nvim-lspconfig") end,
|
||||
config = function() require "configs.lspconfig" end,
|
||||
},
|
||||
|
||||
-- Formatting and linting
|
||||
["jose-elias-alvarez/null-ls.nvim"] = {
|
||||
module = "null-ls",
|
||||
setup = function() table.insert(astronvim.file_plugins, "null-ls.nvim") end,
|
||||
config = function() require "configs.null-ls" end,
|
||||
},
|
||||
|
||||
-- Debugger
|
||||
["mfussenegger/nvim-dap"] = {
|
||||
disable = vim.fn.has "win32" == 1,
|
||||
module = "dap",
|
||||
config = function() require "configs.dap" end,
|
||||
},
|
||||
|
||||
-- Debugger UI
|
||||
["rcarriga/nvim-dap-ui"] = {
|
||||
disable = vim.fn.has "win32" == 1,
|
||||
after = "nvim-dap",
|
||||
config = function() require "configs.dapui" end,
|
||||
},
|
||||
|
||||
-- Package Manager
|
||||
["williamboman/mason.nvim"] = {
|
||||
module = "mason",
|
||||
cmd = {
|
||||
"Mason",
|
||||
"MasonInstall",
|
||||
"MasonUninstall",
|
||||
"MasonUninstallAll",
|
||||
"MasonLog",
|
||||
"MasonUpdate", -- astronvim command
|
||||
"MasonUpdateAll", -- astronvim command
|
||||
},
|
||||
config = function()
|
||||
require "configs.mason"
|
||||
vim.tbl_map(function(plugin) pcall(require, plugin) end, { "lspconfig", "null-ls", "dap" })
|
||||
end,
|
||||
},
|
||||
|
||||
-- LSP manager
|
||||
["williamboman/mason-lspconfig.nvim"] = {
|
||||
after = "nvim-lspconfig",
|
||||
config = function() require "configs.mason-lspconfig" end,
|
||||
},
|
||||
|
||||
-- null-ls manager
|
||||
["jayp0521/mason-null-ls.nvim"] = { after = "null-ls.nvim", config = function() require "configs.mason-null-ls" end },
|
||||
|
||||
-- dap manager
|
||||
["jayp0521/mason-nvim-dap.nvim"] = {
|
||||
disable = vim.fn.has "win32" == 1,
|
||||
after = "nvim-dap",
|
||||
config = function() require "configs.mason-nvim-dap" end,
|
||||
},
|
||||
|
||||
-- LSP symbols
|
||||
["stevearc/aerial.nvim"] = {
|
||||
module = "aerial",
|
||||
after = { "nvim-treesitter", "nvim-lspconfig" },
|
||||
ft = { "man", "markdown" },
|
||||
config = function() require "configs.aerial" end,
|
||||
},
|
||||
|
||||
-- Fuzzy finder
|
||||
["nvim-telescope/telescope.nvim"] = {
|
||||
module = "telescope",
|
||||
setup = function() astronvim.lazy_load_commands("telescope.nvim", "Telescope") end,
|
||||
config = function() require "configs.telescope" end,
|
||||
},
|
||||
|
||||
-- Fuzzy finder syntax support
|
||||
["nvim-telescope/telescope-fzf-native.nvim"] = {
|
||||
after = "telescope.nvim",
|
||||
disable = vim.fn.executable "make" == 0,
|
||||
run = "make",
|
||||
config = function() require("telescope").load_extension "fzf" end,
|
||||
},
|
||||
|
||||
-- Git integration
|
||||
["lewis6991/gitsigns.nvim"] = {
|
||||
disable = vim.fn.executable "git" == 0,
|
||||
ft = "gitcommit",
|
||||
setup = function() table.insert(astronvim.git_plugins, "gitsigns.nvim") end,
|
||||
config = function() require "configs.gitsigns" end,
|
||||
},
|
||||
|
||||
-- Start screen
|
||||
["goolord/alpha-nvim"] = {
|
||||
module = "alpha",
|
||||
setup = function() astronvim.lazy_load_commands("alpha-nvim", "Alpha") end,
|
||||
config = function() require "configs.alpha" end,
|
||||
},
|
||||
|
||||
-- Color highlighting
|
||||
["NvChad/nvim-colorizer.lua"] = {
|
||||
opt = true,
|
||||
setup = function()
|
||||
astronvim.lazy_load_commands(
|
||||
"nvim-colorizer.lua",
|
||||
{ "ColorizerToggle", "ColorizerAttachToBuffer", "ColorizerDetachFromBuffer", "ColorizerReloadAllBuffers" }
|
||||
)
|
||||
table.insert(astronvim.file_plugins, "nvim-colorizer.lua")
|
||||
end,
|
||||
config = function() require "configs.colorizer" end,
|
||||
},
|
||||
|
||||
-- Autopairs
|
||||
["windwp/nvim-autopairs"] = { event = "InsertEnter", config = function() require "configs.autopairs" end },
|
||||
|
||||
-- Terminal
|
||||
["akinsho/toggleterm.nvim"] = {
|
||||
module = "toggleterm",
|
||||
setup = function() astronvim.lazy_load_commands("toggleterm.nvim", { "ToggleTerm", "TermExec" }) end,
|
||||
config = function() require "configs.toggleterm" end,
|
||||
},
|
||||
|
||||
-- Commenting
|
||||
["numToStr/Comment.nvim"] = {
|
||||
module = "Comment",
|
||||
keys = { "gc", "gb" },
|
||||
config = function() require "configs.Comment" end,
|
||||
},
|
||||
|
||||
-- Indentation
|
||||
["lukas-reineke/indent-blankline.nvim"] = {
|
||||
opt = true,
|
||||
setup = function() table.insert(astronvim.file_plugins, "indent-blankline.nvim") end,
|
||||
config = function() require "configs.indent-line" end,
|
||||
},
|
||||
|
||||
-- Keymaps popup
|
||||
["folke/which-key.nvim"] = { module = "which-key", config = function() require "configs.which-key" end },
|
||||
|
||||
-- Smooth escaping
|
||||
["max397574/better-escape.nvim"] = {
|
||||
event = "InsertCharPre",
|
||||
config = function() require "configs.better_escape" end,
|
||||
},
|
||||
|
||||
-- Get extra JSON schemas
|
||||
["b0o/SchemaStore.nvim"] = { module = "schemastore" },
|
||||
|
||||
-- Session manager
|
||||
["Shatur/neovim-session-manager"] = {
|
||||
module = "session_manager",
|
||||
event = "BufWritePost",
|
||||
setup = function() astronvim.lazy_load_commands("neovim-session-manager", "SessionManager") end,
|
||||
config = function() require "configs.session_manager" end,
|
||||
},
|
||||
}
|
||||
|
||||
if astronvim.updater.snapshot then
|
||||
for plugin, options in pairs(astro_plugins) do
|
||||
local pin = astronvim.updater.snapshot[plugin:match "/([^/]*)$"]
|
||||
if pin and pin.commit then
|
||||
options.commit = pin.commit
|
||||
options.tag = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local user_plugin_opts = astronvim.user_plugin_opts
|
||||
local status_ok, packer = pcall(require, "packer")
|
||||
if status_ok then
|
||||
packer.startup {
|
||||
function(use)
|
||||
local plugins = user_plugin_opts("plugins.init", astro_plugins)
|
||||
for key, plugin in pairs(plugins) do
|
||||
if type(key) == "string" and not plugin[1] then plugin[1] = key end
|
||||
if key == "williamboman/mason.nvim" and plugin.cmd then
|
||||
for mason_plugin, commands in pairs { -- lazy load mason plugin commands with Mason
|
||||
["jayp0521/mason-null-ls.nvim"] = { "NullLsInstall", "NullLsUninstall" },
|
||||
["williamboman/mason-lspconfig.nvim"] = { "LspInstall", "LspUninstall" },
|
||||
["jayp0521/mason-nvim-dap.nvim"] = { "DapInstall", "DapUninstall" },
|
||||
} do
|
||||
if plugins[mason_plugin] and not plugins[mason_plugin].disable then
|
||||
vim.list_extend(plugin.cmd, commands)
|
||||
end
|
||||
end
|
||||
end
|
||||
use(plugin)
|
||||
end
|
||||
end,
|
||||
config = user_plugin_opts("plugins.packer", {
|
||||
compile_path = astronvim.default_compile_path,
|
||||
display = {
|
||||
open_fn = function() return require("packer.util").float { border = "rounded" } end,
|
||||
},
|
||||
profile = {
|
||||
enable = true,
|
||||
threshold = 0.0001,
|
||||
},
|
||||
git = {
|
||||
clone_timeout = 300,
|
||||
subcommands = {
|
||||
update = "pull --rebase",
|
||||
},
|
||||
},
|
||||
auto_clean = true,
|
||||
compile_on_sync = true,
|
||||
}),
|
||||
}
|
||||
end
|
||||
@@ -0,0 +1,157 @@
|
||||
--- ### Git LUA API
|
||||
--
|
||||
-- This module can be loaded with `local git = require "core.utils.git"`
|
||||
--
|
||||
-- @module core.utils.git
|
||||
-- @copyright 2022
|
||||
-- @license GNU General Public License v3.0
|
||||
|
||||
local git = { url = "https://github.com/" }
|
||||
|
||||
--- Run a git command from the AstroNvim installation directory
|
||||
-- @param args the git arguments
|
||||
-- @return the result of the command or nil if unsuccessful
|
||||
function git.cmd(args, ...) return astronvim.cmd("git -C " .. astronvim.install.home .. " " .. args, ...) end
|
||||
|
||||
--- Check if the AstroNvim is able to reach the `git` command
|
||||
-- @return the result of running `git --help`
|
||||
function git.available() return vim.fn.executable "git" == 1 end
|
||||
|
||||
--- Check if the AstroNvim home is a git repo
|
||||
-- @return the result of the command
|
||||
function git.is_repo() return git.cmd("rev-parse --is-inside-work-tree", false) end
|
||||
|
||||
--- Fetch git remote
|
||||
-- @param remote the remote to fetch
|
||||
-- @return the result of the command
|
||||
function git.fetch(remote, ...) return git.cmd("fetch " .. remote, ...) end
|
||||
|
||||
--- Pull the git repo
|
||||
-- @return the result of the command
|
||||
function git.pull(...) return git.cmd("pull --rebase", ...) end
|
||||
|
||||
--- Checkout git target
|
||||
-- @param dest the target to checkout
|
||||
-- @return the result of the command
|
||||
function git.checkout(dest, ...) return git.cmd("checkout " .. dest, ...) end
|
||||
|
||||
--- Hard reset to a git target
|
||||
-- @param dest the target to hard reset to
|
||||
-- @return the result of the command
|
||||
function git.hard_reset(dest, ...) return git.cmd("reset --hard " .. dest, ...) end
|
||||
|
||||
--- Check if a branch contains a commit
|
||||
-- @param remote the git remote to check
|
||||
-- @param branch the git branch to check
|
||||
-- @param commit the git commit to check for
|
||||
-- @return the result of the command
|
||||
function git.branch_contains(remote, branch, commit, ...)
|
||||
return git.cmd("merge-base --is-ancestor " .. commit .. " " .. remote .. "/" .. branch, ...) ~= nil
|
||||
end
|
||||
|
||||
--- Add a git remote
|
||||
-- @param remote the remote to add
|
||||
-- @param url the url of the remote
|
||||
-- @return the result of the command
|
||||
function git.remote_add(remote, url, ...) return git.cmd("remote add " .. remote .. " " .. url, ...) end
|
||||
|
||||
--- Update a git remote URL
|
||||
-- @param remote the remote to update
|
||||
-- @param url the new URL of the remote
|
||||
-- @return the result of the command
|
||||
function git.remote_update(remote, url, ...) return git.cmd("remote set-url " .. remote .. " " .. url, ...) end
|
||||
|
||||
--- Get the URL of a given git remote
|
||||
-- @param remote the remote to get the URL of
|
||||
-- @return the url of the remote
|
||||
function git.remote_url(remote, ...) return astronvim.trim_or_nil(git.cmd("remote get-url " .. remote, ...)) end
|
||||
|
||||
--- Get the current version with git describe including tags
|
||||
-- @return the current git describe string
|
||||
function git.current_version(...) return astronvim.trim_or_nil(git.cmd("describe --tags", ...)) end
|
||||
|
||||
--- Get the current branch
|
||||
-- @return the branch of the AstroNvim installation
|
||||
function git.current_branch(...) return astronvim.trim_or_nil(git.cmd("rev-parse --abbrev-ref HEAD", ...)) end
|
||||
|
||||
--- Get the current head of the git repo
|
||||
-- @return the head string
|
||||
function git.local_head(...) return astronvim.trim_or_nil(git.cmd("rev-parse HEAD", ...)) end
|
||||
|
||||
--- Get the current head of a git remote
|
||||
-- @param remote the remote to check
|
||||
-- @param branch the branch to check
|
||||
-- @return the head string of the remote branch
|
||||
function git.remote_head(remote, branch, ...)
|
||||
return astronvim.trim_or_nil(git.cmd("rev-list -n 1 " .. remote .. "/" .. branch, ...))
|
||||
end
|
||||
|
||||
--- Get the commit hash of a given tag
|
||||
-- @param tag the tag to resolve
|
||||
-- @return the commit hash of a git tag
|
||||
function git.tag_commit(tag, ...) return astronvim.trim_or_nil(git.cmd("rev-list -n 1 " .. tag, ...)) end
|
||||
|
||||
--- Get the commit log between two commit hashes
|
||||
-- @param start_hash the start commit hash
|
||||
-- @param end_hash the end commit hash
|
||||
-- @return an array like table of commit messages
|
||||
function git.get_commit_range(start_hash, end_hash, ...)
|
||||
local range = ""
|
||||
if start_hash and end_hash then range = start_hash .. ".." .. end_hash end
|
||||
local log = git.cmd('log --no-merges --pretty="format:[%h] %s" ' .. range, ...)
|
||||
return log and vim.fn.split(log, "\n") or {}
|
||||
end
|
||||
|
||||
--- Get a list of all tags with a regex filter
|
||||
-- @param search a regex to search the tags with (defaults to "v*" for version tags)
|
||||
-- @return an array like table of tags that match the search
|
||||
function git.get_versions(search, ...)
|
||||
local tags = git.cmd('tag -l --sort=version:refname "' .. (search == "latest" and "v*" or search) .. '"', ...)
|
||||
return tags and vim.fn.split(tags, "\n") or {}
|
||||
end
|
||||
|
||||
--- Get the latest version of a list of versions
|
||||
-- @param versions a list of versions to search (defaults to all versions available)
|
||||
-- @return the latest version from the array
|
||||
function git.latest_version(versions, ...)
|
||||
if not versions then versions = git.get_versions(...) end
|
||||
return versions[#versions]
|
||||
end
|
||||
|
||||
--- Parse a remote url
|
||||
-- @param str the remote to parse to a full git url
|
||||
-- @return the full git url for the given remote string
|
||||
function git.parse_remote_url(str)
|
||||
return vim.fn.match(str, astronvim.url_matcher) == -1
|
||||
and git.url .. str .. (vim.fn.match(str, "/") == -1 and "/AstroNvim.git" or ".git")
|
||||
or str
|
||||
end
|
||||
|
||||
--- Check if a Conventional Commit commit message is breaking or not
|
||||
-- @param commit a commit message
|
||||
-- @return boolean true if the message is breaking, false if the commit message is not breaking
|
||||
function git.is_breaking(commit) return vim.fn.match(commit, "\\[.*\\]\\s\\+\\w\\+\\((\\w\\+)\\)\\?!:") ~= -1 end
|
||||
|
||||
--- Get a list of breaking commits from commit messages using Conventional Commit standard
|
||||
-- @param commits an array like table of commit messages
|
||||
-- @return an array like table of commits that are breaking
|
||||
function git.breaking_changes(commits) return vim.tbl_filter(git.is_breaking, commits) end
|
||||
|
||||
--- Generate a table of commit messages for neovim's echo API with highlighting
|
||||
-- @param commits an array like table of commit messages
|
||||
-- @return an array like table of echo messages to provide to nvim_echo or astronvim.echo
|
||||
function git.pretty_changelog(commits)
|
||||
local changelog = {}
|
||||
for _, commit in ipairs(commits) do
|
||||
local hash, type, msg = commit:match "(%[.*%])(.*:)(.*)"
|
||||
if hash and type and msg then
|
||||
vim.list_extend(
|
||||
changelog,
|
||||
{ { hash, "DiffText" }, { type, git.is_breaking(commit) and "DiffDelete" or "DiffChange" }, { msg }, { "\n" } }
|
||||
)
|
||||
end
|
||||
end
|
||||
return changelog
|
||||
end
|
||||
|
||||
return git
|
||||
@@ -0,0 +1,606 @@
|
||||
--- ### AstroNvim Utilities
|
||||
--
|
||||
-- This module is automatically loaded by AstroNvim on during it's initialization into global variable `astronvim`
|
||||
--
|
||||
-- This module can also be manually loaded with `local astronvim = require "core.utils"`
|
||||
--
|
||||
-- @module core.utils
|
||||
-- @copyright 2022
|
||||
-- @license GNU General Public License v3.0
|
||||
|
||||
_G.astronvim = {}
|
||||
local stdpath = vim.fn.stdpath
|
||||
local tbl_insert = table.insert
|
||||
local map = vim.keymap.set
|
||||
|
||||
--- installation details from external installers
|
||||
astronvim.install = astronvim_installation or { home = stdpath "config" }
|
||||
--- external astronvim configuration folder
|
||||
astronvim.install.config = stdpath("config"):gsub("nvim$", "astronvim")
|
||||
vim.opt.rtp:append(astronvim.install.config)
|
||||
local supported_configs = { astronvim.install.home, astronvim.install.config }
|
||||
|
||||
--- Looks to see if a module path references a lua file in a configuration folder and tries to load it. If there is an error loading the file, write an error and continue
|
||||
-- @param module the module path to try and load
|
||||
-- @return the loaded module if successful or nil
|
||||
local function load_module_file(module)
|
||||
-- placeholder for final return value
|
||||
local found_module = nil
|
||||
-- search through each of the supported configuration locations
|
||||
for _, config_path in ipairs(supported_configs) do
|
||||
-- convert the module path to a file path (example user.init -> user/init.lua)
|
||||
local module_path = config_path .. "/lua/" .. module:gsub("%.", "/") .. ".lua"
|
||||
-- check if there is a readable file, if so, set it as found
|
||||
if vim.fn.filereadable(module_path) == 1 then found_module = module_path end
|
||||
end
|
||||
-- if we found a readable lua file, try to load it
|
||||
if found_module then
|
||||
-- try to load the file
|
||||
local status_ok, loaded_module = pcall(require, module)
|
||||
-- if successful at loading, set the return variable
|
||||
if status_ok then
|
||||
found_module = loaded_module
|
||||
-- if unsuccessful, throw an error
|
||||
else
|
||||
vim.api.nvim_err_writeln("Error loading file: " .. found_module .. "\n\n" .. loaded_module)
|
||||
end
|
||||
end
|
||||
-- return the loaded module or nil if no file found
|
||||
return found_module
|
||||
end
|
||||
|
||||
--- user settings from the base `user/init.lua` file
|
||||
astronvim.user_settings = load_module_file "user.init"
|
||||
--- default packer compilation location to be used in bootstrapping and packer setup call
|
||||
astronvim.default_compile_path = stdpath "data" .. "/packer_compiled.lua"
|
||||
--- table of user created terminals
|
||||
astronvim.user_terminals = {}
|
||||
--- table of plugins to load with git
|
||||
astronvim.git_plugins = {}
|
||||
--- table of plugins to load when file opened
|
||||
astronvim.file_plugins = {}
|
||||
--- regex used for matching a valid URL/URI string
|
||||
astronvim.url_matcher =
|
||||
"\\v\\c%(%(h?ttps?|ftp|file|ssh|git)://|[a-z]+[@][a-z]+[.][a-z]+:)%([&:#*@~%_\\-=?!+;/0-9a-z]+%(%([.;/?]|[.][.]+)[&:#*@~%_\\-=?!+/0-9a-z]+|:\\d+|,%(%(%(h?ttps?|ftp|file|ssh|git)://|[a-z]+[@][a-z]+[.][a-z]+:)@![0-9a-z]+))*|\\([&:#*@~%_\\-=?!+;/.0-9a-z]*\\)|\\[[&:#*@~%_\\-=?!+;/.0-9a-z]*\\]|\\{%([&:#*@~%_\\-=?!+;/.0-9a-z]*|\\{[&:#*@~%_\\-=?!+;/.0-9a-z]*})\\})+"
|
||||
|
||||
--- Main configuration engine logic for extending a default configuration table with either a function override or a table to merge into the default option
|
||||
-- @function astronvim.func_or_extend
|
||||
-- @param overrides the override definition, either a table or a function that takes a single parameter of the original table
|
||||
-- @param default the default configuration table
|
||||
-- @param extend boolean value to either extend the default or simply overwrite it if an override is provided
|
||||
-- @return the new configuration table
|
||||
local function func_or_extend(overrides, default, extend)
|
||||
-- if we want to extend the default with the provided override
|
||||
if extend then
|
||||
-- if the override is a table, use vim.tbl_deep_extend
|
||||
if type(overrides) == "table" then
|
||||
default = astronvim.default_tbl(overrides, default)
|
||||
-- if the override is a function, call it with the default and overwrite default with the return value
|
||||
elseif type(overrides) == "function" then
|
||||
default = overrides(default)
|
||||
end
|
||||
-- if extend is set to false and we have a provided override, simply override the default
|
||||
elseif overrides ~= nil then
|
||||
default = overrides
|
||||
end
|
||||
-- return the modified default table
|
||||
return default
|
||||
end
|
||||
|
||||
--- Merge extended options with a default table of options
|
||||
-- @param opts the new options that should be merged with the default table
|
||||
-- @param default the default table that you want to merge into
|
||||
-- @return the merged table
|
||||
function astronvim.default_tbl(opts, default)
|
||||
opts = opts or {}
|
||||
return default and vim.tbl_deep_extend("force", default, opts) or opts
|
||||
end
|
||||
|
||||
--- Call function if a condition is met
|
||||
-- @param func the function to run
|
||||
-- @param condition a boolean value of whether to run the function or not
|
||||
function astronvim.conditional_func(func, condition, ...)
|
||||
-- if the condition is true or no condition is provided, evaluate the function with the rest of the parameters and return the result
|
||||
if (condition == nil or condition) and type(func) == "function" then return func(...) end
|
||||
end
|
||||
|
||||
--- Get highlight properties for a given highlight name
|
||||
-- @param name highlight group name
|
||||
-- @return table of highlight group properties
|
||||
function astronvim.get_hlgroup(name, fallback)
|
||||
if vim.fn.hlexists(name) == 1 then
|
||||
local hl = vim.api.nvim_get_hl_by_name(name, vim.o.termguicolors)
|
||||
if not hl["foreground"] then hl["foreground"] = "NONE" end
|
||||
if not hl["background"] then hl["background"] = "NONE" end
|
||||
hl.fg, hl.bg, hl.sp = hl.foreground, hl.background, hl.special
|
||||
hl.ctermfg, hl.ctermbg = hl.foreground, hl.background
|
||||
return hl
|
||||
end
|
||||
return fallback
|
||||
end
|
||||
|
||||
--- Trim a string or return nil
|
||||
-- @param str the string to trim
|
||||
-- @return a trimmed version of the string or nil if the parameter isn't a string
|
||||
function astronvim.trim_or_nil(str) return type(str) == "string" and vim.trim(str) or nil end
|
||||
|
||||
--- Add left and/or right padding to a string
|
||||
-- @param str the string to add padding to
|
||||
-- @param padding a table of the format `{ left = 0, right = 0}` that defines the number of spaces to include to the left and the right of the string
|
||||
-- @return the padded string
|
||||
function astronvim.pad_string(str, padding)
|
||||
padding = padding or {}
|
||||
return str and str ~= "" and string.rep(" ", padding.left or 0) .. str .. string.rep(" ", padding.right or 0) or ""
|
||||
end
|
||||
|
||||
--- Initialize icons used throughout the user interface
|
||||
function astronvim.initialize_icons()
|
||||
astronvim.icons = astronvim.user_plugin_opts("icons", require "core.icons.nerd_font")
|
||||
astronvim.text_icons = astronvim.user_plugin_opts("text_icons", require "core.icons.text")
|
||||
end
|
||||
|
||||
--- Get an icon from `lspkind` if it is available and return it
|
||||
-- @param kind the kind of icon in `lspkind` to retrieve
|
||||
-- @return the icon
|
||||
function astronvim.get_icon(kind)
|
||||
local icon_pack = vim.g.icons_enabled and "icons" or "text_icons"
|
||||
if not astronvim[icon_pack] then astronvim.initialize_icons() end
|
||||
return astronvim[icon_pack] and astronvim[icon_pack][kind] or ""
|
||||
end
|
||||
|
||||
--- Serve a notification with a title of AstroNvim
|
||||
-- @param msg the notification body
|
||||
-- @param type the type of the notification (:help vim.log.levels)
|
||||
-- @param opts table of nvim-notify options to use (:help notify-options)
|
||||
function astronvim.notify(msg, type, opts)
|
||||
vim.schedule(function() vim.notify(msg, type, astronvim.default_tbl(opts, { title = "AstroNvim" })) end)
|
||||
end
|
||||
|
||||
--- Trigger an AstroNvim user event
|
||||
-- @param event the event name to be appended to Astro
|
||||
function astronvim.event(event)
|
||||
vim.schedule(function() vim.api.nvim_exec_autocmds("User", { pattern = "Astro" .. event }) end)
|
||||
end
|
||||
|
||||
--- Wrapper function for neovim echo API
|
||||
-- @param messages an array like table where each item is an array like table of strings to echo
|
||||
function astronvim.echo(messages)
|
||||
-- if no parameter provided, echo a new line
|
||||
messages = messages or { { "\n" } }
|
||||
if type(messages) == "table" then vim.api.nvim_echo(messages, false, {}) end
|
||||
end
|
||||
|
||||
--- Echo a message and prompt the user for yes or no response
|
||||
-- @param messages the message to echo
|
||||
-- @return True if the user responded y, False for any other response
|
||||
function astronvim.confirm_prompt(messages)
|
||||
if messages then astronvim.echo(messages) end
|
||||
local confirmed = string.lower(vim.fn.input "(y/n) ") == "y"
|
||||
astronvim.echo()
|
||||
astronvim.echo()
|
||||
return confirmed
|
||||
end
|
||||
|
||||
--- Search the user settings (user/init.lua table) for a table with a module like path string
|
||||
-- @param module the module path like string to look up in the user settings table
|
||||
-- @return the value of the table entry if exists or nil
|
||||
local function user_setting_table(module)
|
||||
-- get the user settings table
|
||||
local settings = astronvim.user_settings or {}
|
||||
-- iterate over the path string split by '.' to look up the table value
|
||||
for tbl in string.gmatch(module, "([^%.]+)") do
|
||||
settings = settings[tbl]
|
||||
-- if key doesn't exist, keep the nil value and stop searching
|
||||
if settings == nil then break end
|
||||
end
|
||||
-- return the found settings
|
||||
return settings
|
||||
end
|
||||
|
||||
--- Check if packer is installed and loadable, if not then install it and make sure it loads
|
||||
function astronvim.initialize_packer()
|
||||
-- try loading packer
|
||||
local packer_path = stdpath "data" .. "/site/pack/packer/opt/packer.nvim"
|
||||
local packer_avail = vim.fn.empty(vim.fn.glob(packer_path)) == 0
|
||||
-- if packer isn't availble, reinstall it
|
||||
if not packer_avail then
|
||||
-- set the location to install packer
|
||||
-- delete the old packer install if one exists
|
||||
vim.fn.delete(packer_path, "rf")
|
||||
-- clone packer
|
||||
vim.fn.system {
|
||||
"git",
|
||||
"clone",
|
||||
"--depth",
|
||||
"1",
|
||||
"https://github.com/wbthomason/packer.nvim",
|
||||
packer_path,
|
||||
}
|
||||
-- add packer and try loading it
|
||||
vim.cmd.packadd "packer.nvim"
|
||||
local packer_loaded, _ = pcall(require, "packer")
|
||||
packer_avail = packer_loaded
|
||||
-- if packer didn't load, print error
|
||||
if not packer_avail then vim.api.nvim_err_writeln("Failed to load packer at:" .. packer_path) end
|
||||
end
|
||||
-- if packer is available, check if there is a compiled packer file
|
||||
if packer_avail then
|
||||
-- try to load the packer compiled file
|
||||
local run_me, _ = loadfile(
|
||||
astronvim.user_plugin_opts("plugins.packer", { compile_path = astronvim.default_compile_path }).compile_path
|
||||
)
|
||||
if run_me then
|
||||
-- if the file loads, run the compiled function
|
||||
run_me()
|
||||
else
|
||||
-- if there is no compiled file, ask user to sync packer
|
||||
require "core.plugins"
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
once = true,
|
||||
pattern = "PackerComplete",
|
||||
callback = function()
|
||||
vim.cmd.bw()
|
||||
vim.tbl_map(require, { "nvim-treesitter", "mason" })
|
||||
astronvim.notify "Mason is installing packages if configured, check status with :Mason"
|
||||
end,
|
||||
})
|
||||
vim.opt.cmdheight = 1
|
||||
vim.notify "Please wait while plugins are installed..."
|
||||
vim.cmd.PackerSync()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function astronvim.lazy_load_commands(plugin, commands)
|
||||
if type(commands) == "string" then commands = { commands } end
|
||||
if astronvim.is_available(plugin) and not packer_plugins[plugin].loaded then
|
||||
for _, command in ipairs(commands) do
|
||||
pcall(
|
||||
vim.cmd,
|
||||
string.format(
|
||||
'command -nargs=* -range -bang -complete=file %s lua require("packer.load")({"%s"}, { cmd = "%s", l1 = <line1>, l2 = <line2>, bang = <q-bang>, args = <q-args>, mods = "<mods>" }, _G.packer_plugins)',
|
||||
command,
|
||||
plugin,
|
||||
command
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Set vim options with a nested table like API with the format vim.<first_key>.<second_key>.<value>
|
||||
-- @param options the nested table of vim options
|
||||
function astronvim.vim_opts(options)
|
||||
for scope, table in pairs(options) do
|
||||
for setting, value in pairs(table) do
|
||||
vim[scope][setting] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- User configuration entry point to override the default options of a configuration table with a user configuration file or table in the user/init.lua user settings
|
||||
-- @param module the module path of the override setting
|
||||
-- @param default the default settings that will be overridden
|
||||
-- @param extend boolean value to either extend the default settings or overwrite them with the user settings entirely (default: true)
|
||||
-- @param prefix a module prefix for where to search (default: user)
|
||||
-- @return the new configuration settings with the user overrides applied
|
||||
function astronvim.user_plugin_opts(module, default, extend, prefix)
|
||||
-- default to extend = true
|
||||
if extend == nil then extend = true end
|
||||
-- if no default table is provided set it to an empty table
|
||||
default = default or {}
|
||||
-- try to load a module file if it exists
|
||||
local user_settings = load_module_file((prefix or "user") .. "." .. module)
|
||||
-- if no user module file is found, try to load an override from the user settings table from user/init.lua
|
||||
if user_settings == nil and prefix == nil then user_settings = user_setting_table(module) end
|
||||
-- if a user override was found call the configuration engine
|
||||
if user_settings ~= nil then default = func_or_extend(user_settings, default, extend) end
|
||||
-- return the final configuration table with any overrides applied
|
||||
return default
|
||||
end
|
||||
|
||||
--- Open a URL under the cursor with the current operating system (Supports Mac OS X and *nix)
|
||||
-- @param path the path of the file to open with the system opener
|
||||
function astronvim.system_open(path)
|
||||
path = path or vim.fn.expand "<cfile>"
|
||||
if vim.fn.has "mac" == 1 then
|
||||
-- if mac use the open command
|
||||
vim.fn.jobstart({ "open", path }, { detach = true })
|
||||
elseif vim.fn.has "unix" == 1 then
|
||||
-- if unix then use xdg-open
|
||||
vim.fn.jobstart({ "xdg-open", path }, { detach = true })
|
||||
else
|
||||
-- if any other operating system notify the user that there is currently no support
|
||||
astronvim.notify("System open is not supported on this OS!", "error")
|
||||
end
|
||||
end
|
||||
|
||||
-- term_details can be either a string for just a command or
|
||||
-- a complete table to provide full access to configuration when calling Terminal:new()
|
||||
|
||||
--- Toggle a user terminal if it exists, if not then create a new one and save it
|
||||
-- @param term_details a terminal command string or a table of options for Terminal:new() (Check toggleterm.nvim documentation for table format)
|
||||
function astronvim.toggle_term_cmd(opts)
|
||||
local terms = astronvim.user_terminals
|
||||
-- if a command string is provided, create a basic table for Terminal:new() options
|
||||
if type(opts) == "string" then opts = { cmd = opts, hidden = true } end
|
||||
local num = vim.v.count > 0 and vim.v.count or 1
|
||||
-- if terminal doesn't exist yet, create it
|
||||
if not terms[opts.cmd] then terms[opts.cmd] = {} end
|
||||
if not terms[opts.cmd][num] then
|
||||
if not opts.count then opts.count = vim.tbl_count(terms) * 100 + num end
|
||||
terms[opts.cmd][num] = require("toggleterm.terminal").Terminal:new(opts)
|
||||
end
|
||||
-- toggle the terminal
|
||||
astronvim.user_terminals[opts.cmd][num]:toggle()
|
||||
end
|
||||
|
||||
--- Add a source to cmp
|
||||
-- @param source the cmp source string or table to add (see cmp documentation for source table format)
|
||||
function astronvim.add_cmp_source(source)
|
||||
-- load cmp if available
|
||||
local cmp_avail, cmp = pcall(require, "cmp")
|
||||
if cmp_avail then
|
||||
-- get the current cmp config
|
||||
local config = cmp.get_config()
|
||||
-- add the source to the list of sources
|
||||
tbl_insert(config.sources, source)
|
||||
-- call the setup function again
|
||||
cmp.setup(config)
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the priority of a cmp source
|
||||
-- @param source the cmp source string or table (see cmp documentation for source table format)
|
||||
-- @return a cmp source table with the priority set from the user configuration
|
||||
function astronvim.get_user_cmp_source(source)
|
||||
-- if the source is a string, convert it to a cmp source table
|
||||
source = type(source) == "string" and { name = source } or source
|
||||
-- get the priority of the source name from the user configuration
|
||||
local priority = astronvim.user_plugin_opts("cmp.source_priority", {
|
||||
nvim_lsp = 1000,
|
||||
luasnip = 750,
|
||||
buffer = 500,
|
||||
path = 250,
|
||||
})[source.name]
|
||||
-- if a priority is found, set it in the source
|
||||
if priority then source.priority = priority end
|
||||
-- return the source table
|
||||
return source
|
||||
end
|
||||
|
||||
--- add a source to cmp with the user configured priority
|
||||
-- @param source a cmp source string or table (see cmp documentation for source table format)
|
||||
function astronvim.add_user_cmp_source(source) astronvim.add_cmp_source(astronvim.get_user_cmp_source(source)) end
|
||||
|
||||
--- register mappings table with which-key
|
||||
-- @param mappings nested table of mappings where the first key is the mode, the second key is the prefix, and the value is the mapping table for which-key
|
||||
-- @param opts table of which-key options when setting the mappings (see which-key documentation for possible values)
|
||||
function astronvim.which_key_register(mappings, opts)
|
||||
local status_ok, which_key = pcall(require, "which-key")
|
||||
if not status_ok then return end
|
||||
for mode, prefixes in pairs(mappings) do
|
||||
for prefix, mapping_table in pairs(prefixes) do
|
||||
which_key.register(
|
||||
mapping_table,
|
||||
astronvim.default_tbl(opts, {
|
||||
mode = mode,
|
||||
prefix = prefix,
|
||||
buffer = nil,
|
||||
silent = true,
|
||||
noremap = true,
|
||||
nowait = true,
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Get a list of registered null-ls providers for a given filetype
|
||||
-- @param filetype the filetype to search null-ls for
|
||||
-- @return a list of null-ls sources
|
||||
function astronvim.null_ls_providers(filetype)
|
||||
local registered = {}
|
||||
-- try to load null-ls
|
||||
local sources_avail, sources = pcall(require, "null-ls.sources")
|
||||
if sources_avail then
|
||||
-- get the available sources of a given filetype
|
||||
for _, source in ipairs(sources.get_available(filetype)) do
|
||||
-- get each source name
|
||||
for method in pairs(source.methods) do
|
||||
registered[method] = registered[method] or {}
|
||||
tbl_insert(registered[method], source.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- return the found null-ls sources
|
||||
return registered
|
||||
end
|
||||
|
||||
--- Get the null-ls sources for a given null-ls method
|
||||
-- @param filetype the filetype to search null-ls for
|
||||
-- @param method the null-ls method (check null-ls documentation for available methods)
|
||||
-- @return the available sources for the given filetype and method
|
||||
function astronvim.null_ls_sources(filetype, method)
|
||||
local methods_avail, methods = pcall(require, "null-ls.methods")
|
||||
return methods_avail and astronvim.null_ls_providers(filetype)[methods.internal[method]] or {}
|
||||
end
|
||||
|
||||
--- Create a button entity to use with the alpha dashboard
|
||||
-- @param sc the keybinding string to convert to a button
|
||||
-- @param txt the explanation text of what the keybinding does
|
||||
-- @return a button entity table for an alpha configuration
|
||||
function astronvim.alpha_button(sc, txt)
|
||||
-- replace <leader> in shortcut text with LDR for nicer printing
|
||||
local sc_ = sc:gsub("%s", ""):gsub("LDR", "<leader>")
|
||||
-- if the leader is set, replace the text with the actual leader key for nicer printing
|
||||
if vim.g.mapleader then sc = sc:gsub("LDR", vim.g.mapleader == " " and "SPC" or vim.g.mapleader) end
|
||||
-- return the button entity to display the correct text and send the correct keybinding on press
|
||||
return {
|
||||
type = "button",
|
||||
val = txt,
|
||||
on_press = function()
|
||||
local key = vim.api.nvim_replace_termcodes(sc_, true, false, true)
|
||||
vim.api.nvim_feedkeys(key, "normal", false)
|
||||
end,
|
||||
opts = {
|
||||
position = "center",
|
||||
text = txt,
|
||||
shortcut = sc,
|
||||
cursor = 5,
|
||||
width = 36,
|
||||
align_shortcut = "right",
|
||||
hl = "DashboardCenter",
|
||||
hl_shortcut = "DashboardShortcut",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
--- Check if a plugin is defined in packer. Useful with lazy loading when a plugin is not necessarily loaded yet
|
||||
-- @param plugin the plugin string to search for
|
||||
-- @return boolean value if the plugin is available
|
||||
function astronvim.is_available(plugin) return packer_plugins ~= nil and packer_plugins[plugin] ~= nil end
|
||||
|
||||
--- A helper function to wrap a module function to require a plugin before running
|
||||
-- @param plugin the plugin string to call `require("packer").laoder` with
|
||||
-- @param module the system module where the functions live (e.g. `vim.ui`)
|
||||
-- @param func_names a string or a list like table of strings for functions to wrap in the given moduel (e.g. `{ "ui", "select }`)
|
||||
function astronvim.load_plugin_with_func(plugin, module, func_names)
|
||||
if type(func_names) == "string" then func_names = { func_names } end
|
||||
for _, func in ipairs(func_names) do
|
||||
local old_func = module[func]
|
||||
module[func] = function(...)
|
||||
module[func] = old_func
|
||||
require("packer").loader(plugin)
|
||||
module[func](...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Table based API for setting keybindings
|
||||
-- @param map_table A nested table where the first key is the vim mode, the second key is the key to map, and the value is the function to set the mapping to
|
||||
-- @param base A base set of options to set on every keybinding
|
||||
function astronvim.set_mappings(map_table, base)
|
||||
-- iterate over the first keys for each mode
|
||||
for mode, maps in pairs(map_table) do
|
||||
-- iterate over each keybinding set in the current mode
|
||||
for keymap, options in pairs(maps) do
|
||||
-- build the options for the command accordingly
|
||||
if options then
|
||||
local cmd = options
|
||||
local keymap_opts = base or {}
|
||||
if type(options) == "table" then
|
||||
cmd = options[1]
|
||||
keymap_opts = vim.tbl_deep_extend("force", options, keymap_opts)
|
||||
keymap_opts[1] = nil
|
||||
end
|
||||
-- extend the keybinding options with the base provided and set the mapping
|
||||
map(mode, keymap, cmd, keymap_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Delete the syntax matching rules for URLs/URIs if set
|
||||
function astronvim.delete_url_match()
|
||||
for _, match in ipairs(vim.fn.getmatches()) do
|
||||
if match.group == "HighlightURL" then vim.fn.matchdelete(match.id) end
|
||||
end
|
||||
end
|
||||
|
||||
--- Add syntax matching rules for highlighting URLs/URIs
|
||||
function astronvim.set_url_match()
|
||||
astronvim.delete_url_match()
|
||||
if vim.g.highlighturl_enabled then vim.fn.matchadd("HighlightURL", astronvim.url_matcher, 15) end
|
||||
end
|
||||
|
||||
--- Run a shell command and capture the output and if the command succeeded or failed
|
||||
-- @param cmd the terminal command to execute
|
||||
-- @param show_error boolean of whether or not to show an unsuccessful command as an error to the user
|
||||
-- @return the result of a successfully executed command or nil
|
||||
function astronvim.cmd(cmd, show_error)
|
||||
if vim.fn.has "win32" == 1 then cmd = { "cmd.exe", "/C", cmd } end
|
||||
local result = vim.fn.system(cmd)
|
||||
local success = vim.api.nvim_get_vvar "shell_error" == 0
|
||||
if not success and (show_error == nil and true or show_error) then
|
||||
vim.api.nvim_err_writeln("Error running command: " .. cmd .. "\nError message:\n" .. result)
|
||||
end
|
||||
return success and result:gsub("[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]", "") or nil
|
||||
end
|
||||
|
||||
--- Check if a buffer is valid
|
||||
-- @param bufnr the buffer to check
|
||||
-- @return true if the buffer is valid or false
|
||||
function astronvim.is_valid_buffer(bufnr)
|
||||
if not bufnr or bufnr < 1 then return false end
|
||||
return vim.bo[bufnr].buflisted and vim.api.nvim_buf_is_valid(bufnr)
|
||||
end
|
||||
|
||||
--- Move the current buffer tab n places in the bufferline
|
||||
-- @param n numer of tabs to move the current buffer over by (positive = right, negative = left)
|
||||
function astronvim.move_buf(n)
|
||||
if n == 0 then return end -- if n = 0 then no shifts are needed
|
||||
local bufs = vim.t.bufs -- make temp variable
|
||||
for i, bufnr in ipairs(bufs) do -- loop to find current buffer
|
||||
if bufnr == vim.api.nvim_get_current_buf() then -- found index of current buffer
|
||||
for _ = 0, (n % #bufs) - 1 do -- calculate number of right shifts
|
||||
local new_i = i + 1 -- get next i
|
||||
if i == #bufs then -- if at end, cycle to beginning
|
||||
new_i = 1 -- next i is actually 1 if at the end
|
||||
local val = bufs[i] -- save value
|
||||
table.remove(bufs, i) -- remove from end
|
||||
table.insert(bufs, new_i, val) -- insert at beginning
|
||||
else -- if not at the end,then just do an in place swap
|
||||
bufs[i], bufs[new_i] = bufs[new_i], bufs[i]
|
||||
end
|
||||
i = new_i -- iterate i to next value
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
vim.t.bufs = bufs -- set buffers
|
||||
vim.cmd.redrawtabline() -- redraw tabline
|
||||
end
|
||||
|
||||
--- Navigate left and right by n places in the bufferline
|
||||
-- @param n the number of tabs to navigate to (positive = right, negative = left)
|
||||
function astronvim.nav_buf(n)
|
||||
local current = vim.api.nvim_get_current_buf()
|
||||
for i, v in ipairs(vim.t.bufs) do
|
||||
if current == v then
|
||||
vim.cmd.b(vim.t.bufs[(i + n - 1) % #vim.t.bufs + 1])
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Close a given buffer
|
||||
-- @param bufnr? the buffer number to close or the current buffer if not provided
|
||||
function astronvim.close_buf(bufnr, force)
|
||||
if force == nil then force = false end
|
||||
local current = vim.api.nvim_get_current_buf()
|
||||
if not bufnr or bufnr == 0 then bufnr = current end
|
||||
if bufnr == current then astronvim.nav_buf(-1) end
|
||||
|
||||
if astronvim.is_available "bufdelete.nvim" then
|
||||
require("bufdelete").bufdelete(bufnr, force)
|
||||
else
|
||||
vim.cmd((force and "bd!" or "confirm bd") .. bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
--- Close the current tab
|
||||
function astronvim.close_tab()
|
||||
if #vim.api.nvim_list_tabpages() > 1 then
|
||||
vim.t.bufs = nil
|
||||
vim.cmd.tabclose()
|
||||
end
|
||||
end
|
||||
|
||||
require "core.utils.ui"
|
||||
require "core.utils.status"
|
||||
require "core.utils.updater"
|
||||
require "core.utils.mason"
|
||||
require "core.utils.lsp"
|
||||
|
||||
return astronvim
|
||||
@@ -0,0 +1,243 @@
|
||||
--- ### AstroNvim LSP
|
||||
--
|
||||
-- This module is automatically loaded by AstroNvim on during it's initialization into global variable `astronvim.lsp`
|
||||
--
|
||||
-- This module can also be manually loaded with `local updater = require("core.utils").lsp`
|
||||
--
|
||||
-- @module core.utils.lsp
|
||||
-- @see core.utils
|
||||
-- @copyright 2022
|
||||
-- @license GNU General Public License v3.0
|
||||
|
||||
astronvim.lsp = {}
|
||||
local tbl_contains = vim.tbl_contains
|
||||
local tbl_isempty = vim.tbl_isempty
|
||||
local user_plugin_opts = astronvim.user_plugin_opts
|
||||
local conditional_func = astronvim.conditional_func
|
||||
local is_available = astronvim.is_available
|
||||
local user_registration = user_plugin_opts("lsp.server_registration", nil, false)
|
||||
local skip_setup = user_plugin_opts "lsp.skip_setup"
|
||||
|
||||
astronvim.lsp.formatting =
|
||||
astronvim.user_plugin_opts("lsp.formatting", { format_on_save = { enabled = true }, disabled = {} })
|
||||
if type(astronvim.lsp.formatting.format_on_save) == "boolean" then
|
||||
astronvim.lsp.formatting.format_on_save = { enabled = astronvim.lsp.formatting.format_on_save }
|
||||
end
|
||||
|
||||
astronvim.lsp.format_opts = vim.deepcopy(astronvim.lsp.formatting)
|
||||
astronvim.lsp.format_opts.disabled = nil
|
||||
astronvim.lsp.format_opts.format_on_save = nil
|
||||
astronvim.lsp.format_opts.filter = function(client)
|
||||
local filter = astronvim.lsp.formatting.filter
|
||||
local disabled = astronvim.lsp.formatting.disabled or {}
|
||||
-- check if client is fully disabled or filtered by function
|
||||
return not (vim.tbl_contains(disabled, client.name) or (type(filter) == "function" and not filter(client)))
|
||||
end
|
||||
|
||||
--- Helper function to set up a given server with the Neovim LSP client
|
||||
-- @param server the name of the server to be setup
|
||||
astronvim.lsp.setup = function(server)
|
||||
if not tbl_contains(skip_setup, server) then
|
||||
-- if server doesn't exist, set it up from user server definition
|
||||
if not pcall(require, "lspconfig.server_configurations." .. server) then
|
||||
local server_definition = user_plugin_opts("lsp.server-settings." .. server)
|
||||
if server_definition.cmd then require("lspconfig.configs")[server] = { default_config = server_definition } end
|
||||
end
|
||||
local opts = astronvim.lsp.server_settings(server)
|
||||
if type(user_registration) == "function" then
|
||||
user_registration(server, opts)
|
||||
else
|
||||
require("lspconfig")[server].setup(opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- The `on_attach` function used by AstroNvim
|
||||
-- @param client the LSP client details when attaching
|
||||
-- @param bufnr the number of the buffer that the LSP client is attaching to
|
||||
astronvim.lsp.on_attach = function(client, bufnr)
|
||||
local capabilities = client.server_capabilities
|
||||
local lsp_mappings = {
|
||||
n = {
|
||||
["<leader>ld"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" },
|
||||
["[d"] = { function() vim.diagnostic.goto_prev() end, desc = "Previous diagnostic" },
|
||||
["]d"] = { function() vim.diagnostic.goto_next() end, desc = "Next diagnostic" },
|
||||
["gl"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" },
|
||||
},
|
||||
v = {},
|
||||
}
|
||||
|
||||
if is_available "mason-lspconfig.nvim" then
|
||||
lsp_mappings.n["<leader>li"] = { "<cmd>LspInfo<cr>", desc = "LSP information" }
|
||||
end
|
||||
|
||||
if is_available "null-ls.nvim" then
|
||||
lsp_mappings.n["<leader>lI"] = { "<cmd>NullLsInfo<cr>", desc = "Null-ls information" }
|
||||
end
|
||||
|
||||
if capabilities.codeActionProvider then
|
||||
lsp_mappings.n["<leader>la"] = { function() vim.lsp.buf.code_action() end, desc = "LSP code action" }
|
||||
lsp_mappings.v["<leader>la"] = lsp_mappings.n["<leader>la"]
|
||||
end
|
||||
|
||||
if capabilities.codeLensProvider then
|
||||
lsp_mappings.n["<leader>ll"] = { function() vim.lsp.codelens.refresh() end, desc = "LSP codelens refresh" }
|
||||
lsp_mappings.n["<leader>lL"] = { function() vim.lsp.codelens.run() end, desc = "LSP codelens run" }
|
||||
end
|
||||
|
||||
if capabilities.declarationProvider then
|
||||
lsp_mappings.n["gD"] = { function() vim.lsp.buf.declaration() end, desc = "Declaration of current symbol" }
|
||||
end
|
||||
|
||||
if capabilities.definitionProvider then
|
||||
lsp_mappings.n["gd"] = { function() vim.lsp.buf.definition() end, desc = "Show the definition of current symbol" }
|
||||
end
|
||||
|
||||
if capabilities.documentFormattingProvider and not tbl_contains(astronvim.lsp.formatting.disabled, client.name) then
|
||||
lsp_mappings.n["<leader>lf"] = {
|
||||
function() vim.lsp.buf.format(astronvim.lsp.format_opts) end,
|
||||
desc = "Format buffer",
|
||||
}
|
||||
lsp_mappings.v["<leader>lf"] = lsp_mappings.n["<leader>lf"]
|
||||
|
||||
vim.api.nvim_buf_create_user_command(
|
||||
bufnr,
|
||||
"Format",
|
||||
function() vim.lsp.buf.format(astronvim.lsp.format_opts) end,
|
||||
{ desc = "Format file with LSP" }
|
||||
)
|
||||
local autoformat = astronvim.lsp.formatting.format_on_save
|
||||
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
||||
if
|
||||
autoformat.enabled
|
||||
and (tbl_isempty(autoformat.allow_filetypes or {}) or tbl_contains(autoformat.allow_filetypes, filetype))
|
||||
and (tbl_isempty(autoformat.ignore_filetypes or {}) or not tbl_contains(autoformat.ignore_filetypes, filetype))
|
||||
then
|
||||
local autocmd_group = "auto_format_" .. bufnr
|
||||
vim.api.nvim_create_augroup(autocmd_group, { clear = true })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = autocmd_group,
|
||||
buffer = bufnr,
|
||||
desc = "Auto format buffer " .. bufnr .. " before save",
|
||||
callback = function()
|
||||
if vim.g.autoformat_enabled then
|
||||
vim.lsp.buf.format(astronvim.default_tbl({ bufnr = bufnr }, astronvim.lsp.format_opts))
|
||||
end
|
||||
end,
|
||||
})
|
||||
lsp_mappings.n["<leader>uf"] = {
|
||||
function() astronvim.ui.toggle_autoformat() end,
|
||||
desc = "Toggle autoformatting",
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if capabilities.documentHighlightProvider then
|
||||
local highlight_name = vim.fn.printf("lsp_document_highlight_%d", bufnr)
|
||||
vim.api.nvim_create_augroup(highlight_name, {})
|
||||
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
||||
group = highlight_name,
|
||||
buffer = bufnr,
|
||||
callback = function() vim.lsp.buf.document_highlight() end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||
group = highlight_name,
|
||||
buffer = bufnr,
|
||||
callback = function() vim.lsp.buf.clear_references() end,
|
||||
})
|
||||
end
|
||||
|
||||
if capabilities.hoverProvider then
|
||||
lsp_mappings.n["K"] = { function() vim.lsp.buf.hover() end, desc = "Hover symbol details" }
|
||||
end
|
||||
|
||||
if capabilities.implementationProvider then
|
||||
lsp_mappings.n["gI"] = { function() vim.lsp.buf.implementation() end, desc = "Implementation of current symbol" }
|
||||
end
|
||||
|
||||
if capabilities.referencesProvider then
|
||||
lsp_mappings.n["gr"] = { function() vim.lsp.buf.references() end, desc = "References of current symbol" }
|
||||
lsp_mappings.n["<leader>lR"] = { function() vim.lsp.buf.references() end, desc = "Search references" }
|
||||
end
|
||||
|
||||
if capabilities.renameProvider then
|
||||
lsp_mappings.n["<leader>lr"] = { function() vim.lsp.buf.rename() end, desc = "Rename current symbol" }
|
||||
end
|
||||
|
||||
if capabilities.signatureHelpProvider then
|
||||
lsp_mappings.n["<leader>lh"] = { function() vim.lsp.buf.signature_help() end, desc = "Signature help" }
|
||||
end
|
||||
|
||||
if capabilities.typeDefinitionProvider then
|
||||
lsp_mappings.n["gT"] = { function() vim.lsp.buf.type_definition() end, desc = "Definition of current type" }
|
||||
end
|
||||
|
||||
if capabilities.workspaceSymbolProvider then
|
||||
lsp_mappings.n["<leader>lG"] = { function() vim.lsp.buf.workspace_symbol() end, desc = "Search workspace symbols" }
|
||||
end
|
||||
|
||||
if is_available "telescope.nvim" then -- setup telescope mappings if available
|
||||
if lsp_mappings.n.gd then lsp_mappings.n.gd[1] = function() require("telescope.builtin").lsp_definitions() end end
|
||||
if lsp_mappings.n.gI then
|
||||
lsp_mappings.n.gI[1] = function() require("telescope.builtin").lsp_implementations() end
|
||||
end
|
||||
if lsp_mappings.n.gr then lsp_mappings.n.gr[1] = function() require("telescope.builtin").lsp_references() end end
|
||||
if lsp_mappings.n["<leader>lR"] then
|
||||
lsp_mappings.n["<leader>lR"][1] = function() require("telescope.builtin").lsp_references() end
|
||||
end
|
||||
if lsp_mappings.n.gT then
|
||||
lsp_mappings.n.gT[1] = function() require("telescope.builtin").lsp_type_definitions() end
|
||||
end
|
||||
if lsp_mappings.n["<leader>lG"] then
|
||||
lsp_mappings.n["<leader>lG"][1] = function() require("telescope.builtin").lsp_workspace_symbols() end
|
||||
end
|
||||
end
|
||||
|
||||
astronvim.set_mappings(user_plugin_opts("lsp.mappings", lsp_mappings), { buffer = bufnr })
|
||||
if not vim.tbl_isempty(lsp_mappings.v) then
|
||||
astronvim.which_key_register({ v = { ["<leader>"] = { l = { name = "LSP" } } } }, { buffer = bufnr })
|
||||
end
|
||||
|
||||
local on_attach_override = user_plugin_opts("lsp.on_attach", nil, false)
|
||||
conditional_func(on_attach_override, true, client, bufnr)
|
||||
end
|
||||
|
||||
--- The default AstroNvim LSP capabilities
|
||||
astronvim.lsp.capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.documentationFormat = { "markdown", "plaintext" }
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.preselectSupport = true
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.deprecatedSupport = true
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
|
||||
astronvim.lsp.capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||
properties = { "documentation", "detail", "additionalTextEdits" },
|
||||
}
|
||||
astronvim.lsp.capabilities = user_plugin_opts("lsp.capabilities", astronvim.lsp.capabilities)
|
||||
astronvim.lsp.flags = user_plugin_opts "lsp.flags"
|
||||
|
||||
--- Get the server settings for a given language server to be provided to the server's `setup()` call
|
||||
-- @param server_name the name of the server
|
||||
-- @return the table of LSP options used when setting up the given language server
|
||||
function astronvim.lsp.server_settings(server_name)
|
||||
local server = require("lspconfig")[server_name]
|
||||
local opts = user_plugin_opts( -- get user server-settings
|
||||
"lsp.server-settings." .. server_name, -- TODO: RENAME lsp.server-settings to lsp.config in v3
|
||||
user_plugin_opts("server-settings." .. server_name, { -- get default server-settings
|
||||
capabilities = vim.tbl_deep_extend("force", astronvim.lsp.capabilities, server.capabilities or {}),
|
||||
flags = vim.tbl_deep_extend("force", astronvim.lsp.flags, server.flags or {}),
|
||||
}, true, "configs")
|
||||
)
|
||||
local old_on_attach = server.on_attach
|
||||
local user_on_attach = opts.on_attach
|
||||
opts.on_attach = function(client, bufnr)
|
||||
conditional_func(old_on_attach, true, client, bufnr)
|
||||
astronvim.lsp.on_attach(client, bufnr)
|
||||
conditional_func(user_on_attach, true, client, bufnr)
|
||||
end
|
||||
return opts
|
||||
end
|
||||
|
||||
return astronvim.lsp
|
||||
@@ -0,0 +1,95 @@
|
||||
--- ### AstroNvim Mason Utils
|
||||
--
|
||||
-- This module is automatically loaded by AstroNvim on during it's initialization into global variable `astronvim.mason`
|
||||
--
|
||||
-- This module can also be manually loaded with `local updater = require("core.utils").mason`
|
||||
--
|
||||
-- @module core.utils.mason
|
||||
-- @see core.utils
|
||||
-- @copyright 2022
|
||||
-- @license GNU General Public License v3.0
|
||||
|
||||
astronvim.mason = {}
|
||||
|
||||
--- Update a mason package
|
||||
-- @param pkg_name string of the name of the package as defined in Mason (Not mason-lspconfig or mason-null-ls)
|
||||
-- @param auto_install boolean of whether or not to install a package that is not currently installed (default: True)
|
||||
function astronvim.mason.update(pkg_name, auto_install)
|
||||
if auto_install == nil then auto_install = true end
|
||||
local registry_avail, registry = pcall(require, "mason-registry")
|
||||
if not registry_avail then
|
||||
vim.api.nvim_err_writeln "Unable to access mason registry"
|
||||
return
|
||||
end
|
||||
|
||||
local pkg_avail, pkg = pcall(registry.get_package, pkg_name)
|
||||
if not pkg_avail then
|
||||
astronvim.notify(("Mason: %s is not available"):format(pkg_name), "error")
|
||||
else
|
||||
if not pkg:is_installed() then
|
||||
if auto_install then
|
||||
astronvim.notify(("Mason: Installing %s"):format(pkg.name))
|
||||
pkg:install()
|
||||
else
|
||||
astronvim.notify(("Mason: %s not installed"):format(pkg.name), "warn")
|
||||
end
|
||||
else
|
||||
pkg:check_new_version(function(update_available, version)
|
||||
if update_available then
|
||||
astronvim.notify(("Mason: Updating %s to %s"):format(pkg.name, version.latest_version))
|
||||
pkg:install():on("closed", function() astronvim.notify(("Mason: Updated %s"):format(pkg.name)) end)
|
||||
else
|
||||
astronvim.notify(("Mason: No updates available for %s"):format(pkg.name))
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Update all packages in Mason
|
||||
function astronvim.mason.update_all()
|
||||
local registry_avail, registry = pcall(require, "mason-registry")
|
||||
if not registry_avail then
|
||||
vim.api.nvim_err_writeln "Unable to access mason registry"
|
||||
return
|
||||
end
|
||||
|
||||
local installed_pkgs = registry.get_installed_packages()
|
||||
local running = #installed_pkgs
|
||||
local no_pkgs = running == 0
|
||||
astronvim.notify "Mason: Checking for package updates..."
|
||||
|
||||
if no_pkgs then
|
||||
astronvim.notify "Mason: No updates available"
|
||||
astronvim.event "MasonUpdateComplete"
|
||||
else
|
||||
local updated = false
|
||||
for _, pkg in ipairs(installed_pkgs) do
|
||||
pkg:check_new_version(function(update_available, version)
|
||||
if update_available then
|
||||
updated = true
|
||||
astronvim.notify(("Mason: Updating %s to %s"):format(pkg.name, version.latest_version))
|
||||
pkg:install():on("closed", function()
|
||||
running = running - 1
|
||||
if running == 0 then
|
||||
astronvim.notify "Mason: Update Complete"
|
||||
astronvim.event "MasonUpdateComplete"
|
||||
end
|
||||
end)
|
||||
else
|
||||
running = running - 1
|
||||
if running == 0 then
|
||||
if updated then
|
||||
astronvim.notify "Mason: Update Complete"
|
||||
else
|
||||
astronvim.notify "Mason: No updates available"
|
||||
end
|
||||
astronvim.event "MasonUpdateComplete"
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return astronvim.mason
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,188 @@
|
||||
--- ### AstroNvim UI Options
|
||||
--
|
||||
-- This module is automatically loaded by AstroNvim on during it's initialization into global variable `astronvim.ui`
|
||||
--
|
||||
-- This module can also be manually loaded with `local updater = require("core.utils").ui`
|
||||
--
|
||||
-- @module core.utils.ui
|
||||
-- @see core.utils
|
||||
-- @copyright 2022
|
||||
-- @license GNU General Public License v3.0
|
||||
|
||||
astronvim.ui = {}
|
||||
|
||||
local function bool2str(bool) return bool and "on" or "off" end
|
||||
|
||||
local function ui_notify(str)
|
||||
if vim.g.ui_notifications_enabled then astronvim.notify(str) end
|
||||
end
|
||||
|
||||
--- Toggle notifications for UI toggles
|
||||
function astronvim.ui.toggle_ui_notifications()
|
||||
vim.g.ui_notifications_enabled = not vim.g.ui_notifications_enabled
|
||||
ui_notify(string.format("ui notifications %s", bool2str(vim.g.ui_notifications_enabled)))
|
||||
end
|
||||
|
||||
--- Toggle autopairs
|
||||
function astronvim.ui.toggle_autopairs()
|
||||
local ok, autopairs = pcall(require, "nvim-autopairs")
|
||||
if ok then
|
||||
if autopairs.state.disabled then
|
||||
autopairs.enable()
|
||||
else
|
||||
autopairs.disable()
|
||||
end
|
||||
vim.g.autopairs_enabled = autopairs.state.disabled
|
||||
ui_notify(string.format("autopairs %s", bool2str(not autopairs.state.disabled)))
|
||||
else
|
||||
ui_notify "autopairs not available"
|
||||
end
|
||||
end
|
||||
|
||||
--- Toggle diagnostics
|
||||
function astronvim.ui.toggle_diagnostics()
|
||||
local status = "on"
|
||||
if vim.g.status_diagnostics_enabled then
|
||||
if vim.g.diagnostics_enabled then
|
||||
vim.g.diagnostics_enabled = false
|
||||
status = "virtual text off"
|
||||
else
|
||||
vim.g.status_diagnostics_enabled = false
|
||||
status = "fully off"
|
||||
end
|
||||
else
|
||||
vim.g.diagnostics_enabled = true
|
||||
vim.g.status_diagnostics_enabled = true
|
||||
end
|
||||
|
||||
vim.diagnostic.config(astronvim.lsp.diagnostics[bool2str(vim.g.diagnostics_enabled)])
|
||||
ui_notify(string.format("diagnostics %s", status))
|
||||
end
|
||||
|
||||
--- Toggle background="dark"|"light"
|
||||
function astronvim.ui.toggle_background()
|
||||
vim.go.background = vim.go.background == "light" and "dark" or "light"
|
||||
ui_notify(string.format("background=%s", vim.go.background))
|
||||
end
|
||||
|
||||
--- Toggle cmp entrirely
|
||||
function astronvim.ui.toggle_cmp()
|
||||
vim.g.cmp_enabled = not vim.g.cmp_enabled
|
||||
local ok, _ = pcall(require, "cmp")
|
||||
ui_notify(ok and string.format("completion %s", bool2str(vim.g.cmp_enabled)) or "completion not available")
|
||||
end
|
||||
|
||||
--- Toggle auto format
|
||||
function astronvim.ui.toggle_autoformat()
|
||||
vim.g.autoformat_enabled = not vim.g.autoformat_enabled
|
||||
ui_notify(string.format("Autoformatting %s", bool2str(vim.g.autoformat_enabled)))
|
||||
end
|
||||
|
||||
--- Toggle showtabline=2|0
|
||||
function astronvim.ui.toggle_tabline()
|
||||
vim.opt.showtabline = vim.opt.showtabline:get() == 0 and 2 or 0
|
||||
ui_notify(string.format("tabline %s", bool2str(vim.opt.showtabline:get() == 2)))
|
||||
end
|
||||
|
||||
--- Toggle conceal=2|0
|
||||
function astronvim.ui.toggle_conceal()
|
||||
vim.opt.conceallevel = vim.opt.conceallevel:get() == 0 and 2 or 0
|
||||
ui_notify(string.format("conceal %s", bool2str(vim.opt.conceallevel:get() == 2)))
|
||||
end
|
||||
|
||||
--- Toggle laststatus=3|2|0
|
||||
function astronvim.ui.toggle_statusline()
|
||||
local laststatus = vim.opt.laststatus:get()
|
||||
local status
|
||||
if laststatus == 0 then
|
||||
vim.opt.laststatus = 2
|
||||
status = "local"
|
||||
elseif laststatus == 2 then
|
||||
vim.opt.laststatus = 3
|
||||
status = "global"
|
||||
elseif laststatus == 3 then
|
||||
vim.opt.laststatus = 0
|
||||
status = "off"
|
||||
end
|
||||
ui_notify(string.format("statusline %s", status))
|
||||
end
|
||||
|
||||
--- Toggle signcolumn="auto"|"no"
|
||||
function astronvim.ui.toggle_signcolumn()
|
||||
if vim.wo.signcolumn == "no" then
|
||||
vim.wo.signcolumn = "yes"
|
||||
elseif vim.wo.signcolumn == "yes" then
|
||||
vim.wo.signcolumn = "auto"
|
||||
else
|
||||
vim.wo.signcolumn = "no"
|
||||
end
|
||||
ui_notify(string.format("signcolumn=%s", vim.wo.signcolumn))
|
||||
end
|
||||
|
||||
--- Set the indent and tab related numbers
|
||||
function astronvim.ui.set_indent()
|
||||
local input_avail, input = pcall(vim.fn.input, "Set indent value (>0 expandtab, <=0 noexpandtab): ")
|
||||
if input_avail then
|
||||
local indent = tonumber(input)
|
||||
if not indent or indent == 0 then return end
|
||||
vim.bo.expandtab = (indent > 0) -- local to buffer
|
||||
indent = math.abs(indent)
|
||||
vim.bo.tabstop = indent -- local to buffer
|
||||
vim.bo.softtabstop = indent -- local to buffer
|
||||
vim.bo.shiftwidth = indent -- local to buffer
|
||||
ui_notify(string.format("indent=%d %s", indent, vim.bo.expandtab and "expandtab" or "noexpandtab"))
|
||||
end
|
||||
end
|
||||
|
||||
--- Change the number display modes
|
||||
function astronvim.ui.change_number()
|
||||
local number = vim.wo.number -- local to window
|
||||
local relativenumber = vim.wo.relativenumber -- local to window
|
||||
if not number and not relativenumber then
|
||||
vim.wo.number = true
|
||||
elseif number and not relativenumber then
|
||||
vim.wo.relativenumber = true
|
||||
elseif number and relativenumber then
|
||||
vim.wo.number = false
|
||||
else -- not number and relativenumber
|
||||
vim.wo.relativenumber = false
|
||||
end
|
||||
ui_notify(string.format("number %s, relativenumber %s", bool2str(vim.wo.number), bool2str(vim.wo.relativenumber)))
|
||||
end
|
||||
|
||||
--- Toggle spell
|
||||
function astronvim.ui.toggle_spell()
|
||||
vim.wo.spell = not vim.wo.spell -- local to window
|
||||
ui_notify(string.format("spell %s", bool2str(vim.wo.spell)))
|
||||
end
|
||||
|
||||
--- Toggle paste
|
||||
function astronvim.ui.toggle_paste()
|
||||
vim.opt.paste = not vim.opt.paste:get() -- local to window
|
||||
ui_notify(string.format("paste %s", bool2str(vim.opt.paste:get())))
|
||||
end
|
||||
|
||||
--- Toggle wrap
|
||||
function astronvim.ui.toggle_wrap()
|
||||
vim.wo.wrap = not vim.wo.wrap -- local to window
|
||||
ui_notify(string.format("wrap %s", bool2str(vim.wo.wrap)))
|
||||
end
|
||||
|
||||
--- Toggle syntax highlighting and treesitter
|
||||
function astronvim.ui.toggle_syntax()
|
||||
local ts_avail, parsers = pcall(require, "nvim-treesitter.parsers")
|
||||
if vim.g.syntax_on then -- global var for on//off
|
||||
if ts_avail and parsers.has_parser() then vim.cmd.TSBufDisable "highlight" end
|
||||
vim.cmd.syntax "off" -- set vim.g.syntax_on = false
|
||||
else
|
||||
if ts_avail and parsers.has_parser() then vim.cmd.TSBufEnable "highlight" end
|
||||
vim.cmd.syntax "on" -- set vim.g.syntax_on = true
|
||||
end
|
||||
ui_notify(string.format("syntax %s", bool2str(vim.g.syntax_on)))
|
||||
end
|
||||
|
||||
--- Toggle URL/URI syntax highlighting rules
|
||||
function astronvim.ui.toggle_url_match()
|
||||
vim.g.highlighturl_enabled = not vim.g.highlighturl_enabled
|
||||
astronvim.set_url_match()
|
||||
end
|
||||
@@ -0,0 +1,296 @@
|
||||
--- ### AstroNvim Updater
|
||||
--
|
||||
-- This module is automatically loaded by AstroNvim on during it's initialization into global variable `astronvim.updater`
|
||||
--
|
||||
-- This module can also be manually loaded with `local updater = require("core.utils").updater`
|
||||
--
|
||||
-- @module core.utils.updater
|
||||
-- @see core.utils
|
||||
-- @copyright 2022
|
||||
-- @license GNU General Public License v3.0
|
||||
|
||||
local fn = vim.fn
|
||||
local git = require "core.utils.git"
|
||||
--- Updater settings overridden with any user provided configuration
|
||||
local options = astronvim.user_plugin_opts("updater", {
|
||||
remote = "origin",
|
||||
channel = "stable",
|
||||
show_changelog = true,
|
||||
auto_reload = true,
|
||||
auto_quit = true,
|
||||
})
|
||||
|
||||
-- set the install channel
|
||||
if options.branch and options.branch ~= "main" then options.channel = "nightly" end
|
||||
if astronvim.install.is_stable ~= nil then options.channel = astronvim.install.is_stable and "stable" or "nightly" end
|
||||
|
||||
astronvim.updater = { options = options }
|
||||
-- if the channel is stable or the user has chosen to pin the system plugins
|
||||
if options.pin_plugins == nil and options.channel == "stable" or options.pin_plugins then
|
||||
-- load the current packer snapshot from the installation home location
|
||||
local loaded, snapshot = pcall(fn.readfile, astronvim.install.home .. "/packer_snapshot")
|
||||
if loaded then
|
||||
-- decode the snapshot JSON and save it to a variable
|
||||
loaded, snapshot = pcall(fn.json_decode, snapshot)
|
||||
astronvim.updater.snapshot = type(snapshot) == "table" and snapshot or nil
|
||||
end
|
||||
-- if there is an error loading the snapshot, print an error
|
||||
if not loaded then vim.api.nvim_err_writeln "Error loading packer snapshot" end
|
||||
end
|
||||
|
||||
--- Get the current AstroNvim version
|
||||
-- @param quiet boolean to quietly execute or send a notification
|
||||
-- @return the current AstroNvim version string
|
||||
function astronvim.updater.version(quiet)
|
||||
local version = astronvim.install.version or git.current_version(false)
|
||||
if version and not quiet then astronvim.notify("Version: " .. version) end
|
||||
return version
|
||||
end
|
||||
|
||||
--- Get the full AstroNvim changelog
|
||||
-- @param quiet boolean to quietly execute or display the changelog
|
||||
-- @return the current AstroNvim changelog table of commit messages
|
||||
function astronvim.updater.changelog(quiet)
|
||||
local summary = {}
|
||||
vim.list_extend(summary, git.pretty_changelog(git.get_commit_range()))
|
||||
if not quiet then astronvim.echo(summary) end
|
||||
return summary
|
||||
end
|
||||
|
||||
--- Attempt an update of AstroNvim
|
||||
-- @param target the target if checking out a specific tag or commit or nil if just pulling
|
||||
local function attempt_update(target)
|
||||
-- if updating to a new stable version or a specific commit checkout the provided target
|
||||
if options.channel == "stable" or options.commit then
|
||||
return git.checkout(target, false)
|
||||
-- if no target, pull the latest
|
||||
else
|
||||
return git.pull(false)
|
||||
end
|
||||
end
|
||||
|
||||
--- Cancelled update message
|
||||
local cancelled_message = { { "Update cancelled", "WarningMsg" } }
|
||||
|
||||
--- Reload the AstroNvim configuration live (Experimental)
|
||||
-- @param quiet boolean to quietly execute or send a notification
|
||||
function astronvim.updater.reload(quiet)
|
||||
-- stop LSP if it is running
|
||||
if vim.fn.exists ":LspStop" ~= 0 then vim.cmd.LspStop() end
|
||||
local reload_module = require("plenary.reload").reload_module
|
||||
-- unload AstroNvim configuration files
|
||||
reload_module "user"
|
||||
reload_module "configs"
|
||||
reload_module "default_theme"
|
||||
reload_module "core"
|
||||
-- manual unload some plugins that need it if they exist
|
||||
reload_module "cmp"
|
||||
reload_module "which-key"
|
||||
-- source the AstroNvim configuration
|
||||
local reloaded, _ = pcall(dofile, vim.fn.expand "$MYVIMRC")
|
||||
-- if successful reload and not quiet, display a notification
|
||||
if reloaded and not quiet then astronvim.notify "Reloaded AstroNvim" end
|
||||
end
|
||||
|
||||
--- Sync Packer and then update Mason
|
||||
function astronvim.updater.update_packages()
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
once = true,
|
||||
desc = "Update Mason with Packer",
|
||||
group = vim.api.nvim_create_augroup("astro_sync", { clear = true }),
|
||||
pattern = "PackerComplete",
|
||||
callback = function()
|
||||
if astronvim.is_available "mason.nvim" then
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "AstroMasonUpdateComplete",
|
||||
once = true,
|
||||
callback = function() astronvim.event "UpdatePackagesComplete" end,
|
||||
})
|
||||
astronvim.mason.update_all()
|
||||
else
|
||||
astronvim.event "UpdatePackagesComplete"
|
||||
end
|
||||
end,
|
||||
})
|
||||
vim.cmd.PackerSync()
|
||||
end
|
||||
|
||||
--- AstroNvim's updater function
|
||||
function astronvim.updater.update()
|
||||
-- if the git command is not available, then throw an error
|
||||
if not git.available() then
|
||||
astronvim.notify(
|
||||
"git command is not available, please verify it is accessible in a command line. This may be an issue with your PATH",
|
||||
"error"
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
-- if installed with an external package manager, disable the internal updater
|
||||
if not git.is_repo() then
|
||||
astronvim.notify("Updater not available for non-git installations", "error")
|
||||
return
|
||||
end
|
||||
-- set up any remotes defined by the user if they do not exist
|
||||
for remote, entry in pairs(options.remotes and options.remotes or {}) do
|
||||
local url = git.parse_remote_url(entry)
|
||||
local current_url = git.remote_url(remote, false)
|
||||
local check_needed = false
|
||||
if not current_url then
|
||||
git.remote_add(remote, url)
|
||||
check_needed = true
|
||||
elseif
|
||||
current_url ~= url
|
||||
and astronvim.confirm_prompt {
|
||||
{ "Remote " },
|
||||
{ remote, "Title" },
|
||||
{ " is currently set to " },
|
||||
{ current_url, "WarningMsg" },
|
||||
{ "\nWould you like us to set it to " },
|
||||
{ url, "String" },
|
||||
{ "?" },
|
||||
}
|
||||
then
|
||||
git.remote_update(remote, url)
|
||||
check_needed = true
|
||||
end
|
||||
if check_needed and git.remote_url(remote, false) ~= url then
|
||||
vim.api.nvim_err_writeln("Error setting up remote " .. remote .. " to " .. url)
|
||||
return
|
||||
end
|
||||
end
|
||||
local is_stable = options.channel == "stable"
|
||||
if is_stable then
|
||||
options.branch = "main"
|
||||
elseif not options.branch then
|
||||
options.branch = "nightly"
|
||||
end
|
||||
-- fetch the latest remote
|
||||
if not git.fetch(options.remote) then
|
||||
vim.api.nvim_err_writeln("Error fetching remote: " .. options.remote)
|
||||
return
|
||||
end
|
||||
-- switch to the necessary branch only if not on the stable channel
|
||||
if not is_stable then
|
||||
local local_branch = (options.remote == "origin" and "" or (options.remote .. "_")) .. options.branch
|
||||
if git.current_branch() ~= local_branch then
|
||||
astronvim.echo {
|
||||
{ "Switching to branch: " },
|
||||
{ options.remote .. "/" .. options.branch .. "\n\n", "String" },
|
||||
}
|
||||
if not git.checkout(local_branch, false) then
|
||||
git.checkout("-b " .. local_branch .. " " .. options.remote .. "/" .. options.branch, false)
|
||||
end
|
||||
end
|
||||
-- check if the branch was switched to successfully
|
||||
if git.current_branch() ~= local_branch then
|
||||
vim.api.nvim_err_writeln("Error checking out branch: " .. options.remote .. "/" .. options.branch)
|
||||
return
|
||||
end
|
||||
end
|
||||
local source = git.local_head() -- calculate current commit
|
||||
local target -- calculate target commit
|
||||
if is_stable then -- if stable get tag commit
|
||||
local version_search = options.version or "latest"
|
||||
options.version = git.latest_version(git.get_versions(version_search))
|
||||
if not options.version then -- continue only if stable version is found
|
||||
vim.api.nvim_err_writeln("Error finding version: " .. version_search)
|
||||
return
|
||||
end
|
||||
target = git.tag_commit(options.version)
|
||||
elseif options.commit then -- if commit specified use it
|
||||
target = git.branch_contains(options.remote, options.branch, options.commit) and options.commit or nil
|
||||
else -- get most recent commit
|
||||
target = git.remote_head(options.remote, options.branch)
|
||||
end
|
||||
if not source or not target then -- continue if current and target commits were found
|
||||
vim.api.nvim_err_writeln "Error checking for updates"
|
||||
return
|
||||
elseif source == target then
|
||||
astronvim.echo { { "No updates available", "String" } }
|
||||
return
|
||||
elseif -- prompt user if they want to accept update
|
||||
not options.skip_prompts
|
||||
and not astronvim.confirm_prompt {
|
||||
{ "Update available to ", "Title" },
|
||||
{ is_stable and options.version or target, "String" },
|
||||
{ "\nUpdating requires a restart, continue?" },
|
||||
}
|
||||
then
|
||||
astronvim.echo(cancelled_message)
|
||||
return
|
||||
else -- perform update
|
||||
-- calculate and print the changelog
|
||||
local changelog = git.get_commit_range(source, target)
|
||||
local breaking = git.breaking_changes(changelog)
|
||||
local breaking_prompt = { { "Update contains the following breaking changes:\n", "WarningMsg" } }
|
||||
vim.list_extend(breaking_prompt, git.pretty_changelog(breaking))
|
||||
vim.list_extend(breaking_prompt, { { "\nWould you like to continue?" } })
|
||||
if #breaking > 0 and not options.skip_prompts and not astronvim.confirm_prompt(breaking_prompt) then
|
||||
astronvim.echo(cancelled_message)
|
||||
return
|
||||
end
|
||||
-- attempt an update
|
||||
local updated = attempt_update(target)
|
||||
-- check for local file conflicts and prompt user to continue or abort
|
||||
if
|
||||
not updated
|
||||
and not options.skip_prompts
|
||||
and not astronvim.confirm_prompt {
|
||||
{ "Unable to pull due to local modifications to base files.\n", "ErrorMsg" },
|
||||
{ "Reset local files and continue?" },
|
||||
}
|
||||
then
|
||||
astronvim.echo(cancelled_message)
|
||||
return
|
||||
-- if continued and there were errors reset the base config and attempt another update
|
||||
elseif not updated then
|
||||
git.hard_reset(source)
|
||||
updated = attempt_update(target)
|
||||
end
|
||||
-- if update was unsuccessful throw an error
|
||||
if not updated then
|
||||
vim.api.nvim_err_writeln "Error ocurred performing update"
|
||||
return
|
||||
end
|
||||
-- print a summary of the update with the changelog
|
||||
local summary = {
|
||||
{ "AstroNvim updated successfully to ", "Title" },
|
||||
{ git.current_version(), "String" },
|
||||
{ "!\n", "Title" },
|
||||
{
|
||||
options.auto_reload and "AstroNvim will now sync packer and quit.\n\n"
|
||||
or "Please restart and run :PackerSync.\n\n",
|
||||
"WarningMsg",
|
||||
},
|
||||
}
|
||||
if options.show_changelog and #changelog > 0 then
|
||||
vim.list_extend(summary, { { "Changelog:\n", "Title" } })
|
||||
vim.list_extend(summary, git.pretty_changelog(changelog))
|
||||
end
|
||||
astronvim.echo(summary)
|
||||
|
||||
-- if the user wants to auto quit, create an autocommand to quit AstroNvim on the update completing
|
||||
if options.auto_quit then
|
||||
vim.api.nvim_create_autocmd("User", { pattern = "AstroUpdateComplete", command = "quitall" })
|
||||
end
|
||||
|
||||
-- if the user wants to reload and sync packer
|
||||
if options.auto_reload then
|
||||
-- perform a reload
|
||||
vim.opt.modifiable = true
|
||||
astronvim.updater.reload(true) -- run quiet to not show notification on reload
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
once = true,
|
||||
pattern = "AstroUpdatePackagesComplete",
|
||||
callback = function() astronvim.event "UpdateComplete" end,
|
||||
})
|
||||
require "core.plugins"
|
||||
astronvim.updater.update_packages()
|
||||
-- if packer isn't available send successful update event
|
||||
else
|
||||
-- send user event of successful update
|
||||
astronvim.event "UpdateComplete"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user