From 922dfb8c7ee7fe5a88dc569220ea92aff659fa08 Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 9 May 2025 00:17:42 -0500 Subject: opts.lua --- lua/conf/opts.lua | 176 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 90 insertions(+), 86 deletions(-) diff --git a/lua/conf/opts.lua b/lua/conf/opts.lua index 20e0048..48792bb 100644 --- a/lua/conf/opts.lua +++ b/lua/conf/opts.lua @@ -6,8 +6,6 @@ if vim.fn.has("termguicolors") then vim.opt.termguicolors = true end -vim.opt.laststatus = 3 - -- numbers vim.opt.number = true vim.opt.relativenumber = true @@ -64,95 +62,101 @@ vim.g.netrw_liststyle = 1 vim.g.netrw_sizestyle = "H" 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) vim.g.border_style = "solid" --- folding -auto("FileType", { - callback = function() - -- FIXME: it causes errors every once in a while - -- 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 - vim.opt.foldmethod = "expr" - vim.opt.foldexpr = "nvim_treesitter#foldexpr()" - else - vim.opt.foldmethod = "syntax" +do -- folding + auto("FileType", { + callback = function() + -- use treesitter for folding + if require("nvim-treesitter.parsers").has_parser() then + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + else + vim.opt.foldmethod = "syntax" + end end - end -}) - --- lsp folding: vim.o.foldexpr = "v:lua.vim.lsp.foldexpr()" --- waiting on https://github.com/neovim/neovim/pull/31311 to hit a release -vim.lsp.config['*'] = { - capabilities = { - textDocument = { - foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true - } - } - } -} - -vim.opt.foldlevelstart = 99 -vim.opt.foldlevel = 99 -vim.opt.foldenable = true -vim.o.fillchars = "fold: " - -_G.Fold_text = require("core.folding") -vim.opt.foldtext = "v:lua.Fold_text()" - --- statusline -function _G.Status() - local function percentage() - local percent, line, lines - - line = vim.api.nvim_win_get_cursor(0)[1] - lines = vim.api.nvim_buf_line_count(0) - - percent = math.floor((line / lines) * 100) - if percent == 0 then - return "Top" - elseif percent == 100 then - return "Bot" + }) + + vim.opt.foldlevelstart = 99 + vim.opt.foldlevel = 99 + vim.opt.foldenable = true + vim.o.fillchars = "fold: " + + _G.Fold_text = require("core.folding") + vim.opt.foldtext = "v:lua.Fold_text()" +end + +do -- statusline + local last_bufnr, i = 1, 1 + --- status line + ---@return string out formatted status line + function _G.Status() + --- get the percentage through the file + ---@return string out the formatted percentage + local function percentage() + local percent, line, lines + + -- get the current and total # of lines + line = vim.api.nvim_win_get_cursor(0)[1] + lines = vim.api.nvim_buf_line_count(0) + + -- calculate the percentage through the file + percent = math.floor((line / lines) * 100) + if percent == 0 or line == 1 then + return "Top" + elseif percent == 100 or line == lines then + return "Bot" + end + + return percent.."%%" end - return percent.."%%" - 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 { + "%t", -- file name + " %h", -- help buffer tag + "%m", -- modify tag + "%r", -- readonly flag + "%=", -- seperate left and right side - return table.concat { - "%t", -- file name - " %h", -- help buffer tag - "%m", -- modify tag - "%r", -- readonly flag - "%=", -- seperate left and right side - - -- print out the number of lsp clients attached - "λ"..#vim.lsp.get_clients({ bufnr = 0 }).." ", - - "%<", -- we can start truncating here (I want to keep the file name) - "%l,%c%V", -- line, column-virtual column - "%<", -- we can start truncating here - " "..percentage() -- percentage through the buffer - } + -- print out the number of lsp clients attached with nice colors :) + lsp_servers(), " ", + + "%<", -- we can start truncating here (I want to keep the file name) + "%l,%c%V", -- line, column-virtual column + "%<", -- we can start truncating here + " "..percentage() -- percentage through the buffer + } + end + vim.opt.statusline="%!v:lua.Status()" + vim.opt.laststatus = 3 end -vim.o.statusline="%!v:lua.Status()" -- cgit v1.2.1