Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 37 additions & 40 deletions lua/config/plugin_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ if not is_vscode then
end)
end
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { buffer = ev.buf })
vim.keymap.set("n", "<leader>la", vim.lsp.buf.code_action, { desc = "LSP code action" })
vim.keymap.set("n", "<leader>la", vim.lsp.buf.code_action, { buffer = ev.buf, desc = "LSP code action" })
end,
})
vim.api.nvim_create_user_command("LspToggle", function(opts)
Expand Down Expand Up @@ -155,51 +155,47 @@ if conform_ok and not is_vscode then
typescriptreact = { "prettier" },
},
})
vim.keymap.set("n", "<leader>lf", function()
-- conform derives the range from the live selection in visual mode;
-- the '< '> marks are stale until visual mode is left, so don't use them here
vim.keymap.set({ "n", "v" }, "<leader>lf", function()
conform.format()
end, { desc = "Format buffer" })
vim.keymap.set("v", "<leader>lf", function()
conform.format({
lsp_format = "fallback",
range = {
start = vim.api.nvim_buf_get_mark(0, "<"),
["end"] = vim.api.nvim_buf_get_mark(0, ">"),
},
})
end, { desc = "Format selection" })
end, { desc = "Format buffer or selection" })
end

-- fff
local fff_ok, _ = pcall(function()
vim.api.nvim_create_autocmd("PackChanged", {
callback = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
if name == "fff.nvim" and (kind == "install" or kind == "update") then
if not ev.data.active then
vim.cmd.packadd("fff.nvim")
end
require("fff.download").download_or_build_binary()
-- rebuild the rust binary whenever vim.pack installs/updates fff.nvim
vim.api.nvim_create_autocmd("PackChanged", {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard PackChanged on older Neovim

When this config runs on a Neovim build without vim.pack support, the old install path in plugins.lua is still intended to work, but plugin_config.lua now unconditionally registers the PackChanged event. On those versions the event is unknown, so nvim_create_autocmd('PackChanged', ...) raises during startup before any keymaps or plugin setup can continue. Keep this autocmd behind the same version/feature guard or restore the protective pcall so the non-vim.pack fallback remains usable.

Useful? React with 👍 / 👎.

callback = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
if name == "fff.nvim" and (kind == "install" or kind == "update") then
if not ev.data.active then
vim.cmd.packadd("fff.nvim")
end
end,
})
end)
if fff_ok then
vim.g.fff = {
lazy_sync = true,
debug = {
enabled = true,
show_scores = true,
},
}
if not is_vscode then
vim.keymap.set("n", "<leader>ff", function()
require("fff").find_files()
end, { desc = "fff files" })
-- you can toggle between grep, fuzzy grep, regex grep with shift+tab after launching fff grep
vim.keymap.set("n", "<leader>fg", function()
require("fff").live_grep()
end, { desc = "fff grep" })
require("fff.download").download_or_build_binary()
end
end,
})
vim.g.fff = {
lazy_sync = true,
debug = {
enabled = true,
show_scores = true,
},
}
if not is_vscode then
local function fff_call(fn)
return function()
local fff_ok, fff = pcall(require, "fff")
if not fff_ok then
vim.notify("fff.nvim is not installed (run :SyncPkgs)", vim.log.levels.WARN)
return
end
fff[fn]()
end
end
vim.keymap.set("n", "<leader>ff", fff_call("find_files"), { desc = "fff files" })
-- you can toggle between grep, fuzzy grep, regex grep with shift+tab after launching fff grep
vim.keymap.set("n", "<leader>fg", fff_call("live_grep"), { desc = "fff grep" })
end

-- diffview
Expand Down Expand Up @@ -277,6 +273,7 @@ end
local obsidian_ok, obsidian = pcall(require, "obsidian")
if obsidian_ok then
obsidian.setup({
legacy_commands = false, -- use :Obsidian <subcommand>; legacy :Obsidian* commands warn at startup
workspaces = {
{
name = "notes",
Expand Down
6 changes: 4 additions & 2 deletions lua/config/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ local function sync_packages()
print("Done clean-up!")
print("Install all packages...")
vim.pack.add(package_list)
vim.pack.update()
print("All packages installed!")
-- update() normally opens a confirmation buffer (:write applies it); in headless
-- mode (README setup command) that buffer would just be discarded, so apply directly
vim.pack.update(nil, { force = #vim.api.nvim_list_uis() == 0 })
else
mod_async
.new(function()
Expand All @@ -81,7 +83,7 @@ local function sync_packages()
print("Install: " .. pkg_name .. "...")
end
if pkg_skip then
print("Package skiped manually. Likely due to incompatibility.")
print("Package skipped manually. Likely due to incompatibility.")
else
vim.system({
"git",
Expand Down
44 changes: 29 additions & 15 deletions lua/config/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ vim.api.nvim_create_autocmd("ColorScheme", {
end,
})

local function statusline_escape(text)
if not text or text == "" then
return ""
end
return (text:gsub("%%", "%%%%"))
end

-- git sign
local function current_git_branch()
local ok, gs = pcall(require, "gitsigns")
Expand All @@ -34,7 +41,7 @@ local function current_git_branch()
if not branch or branch == "" then
return ""
end
return " %#Git#  " .. branch .. " " .. "%*"
return " %#Git#  " .. statusline_escape(branch) .. " " .. "%*"
end

local function current_buf_flags()
Expand All @@ -52,11 +59,14 @@ local lsp_progress = {}
local lsp_spinners = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
local lsp_progress_timer = nil

local function statusline_escape(text)
if not text or text == "" then
return ""
-- a client that exits with a token in flight never sends kind == "end",
-- which would keep lsp_progress non-empty and the redraw timer alive forever
local function prune_dead_lsp_progress()
for client_id in pairs(lsp_progress) do
if not vim.lsp.get_client_by_id(client_id) then
lsp_progress[client_id] = nil
end
end
return (text:gsub("%%", "%%%%"))
end

local function ensure_lsp_progress_timer()
Expand All @@ -71,6 +81,7 @@ local function ensure_lsp_progress_timer()
0,
100,
vim.schedule_wrap(function()
prune_dead_lsp_progress()
if vim.tbl_isempty(lsp_progress) then
if lsp_progress_timer then
lsp_progress_timer:stop()
Expand Down Expand Up @@ -219,7 +230,7 @@ local function current_mode()
c = { text = "[C]", hl = "StatusLineModeNormal", hl_alt = "StatusLineModeNormalAlt" },
t = { text = "[T]", hl = "StatusLineModeInsert", hl_alt = "StatusLineModeInsertAlt" },
}
local mode_info = mode_map[m] or { text = "[?]", hl = "StatusLineModeNormal" }
local mode_info = mode_map[m] or { text = "[?]", hl = "StatusLineModeNormal", hl_alt = "StatusLineModeNormalAlt" }
return string.format("%%#%s#%s%%*", mode_info.hl_alt, SOLID_LEFT_ARROW_PART)
.. string.format("%%#%s#%s%%*", mode_info.hl, mode_info.text)
.. string.format("%%#%s#%s%%*", mode_info.hl_alt, SOLID_RIGHT_ARROW)
Expand Down Expand Up @@ -254,22 +265,22 @@ local function current_filetype()
end

local function current_file()
-- local root_path = vim.uv.cwd() or ""
-- this reflects lcd change cwd
local root_path = vim.fn.getcwd(0, 0)
local root_dir = root_path:match("[^/]+$") or ""
local home_path = vim.fn.expand("%:~")
-- BUG: this sometimes break (e.g. .config/nvim/lua/config will have two matches, so need better handling for these cases)
local overlap, _ = home_path:find(root_dir)
local full_path = vim.api.nvim_buf_get_name(0)
local color = "%#File# "
local color_alt = "%#FileAlt#"
if home_path == "" then
return color .. root_path:gsub(vim.env.HOME, "~") .. " %*" .. color_alt .. SOLID_RIGHT_ARROW .. "%*"
elseif overlap then
return color .. home_path:sub(overlap) .. " %*" .. color_alt .. SOLID_RIGHT_ARROW .. "%*"
local name
if full_path == "" then
name = vim.fn.fnamemodify(root_path, ":~")
elseif full_path:sub(1, #root_path + 1) == root_path .. "/" then
-- file inside cwd: show its cwd-relative path prefixed with the cwd's basename
name = root_dir .. full_path:sub(#root_path + 1)
else
return color .. home_path .. " %*" .. color_alt .. SOLID_RIGHT_ARROW .. "%*"
name = vim.fn.fnamemodify(full_path, ":~")
end
return color .. statusline_escape(name) .. " %*" .. color_alt .. SOLID_RIGHT_ARROW .. "%*"
end

local function current_cursor_info()
Expand Down Expand Up @@ -348,5 +359,8 @@ end
if vim.g.vscode then
vim.opt.statusline = ""
else
-- %! is evaluated in the focused window's context, so per-split statuslines
-- would all show the focused buffer's info; use a single global statusline
vim.o.laststatus = 3
vim.opt.statusline = "%!v:lua.StatusLine()"
end
Loading