Skip to content

Commit

Permalink
v3.31.0 Nightly (#2091)
Browse files Browse the repository at this point in the history
* fix(utils): load treesitter when making notifications

* fix(treesitter): ensure markdown treesitter parser

* feat: add `vim.g.git_worktrees` to enable usage of detached git working trees (#2092)

* feat(options): add setting to enable git integration for custom worktrees

* fix(autocmds): add additional check for AstroGitFile to see if file is in custom worktree

* refactor(autocmds): extract `in_worktree()` to custom utility function `find_worktree()`

* feat(mappings): allow toggle lazygit to automatically load git worktrees if available

* chore(mappings): cleanup redundant toggle lazygit mapping

* refactor: clean up implementation of git worktrees

* fix(ui): notifications appearing on top in unintended situations (#2093)

* fix(ui): notifications appearing on top in unintended situations

* fix(ui): increase notification zindex to 175

Co-authored-by: Micah Halter <micah@mehalter.com>

---------

Co-authored-by: Micah Halter <micah@mehalter.com>

* feat: include tables for all map modes in `mappings` and `lsp.mappings`

* chore: use `vim.ui.open` if it's available

* fix(utils): set cursor in a better position (#2094)

* fix: disable `lua_ls` formatting with Neoconf

* fix(lsp): hacky fix for neoconf lazy loading

* fix(heirline): improve lualine integration with statusline

* refactor: simplify notification formatting implementation

* fix(utils): update `is_available` to use the correct lazy API

* chore(snapshot): update lazy_snapshot

---------

Co-authored-by: Josh <56745535+Subjective@users.noreply.github.com>
Co-authored-by: Tiago Muniz de Araujo <tiagomuniz130@gmail.com>
  • Loading branch information
3 people committed Jul 6, 2023
1 parent 219e1c7 commit 467a270
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 61 deletions.
20 changes: 20 additions & 0 deletions .neoconf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"neodev": {
"library": {
"enabled": true,
"plugins": true
}
},
"neoconf": {
"plugins": {
"lua_ls": {
"enabled": true
}
}
},
"lspconfig": {
"lua_ls": {
"Lua.format.enable": false
}
}
}
5 changes: 4 additions & 1 deletion lua/astronvim/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ autocmd({ "BufReadPost", "BufNewFile", "BufWritePost" }, {
callback = function(args)
if not (vim.fn.expand "%" == "" or vim.api.nvim_get_option_value("buftype", { buf = args.buf }) == "nofile") then
astroevent "File"
if utils.cmd({ "git", "-C", vim.fn.expand "%:p:h", "rev-parse" }, false) then
if
require("astronvim.utils.git").file_worktree()
or utils.cmd({ "git", "-C", vim.fn.expand "%:p:h", "rev-parse" }, false)
then
astroevent "GitFile"
vim.api.nvim_del_augroup_by_name "file_user_events"
end
Expand Down
16 changes: 12 additions & 4 deletions lua/astronvim/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local get_icon = utils.get_icon
local is_available = utils.is_available
local ui = require "astronvim.utils.ui"

local maps = { i = {}, n = {}, v = {}, t = {} }
local maps = require("astronvim.utils").empty_map_table()

local sections = {
f = { desc = get_icon("Search", 1, true) .. "Find" },
Expand All @@ -26,11 +26,12 @@ maps.n["k"] = { "v:count == 0 ? 'gk' : 'k'", expr = true, desc = "Move cursor up
maps.n["<leader>w"] = { "<cmd>w<cr>", desc = "Save" }
maps.n["<leader>q"] = { "<cmd>confirm q<cr>", desc = "Quit" }
maps.n["<leader>n"] = { "<cmd>enew<cr>", desc = "New File" }
maps.n["gx"] = { utils.system_open, 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["|"] = { "<cmd>vsplit<cr>", desc = "Vertical Split" }
maps.n["\\"] = { "<cmd>split<cr>", desc = "Horizontal Split" }
-- TODO: Remove when dropping support for <Neovim v0.10
if not vim.ui.open then maps.n["gx"] = { utils.system_open, desc = "Open the file under cursor with system app" } end

-- Plugin Manager
maps.n["<leader>p"] = sections.p
Expand Down Expand Up @@ -308,8 +309,15 @@ if is_available "toggleterm.nvim" then
maps.n["<leader>t"] = sections.t
if vim.fn.executable "lazygit" == 1 then
maps.n["<leader>g"] = sections.g
maps.n["<leader>gg"] = { function() utils.toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" }
maps.n["<leader>tl"] = { function() utils.toggle_term_cmd "lazygit" end, desc = "ToggleTerm lazygit" }
maps.n["<leader>gg"] = {
function()
local worktree = require("astronvim.utils.git").file_worktree()
local flags = worktree and (" --work-tree=%s --git-dir=%s"):format(worktree.toplevel, worktree.gitdir) or ""
utils.toggle_term_cmd("lazygit " .. flags)
end,
desc = "ToggleTerm lazygit",
}
maps.n["<leader>tl"] = maps.n["<leader>gg"]
end
if vim.fn.executable "node" == 1 then
maps.n["<leader>tn"] = { function() utils.toggle_term_cmd "node" end, desc = "ToggleTerm node" }
Expand Down
1 change: 1 addition & 0 deletions lua/astronvim/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ local options = astronvim.user_opts("options", {
lsp_handlers_enabled = true, -- enable or disable default vim.lsp.handlers (hover and signatureHelp)
semantic_tokens_enabled = true, -- enable or disable LSP semantic tokens on startup
ui_notifications_enabled = true, -- disable notifications (TODO: rename to notifications_enabled in AstroNvim v4)
git_worktrees = nil, -- enable git integration for detached worktrees (specify a table where each entry is of the form { toplevel = vim.env.HOME, gitdir=vim.env.HOME .. "/.dotfiles" })
},
t = vim.t.bufs and vim.t.bufs or { bufs = vim.api.nvim_list_bufs() }, -- initialize buffers for the current tab
})
Expand Down
26 changes: 26 additions & 0 deletions lua/astronvim/utils/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ function git.cmd(args, ...)
return require("astronvim.utils").cmd(vim.list_extend({ "git", "-C", astronvim.install.home }, args), ...)
end

--- Get the first worktree that a file belongs to
---@param file string? the file to check, defaults to the current file
---@param worktrees table<string, string>[]? an array like table of worktrees with entries `toplevel` and `gitdir`, default retrieves from `vim.g.git_worktrees`
---@return table<string, string>|nil # a table specifying the `toplevel` and `gitdir` of a worktree or nil if not found
function git.file_worktree(file, worktrees)
worktrees = worktrees or vim.g.git_worktrees
if not worktrees then return end
file = file or vim.fn.expand "%"
for _, worktree in ipairs(worktrees) do
if
require("astronvim.utils").cmd({
"git",
"--work-tree",
worktree.toplevel,
"--git-dir",
worktree.gitdir,
"ls-files",
"--error-unmatch",
file,
}, false)
then
return worktree
end
end
end

--- Check if the AstroNvim is able to reach the `git` command
---@return boolean # The result of running `git --help`
function git.available() return vim.fn.executable "git" == 1 end
Expand Down
37 changes: 20 additions & 17 deletions lua/astronvim/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,7 @@ end
---@param type number|nil The type of the notification (:help vim.log.levels)
---@param opts? table The nvim-notify options to use (:help notify-options)
function M.notify(msg, type, opts)
vim.schedule(function()
vim.notify(
msg,
type,
M.extend_tbl({
title = "AstroNvim",
on_open = function(win)
vim.bo[vim.api.nvim_win_get_buf(win)].filetype = "markdown"
vim.wo[win].spell = false
vim.wo[win].conceallevel = 3
vim.wo[win].concealcursor = "n"
end,
}, opts)
)
end)
vim.schedule(function() vim.notify(msg, type, M.extend_tbl({ title = "AstroNvim" }, opts)) end)
end

--- Trigger an AstroNvim user event
Expand All @@ -161,6 +147,8 @@ end
--- Open a URL under the cursor with the current operating system
---@param path string The path of the file to open with the system opener
function M.system_open(path)
-- TODO: REMOVE WHEN DROPPING NEOVIM <0.10
if vim.ui.open then return vim.ui.open(path) end
local cmd
if vim.fn.has "win32" == 1 and vim.fn.executable "explorer" == 1 then
cmd = { "cmd.exe", "/K", "explorer" }
Expand Down Expand Up @@ -212,7 +200,7 @@ function M.alpha_button(sc, txt)
position = "center",
text = txt,
shortcut = sc,
cursor = 5,
cursor = -2,
width = 36,
align_shortcut = "right",
hl = "DashboardCenter",
Expand All @@ -226,7 +214,7 @@ end
---@return boolean available # Whether the plugin is available
function M.is_available(plugin)
local lazy_config_avail, lazy_config = pcall(require, "lazy.core.config")
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
return lazy_config_avail and lazy_config.spec.plugins[plugin] ~= nil
end

--- Resolve the options table for a given plugin with lazy
Expand Down Expand Up @@ -272,6 +260,21 @@ function M.which_key_register()
end
end

--- Get an empty table of mappings with a key for each map mode
---@return table<string,table> # a table with entries for each map mode
function M.empty_map_table()
local maps = {}
for _, mode in ipairs { "", "n", "v", "x", "s", "o", "!", "i", "l", "c", "t" } do
maps[mode] = {}
end
if vim.fn.has "nvim-0.10.0" == 1 then
for _, abbr_mode in ipairs { "ia", "ca", "!a" } do
maps[abbr_mode] = {}
end
end
return maps
end

--- Table based API for setting keybindings
---@param map_table 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? table A base set of options to set on every keybinding
Expand Down
33 changes: 12 additions & 21 deletions lua/astronvim/utils/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ M.setup = function(server)
end
local opts = M.config(server)
local setup_handler = setup_handlers[server] or setup_handlers[1]

-- HACK: set up neoconf before setting up any language servers if it's not setup
if not package.loaded["neoconf"] and utils.is_available "neoconf.nvim" then
require("neoconf").setup(utils.plugin_opts "neoconf.nvim")
end

if not vim.tbl_contains(astronvim.lsp.skip_setup, server) and setup_handler then setup_handler(server, opts) end
end

Expand Down Expand Up @@ -128,27 +134,12 @@ end
---@param client table The LSP client details when attaching
---@param bufnr number The buffer that the LSP client is attaching to
M.on_attach = function(client, bufnr)
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 = {},
}
local lsp_mappings = require("astronvim.utils").empty_map_table()

lsp_mappings.n["<leader>ld"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" }
lsp_mappings.n["[d"] = { function() vim.diagnostic.goto_prev() end, desc = "Previous diagnostic" }
lsp_mappings.n["]d"] = { function() vim.diagnostic.goto_next() end, desc = "Next diagnostic" }
lsp_mappings.n["gl"] = { function() vim.diagnostic.open_float() end, desc = "Hover diagnostics" }

if is_available "telescope.nvim" then
lsp_mappings.n["<leader>lD"] =
Expand Down
8 changes: 4 additions & 4 deletions lua/lazy_snapshot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ return {
{ "hrsh7th/nvim-cmp", commit = "2743dd989e9b932e1b4813a4927d7b84272a14e2", optional = true },
{ "jay-babu/mason-null-ls.nvim", version = "^2", optional = true },
{ "jay-babu/mason-nvim-dap.nvim", version = "^2", optional = true },
{ "jose-elias-alvarez/null-ls.nvim", commit = "07897774c3b2f14d71b2ca51f3014d1055da9657", optional = true },
{ "jose-elias-alvarez/null-ls.nvim", commit = "db09b6c691def0038c456551e4e2772186449f35", optional = true },
{ "kevinhwang91/nvim-ufo", version = "^1", optional = true },
{ "kevinhwang91/promise-async", version = "^1", optional = true },
{ "lewis6991/gitsigns.nvim", version = "^0.6", optional = true },
{ "lukas-reineke/indent-blankline.nvim", version = "^2", optional = true },
{ "max397574/better-escape.nvim", commit = "7031dc734add47bb71c010e0551829fa5799375f", optional = true },
{ "mfussenegger/nvim-dap", version = "^0.6", optional = true },
{ "mrjones2014/smart-splits.nvim", version = "^1", optional = true },
{ "neovim/nvim-lspconfig", commit = "2187f222c37cb5fd7cf96f242e5c8a4a340f2596", optional = true },
{ "neovim/nvim-lspconfig", commit = "a7ecaff3245ba4b9e5ed784ebefbedba54e7f0ad", optional = true },
{ "numToStr/Comment.nvim", version = "^0.8", optional = true },
{ "nvim-lua/plenary.nvim", version = "^0.1", optional = true },
{ "nvim-neo-tree/neo-tree.nvim", version = "^2", optional = true },
{ "nvim-telescope/telescope-fzf-native.nvim", commit = "9bc8237565ded606e6c366a71c64c0af25cd7a50", optional = true },
{ "nvim-telescope/telescope.nvim", version = "^0.1", optional = true },
{ "nvim-tree/nvim-web-devicons", commit = "9ab9b0b894b2388a9dbcdee5f00ce72e25d85bf9", optional = true },
{ "nvim-treesitter/nvim-treesitter", commit = "0b81ed9f18333949a74586a1ea0497ae4cbb7cd4", optional = true },
{ "nvim-treesitter/nvim-treesitter", commit = "e1ab5391e5c4820dd1ffc2566d29b01573ab52a9", optional = true },
{ "nvim-treesitter/nvim-treesitter-textobjects", commit = "52f1f3280d9092bfaee5c45be5962fabee3d9654", optional = true },
{ "onsails/lspkind.nvim", commit = "57610d5ab560c073c465d6faf0c19f200cb67e6e", optional = true },
{ "rafamadriz/friendly-snippets", commit = "17245edcd1195ad88d60ae13fb1e90d1df9b2fc9", optional = true },
{ "rafamadriz/friendly-snippets", commit = "96c02045323a9e0b8936fc4dce42dc249495c4f1", optional = true },
{ "rcarriga/cmp-dap", commit = "d16f14a210cd28988b97ca8339d504533b7e09a4", optional = true },
{ "rcarriga/nvim-dap-ui", version = "^3", optional = true },
{ "rcarriga/nvim-notify", version = "^3", optional = true },
Expand Down
20 changes: 9 additions & 11 deletions lua/plugins/configs/heirline.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
return function(_, opts)
local heirline = require "heirline"
local hl = require "astronvim.utils.status.hl"
local C = require("astronvim.utils.status.env").fallback_colors
local get_hlgroup = require("astronvim.utils").get_hlgroup
local lualine_mode = require("astronvim.utils.status.hl").lualine_mode
local function resolve_lualine(orig, ...) return (not orig or orig == "NONE") and lualine_mode(...) or orig end

local function setup_colors()
local Normal = get_hlgroup("Normal", { fg = C.fg, bg = C.bg })
Expand All @@ -24,16 +25,13 @@ return function(_, opts)
local DiagnosticWarn = get_hlgroup("DiagnosticWarn", { fg = C.orange, bg = C.dark_bg })
local DiagnosticInfo = get_hlgroup("DiagnosticInfo", { fg = C.white, bg = C.dark_bg })
local DiagnosticHint = get_hlgroup("DiagnosticHint", { fg = C.bright_yellow, bg = C.dark_bg })
local HeirlineInactive = get_hlgroup("HeirlineInactive", { bg = nil }).bg
or hl.lualine_mode("inactive", C.dark_grey)
local HeirlineNormal = get_hlgroup("HeirlineNormal", { bg = nil }).bg or hl.lualine_mode("normal", C.blue)
local HeirlineInsert = get_hlgroup("HeirlineInsert", { bg = nil }).bg or hl.lualine_mode("insert", C.green)
local HeirlineVisual = get_hlgroup("HeirlineVisual", { bg = nil }).bg or hl.lualine_mode("visual", C.purple)
local HeirlineReplace = get_hlgroup("HeirlineReplace", { bg = nil }).bg or hl.lualine_mode("replace", C.bright_red)
local HeirlineCommand = get_hlgroup("HeirlineCommand", { bg = nil }).bg
or hl.lualine_mode("command", C.bright_yellow)
local HeirlineTerminal = get_hlgroup("HeirlineTerminal", { bg = nil }).bg
or hl.lualine_mode("insert", HeirlineInsert)
local HeirlineInactive = resolve_lualine(get_hlgroup("HeirlineInactive", { bg = nil }).bg, "inactive", C.dark_grey)
local HeirlineNormal = resolve_lualine(get_hlgroup("HeirlineNormal", { bg = nil }).bg, "normal", C.blue)
local HeirlineInsert = resolve_lualine(get_hlgroup("HeirlineInsert", { bg = nil }).bg, "insert", C.green)
local HeirlineVisual = resolve_lualine(get_hlgroup("HeirlineVisual", { bg = nil }).bg, "visual", C.purple)
local HeirlineReplace = resolve_lualine(get_hlgroup("HeirlineReplace", { bg = nil }).bg, "replace", C.bright_red)
local HeirlineCommand = resolve_lualine(get_hlgroup("HeirlineCommand", { bg = nil }).bg, "command", C.bright_yellow)
local HeirlineTerminal = resolve_lualine(get_hlgroup("HeirlineTerminal", { bg = nil }).bg, "insert", HeirlineInsert)

local colors = astronvim.user_opts("heirline.colors", {
close_fg = Error.fg,
Expand Down
1 change: 1 addition & 0 deletions lua/plugins/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ return {
changedelete = { text = get_icon "GitSign" },
untracked = { text = get_icon "GitSign" },
},
worktrees = vim.g.git_worktrees,
},
}
2 changes: 2 additions & 0 deletions lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ return {
end
return { global_settings = global_settings and string.rep("../", depth):sub(1, -2) .. global_settings }
end,
-- HACK: defer neoconf loading until after lspconfig is loaded but before servers are set up
config = function() pcall(require, "lspconfig") end, -- actual setup happens in astronvim.utils.lsp
},
{
"williamboman/mason-lspconfig.nvim",
Expand Down
5 changes: 4 additions & 1 deletion lua/plugins/neo-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ return {
},
},
commands = {
system_open = function(state) require("astronvim.utils").system_open(state.tree:get_node():get_id()) end,
system_open = function(state)
-- TODO: just use vim.ui.open when dropping support for Neovim <0.10
(vim.ui.open or require("astronvim.utils").system_open)(state.tree:get_node():get_id())
end,
parent_or_close = function(state)
local node = state.tree:get_node()
if (node.type == "directory" or node:has_children()) and node:is_expanded() then
Expand Down
1 change: 1 addition & 0 deletions lua/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ return {
return {
autotag = { enable = true },
context_commentstring = { enable = true, enable_autocmd = false },
ensure_installed = { "markdown" },
highlight = {
enable = true,
disable = function(_, bufnr) return vim.api.nvim_buf_line_count(bufnr) > 10000 end,
Expand Down
9 changes: 7 additions & 2 deletions lua/plugins/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ return {
init = function() require("astronvim.utils").load_plugin_with_func("nvim-notify", vim, "notify") end,
opts = {
on_open = function(win)
vim.api.nvim_win_set_config(win, { zindex = 1000 })
-- close notification immediately if notifications disabled
vim.api.nvim_win_set_config(win, { zindex = 175 })
if not vim.g.ui_notifications_enabled then vim.api.nvim_win_close(win, true) end
if require("astronvim.utils").is_available "nvim-treesitter" then
if not package.loaded["nvim-treesitter"] then require "nvim-treesitter" end
vim.wo[win].conceallevel = 3
vim.bo[vim.api.nvim_win_get_buf(win)].filetype = "markdown"
vim.wo[win].spell = false
end
end,
},
config = require "plugins.configs.notify",
Expand Down

0 comments on commit 467a270

Please sign in to comment.