This commit is contained in:
2025-05-09 00:17:42 -05:00
parent f3bd08968a
commit 922dfb8c7e

View File

@ -6,8 +6,6 @@ if vim.fn.has("termguicolors") then
vim.opt.termguicolors = true vim.opt.termguicolors = true
end end
vim.opt.laststatus = 3
-- numbers -- numbers
vim.opt.number = true vim.opt.number = true
vim.opt.relativenumber = true vim.opt.relativenumber = true
@ -64,33 +62,14 @@ vim.g.netrw_liststyle = 1
vim.g.netrw_sizestyle = "H" vim.g.netrw_sizestyle = "H"
vim.g.netrw_hide = 1 vim.g.netrw_hide = 1
-- border (this doesn"t actually do anything within vim, I"m just setting it -- border (this doesn't actually do anything within vim, I"m just setting it
-- here so it"s easy to find) -- here so it"s easy to find)
vim.g.border_style = "solid" vim.g.border_style = "solid"
-- folding do -- folding
auto("FileType", { auto("FileType", {
callback = function() callback = function()
-- FIXME: it causes errors every once in a while -- use treesitter for folding
-- support lsp folding
-- if vim.fn.has("nvim-0.11") then
-- auto("LspAttach", {
-- callback = function(args)
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
-- if not client then
-- return
-- end
-- if client:supports_method("textDocument/foldingRange") then
-- local win = vim.api.nvim_get_current_win()
-- vim.wo[win][0].foldmethod = "expr"
-- vim.wo[win][0].foldexpr = "v:lua.vim.lsp.foldexpr()"
-- end
-- end,
-- })
-- end
-- or just rely on treesitter
if require("nvim-treesitter.parsers").has_parser() then if require("nvim-treesitter.parsers").has_parser() then
vim.opt.foldmethod = "expr" vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()" vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
@ -98,47 +77,70 @@ auto("FileType", {
vim.opt.foldmethod = "syntax" vim.opt.foldmethod = "syntax"
end end
end end
}) })
-- lsp folding: vim.o.foldexpr = "v:lua.vim.lsp.foldexpr()" vim.opt.foldlevelstart = 99
-- waiting on https://github.com/neovim/neovim/pull/31311 to hit a release vim.opt.foldlevel = 99
vim.lsp.config['*'] = { vim.opt.foldenable = true
capabilities = { vim.o.fillchars = "fold: "
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true
}
}
}
}
vim.opt.foldlevelstart = 99 _G.Fold_text = require("core.folding")
vim.opt.foldlevel = 99 vim.opt.foldtext = "v:lua.Fold_text()"
vim.opt.foldenable = true end
vim.o.fillchars = "fold: "
_G.Fold_text = require("core.folding") do -- statusline
vim.opt.foldtext = "v:lua.Fold_text()" local last_bufnr, i = 1, 1
--- status line
-- statusline ---@return string out formatted status line
function _G.Status() function _G.Status()
--- get the percentage through the file
---@return string out the formatted percentage
local function percentage() local function percentage()
local percent, line, lines local percent, line, lines
-- get the current and total # of lines
line = vim.api.nvim_win_get_cursor(0)[1] line = vim.api.nvim_win_get_cursor(0)[1]
lines = vim.api.nvim_buf_line_count(0) lines = vim.api.nvim_buf_line_count(0)
-- calculate the percentage through the file
percent = math.floor((line / lines) * 100) percent = math.floor((line / lines) * 100)
if percent == 0 then if percent == 0 or line == 1 then
return "Top" return "Top"
elseif percent == 100 then elseif percent == 100 or line == lines then
return "Bot" return "Bot"
end end
return percent.."%%" return percent.."%%"
end end
--- get the number of lsp servers
---@return string out the formatted number of servers
local function lsp_servers()
local out, nclients, hi
local hi_groups = { "@boolean", "@constant", "@keyword", "@number" }
-- get the number of clients
nclients = #vim.lsp.get_clients({ bufnr = 0 })
-- set the client display
out = "λ"..nclients
if nclients > 0 then
local bufnr = vim.api.nvim_win_get_buf(0)
if bufnr ~= last_bufnr then
last_bufnr = bufnr
i = i + 1
if i > #hi_groups then
i = 1
end
end
hi = "%#"..hi_groups[i].."#"
out = hi..out.."%#StatusLine#"
end
return out
end
return table.concat { return table.concat {
"%t", -- file name "%t", -- file name
" %h", -- help buffer tag " %h", -- help buffer tag
@ -146,13 +148,15 @@ function _G.Status()
"%r", -- readonly flag "%r", -- readonly flag
"%=", -- seperate left and right side "%=", -- seperate left and right side
-- print out the number of lsp clients attached -- print out the number of lsp clients attached with nice colors :)
"λ"..#vim.lsp.get_clients({ bufnr = 0 }).." ", lsp_servers(), " ",
"%<", -- we can start truncating here (I want to keep the file name) "%<", -- we can start truncating here (I want to keep the file name)
"%l,%c%V", -- line, column-virtual column "%l,%c%V", -- line, column-virtual column
"%<", -- we can start truncating here "%<", -- we can start truncating here
" "..percentage() -- percentage through the buffer " "..percentage() -- percentage through the buffer
} }
end
vim.opt.statusline="%!v:lua.Status()"
vim.opt.laststatus = 3
end end
vim.o.statusline="%!v:lua.Status()"