Breaking change for statusline_separator field users | optimize statusline & make it overridable
added cmd fields for various plugins for example lspinstaller+lspconfig gets loaded only when a file opened but their commands can be run before a file is opened so I additionally lazy loaded them on their cmds too
This commit is contained in:
parent
099e075a01
commit
4f1ee6ec8f
7 changed files with 78 additions and 77 deletions
|
@ -22,21 +22,22 @@ M.ui = {
|
||||||
theme_toggle = { "onedark", "one_light" },
|
theme_toggle = { "onedark", "one_light" },
|
||||||
theme = "onedark", -- default theme
|
theme = "onedark", -- default theme
|
||||||
transparency = false,
|
transparency = false,
|
||||||
|
|
||||||
|
statusline = {
|
||||||
|
separator_style = "default", -- default/round/block/arrow
|
||||||
|
config = "%!v:lua.require'ui.statusline'.run()",
|
||||||
|
override = {},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
M.plugins = {
|
M.plugins = {
|
||||||
override = {},
|
override = {},
|
||||||
remove = {},
|
remove = {},
|
||||||
user = {},
|
user = {},
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
lspconfig = {
|
lspconfig = {
|
||||||
setup_lspconf = "", -- path of lspconfig file
|
setup_lspconf = "", -- path of lspconfig file
|
||||||
},
|
},
|
||||||
statusline = {
|
|
||||||
separator_style = "default", -- default/round/block/arrow
|
|
||||||
config = "%!v:lua.require'ui.statusline'.run()",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,31 @@ M.on_file_open = function(plugin_name)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- lspinstaller & lspconfig cmds for lazyloading
|
||||||
|
M.lsp_cmds = {
|
||||||
|
"LspInfo",
|
||||||
|
"LspStart",
|
||||||
|
"LspRestart",
|
||||||
|
"LspStop",
|
||||||
|
"LspInstall",
|
||||||
|
"LspUnInstall",
|
||||||
|
"LspUnInstallAll",
|
||||||
|
"LspInstall",
|
||||||
|
"LspInstallInfo",
|
||||||
|
"LspInstallLog",
|
||||||
|
"LspLog",
|
||||||
|
"LspPrintInstalled",
|
||||||
|
}
|
||||||
|
|
||||||
|
M.treesitter_cmds = {
|
||||||
|
"TSInstall",
|
||||||
|
"TSBufEnable",
|
||||||
|
"TSBufDisable",
|
||||||
|
"TSEnable",
|
||||||
|
"TSDisable",
|
||||||
|
"TSModuleInhfo",
|
||||||
|
}
|
||||||
|
|
||||||
M.gitsigns = function()
|
M.gitsigns = function()
|
||||||
-- taken from https://github.com/max397574
|
-- taken from https://github.com/max397574
|
||||||
vim.api.nvim_create_autocmd({ "BufRead" }, {
|
vim.api.nvim_create_autocmd({ "BufRead" }, {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- n, v, i, tare mode names
|
-- n, v, i, t = mode names
|
||||||
|
|
||||||
local function termcodes(str)
|
local function termcodes(str)
|
||||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||||
|
|
|
@ -12,7 +12,7 @@ g.did_load_filetypes = 0
|
||||||
g.do_filetype_lua = 1
|
g.do_filetype_lua = 1
|
||||||
|
|
||||||
opt.laststatus = 3 -- global statusline
|
opt.laststatus = 3 -- global statusline
|
||||||
opt.statusline = config.plugins.options.statusline.config
|
opt.statusline = config.ui.statusline.config
|
||||||
opt.showmode = false
|
opt.showmode = false
|
||||||
|
|
||||||
opt.title = true
|
opt.title = true
|
||||||
|
|
|
@ -66,6 +66,7 @@ local plugins = {
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").on_file_open "nvim-treesitter"
|
require("core.lazy_load").on_file_open "nvim-treesitter"
|
||||||
end,
|
end,
|
||||||
|
cmd = require("core.lazy_load").treesitter_cmds,
|
||||||
run = ":TSUpdate",
|
run = ":TSUpdate",
|
||||||
config = function()
|
config = function()
|
||||||
require "plugins.configs.treesitter"
|
require "plugins.configs.treesitter"
|
||||||
|
@ -87,6 +88,7 @@ local plugins = {
|
||||||
|
|
||||||
["williamboman/nvim-lsp-installer"] = {
|
["williamboman/nvim-lsp-installer"] = {
|
||||||
opt = true,
|
opt = true,
|
||||||
|
cmd = require("core.lazy_load").lsp_cmds,
|
||||||
setup = function()
|
setup = function()
|
||||||
require("core.lazy_load").on_file_open "nvim-lsp-installer"
|
require("core.lazy_load").on_file_open "nvim-lsp-installer"
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -40,6 +40,28 @@ M.lspkind = {
|
||||||
Package = "",
|
Package = "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
M.statusline_separators = {
|
||||||
|
default = {
|
||||||
|
left = "",
|
||||||
|
right = " ",
|
||||||
|
},
|
||||||
|
|
||||||
|
round = {
|
||||||
|
left = "",
|
||||||
|
right = "",
|
||||||
|
},
|
||||||
|
|
||||||
|
block = {
|
||||||
|
left = "█",
|
||||||
|
right = "█",
|
||||||
|
},
|
||||||
|
|
||||||
|
arrow = {
|
||||||
|
left = "",
|
||||||
|
right = "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
M.devicons = {
|
M.devicons = {
|
||||||
default_icon = {
|
default_icon = {
|
||||||
icon = "",
|
icon = "",
|
||||||
|
|
|
@ -1,30 +1,8 @@
|
||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
local sep_style = require("ui.icons").statusline_separators
|
||||||
local sep_style = {
|
local user_sep = require("core.utils").load_config().ui.statusline.separator_style
|
||||||
default = {
|
local sep_l = sep_style[user_sep]["left"]
|
||||||
left = "",
|
local sep_r = sep_style[user_sep]["right"]
|
||||||
right = " ",
|
|
||||||
},
|
|
||||||
|
|
||||||
round = {
|
|
||||||
left = "",
|
|
||||||
right = "",
|
|
||||||
},
|
|
||||||
|
|
||||||
block = {
|
|
||||||
left = "█",
|
|
||||||
right = "█",
|
|
||||||
},
|
|
||||||
|
|
||||||
arrow = {
|
|
||||||
left = "",
|
|
||||||
right = "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local user_sep_style = require("core.utils").load_config().plugins.options.statusline.separator_style
|
|
||||||
local sep_l = sep_style[user_sep_style]["left"]
|
|
||||||
local sep_r = sep_style[user_sep_style]["right"]
|
|
||||||
|
|
||||||
local modes = {
|
local modes = {
|
||||||
["n"] = { "NORMAL", "St_NormalMode" },
|
["n"] = { "NORMAL", "St_NormalMode" },
|
||||||
|
@ -64,34 +42,22 @@ M.mode = function()
|
||||||
return current_mode .. mode_sep1 .. "%#ST_EmptySpace#" .. sep_r
|
return current_mode .. mode_sep1 .. "%#ST_EmptySpace#" .. sep_r
|
||||||
end
|
end
|
||||||
|
|
||||||
M.fileicon = function()
|
M.fileInfo = function()
|
||||||
local icon = " "
|
local icon = " "
|
||||||
|
local filename = (fn.expand "%" == "" and "Empty ") or fn.expand "%:t"
|
||||||
|
|
||||||
local filename = fn.fnamemodify(fn.expand "%:t", ":r")
|
if filename ~= "Empty " then
|
||||||
local extension = fn.expand "%:e"
|
|
||||||
|
|
||||||
if filename ~= "" then
|
|
||||||
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
||||||
|
|
||||||
if devicons_present then
|
if devicons_present then
|
||||||
local ft_icon = devicons.get_icon(filename, extension)
|
local ft_icon = devicons.get_icon(filename, fn.expand "%:e")
|
||||||
icon = (ft_icon ~= nil and " " .. ft_icon) or ""
|
icon = (ft_icon ~= nil and " " .. ft_icon) or ""
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return "%#St_file_info#" .. icon
|
|
||||||
end
|
|
||||||
|
|
||||||
M.filename = function()
|
|
||||||
local filename = fn.fnamemodify(fn.expand "%:t", ":r")
|
|
||||||
|
|
||||||
if filename == "" then
|
|
||||||
filename = "Empty "
|
|
||||||
else
|
|
||||||
filename = " " .. filename .. " "
|
filename = " " .. filename .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
return "%#St_file_info#" .. filename .. "%#St_file_sep#" .. sep_r
|
return "%#St_file_info#" .. icon .. filename .. "%#St_file_sep#" .. sep_r
|
||||||
end
|
end
|
||||||
|
|
||||||
M.git = function()
|
M.git = function()
|
||||||
|
@ -105,9 +71,8 @@ M.git = function()
|
||||||
local changed = (git_status.changed and git_status.changed ~= 0) and (" " .. git_status.changed) or ""
|
local changed = (git_status.changed and git_status.changed ~= 0) and (" " .. git_status.changed) or ""
|
||||||
local removed = (git_status.removed and git_status.removed ~= 0) and (" " .. git_status.removed) or ""
|
local removed = (git_status.removed and git_status.removed ~= 0) and (" " .. git_status.removed) or ""
|
||||||
local branch_name = " " .. git_status.head .. " "
|
local branch_name = " " .. git_status.head .. " "
|
||||||
local git_info = branch_name .. added .. changed .. removed
|
|
||||||
|
|
||||||
return "%#St_gitIcons#" .. git_info
|
return "%#St_gitIcons#" .. branch_name .. added .. changed .. removed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- LSP STUFF
|
-- LSP STUFF
|
||||||
|
@ -130,10 +95,6 @@ M.LSP_progress = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.LSP_Diagnostics = function()
|
M.LSP_Diagnostics = function()
|
||||||
if not #vim.diagnostic.get(0) then
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
|
local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR })
|
||||||
local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
|
local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
|
||||||
local hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT })
|
local hints = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT })
|
||||||
|
@ -148,48 +109,36 @@ M.LSP_Diagnostics = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.LSP_status = function()
|
M.LSP_status = function()
|
||||||
local clients = vim.lsp.get_active_clients()
|
for _, client in ipairs(vim.lsp.get_active_clients()) do
|
||||||
local name = false
|
|
||||||
for _, client in ipairs(clients) do
|
|
||||||
if client.attached_buffers[vim.api.nvim_get_current_buf()] then
|
if client.attached_buffers[vim.api.nvim_get_current_buf()] then
|
||||||
name = client.name
|
return (vim.o.columns > 70 and "%#St_LspStatus#" .. " LSP ~ " .. client.name .. " ") or " LSP "
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local content = name and " LSP ~ " .. name .. " " or false
|
|
||||||
return content and ("%#St_LspStatus#" .. content) or ""
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.cwd = function()
|
M.cwd = function()
|
||||||
local left_sep = "%#St_cwd_sep#" .. sep_l
|
|
||||||
local dir_icon = "%#St_cwd_icon#" .. " "
|
local dir_icon = "%#St_cwd_icon#" .. " "
|
||||||
local dir_name = "%#St_cwd_text#" .. " " .. fn.fnamemodify(fn.getcwd(), ":t") .. " "
|
local dir_name = "%#St_cwd_text#" .. " " .. fn.fnamemodify(fn.getcwd(), ":t") .. " "
|
||||||
return (vim.o.columns > 120 and left_sep .. dir_icon .. dir_name) or ""
|
return (vim.o.columns > 120 and ("%#St_cwd_sep#" .. sep_l .. dir_icon .. dir_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
M.cursor_position = function()
|
M.cursor_position = function()
|
||||||
local left_sep = "%#St_pos_sep#" .. sep_l
|
local left_sep = "%#St_pos_sep#" .. sep_l .. "%#St_pos_icon#" .. " "
|
||||||
local icon = "%#St_pos_icon#" .. " "
|
|
||||||
|
|
||||||
local current_line = fn.line "."
|
local current_line = fn.line "."
|
||||||
local total_line = fn.line "$"
|
local total_line = fn.line "$"
|
||||||
local text = math.modf((current_line / total_line) * 100) .. tostring "%%"
|
local text = math.modf((current_line / total_line) * 100) .. tostring "%%"
|
||||||
|
|
||||||
if current_line == 1 then
|
text = (current_line == 1 and "Top") or text
|
||||||
text = "Top"
|
text = (current_line == total_line and "Bot") or text
|
||||||
elseif current_line == total_line then
|
|
||||||
text = "Bot"
|
|
||||||
end
|
|
||||||
|
|
||||||
return left_sep .. icon .. "%#St_pos_text#" .. " " .. text .. " "
|
return left_sep .. "%#St_pos_text#" .. " " .. text .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run = function()
|
M.run = function()
|
||||||
return table.concat {
|
return table.concat {
|
||||||
M.mode(),
|
M.mode(),
|
||||||
M.fileicon(),
|
M.fileInfo(),
|
||||||
M.filename(),
|
|
||||||
M.git(),
|
M.git(),
|
||||||
|
|
||||||
"%=",
|
"%=",
|
||||||
|
@ -197,10 +146,12 @@ M.run = function()
|
||||||
"%=",
|
"%=",
|
||||||
|
|
||||||
M.LSP_Diagnostics(),
|
M.LSP_Diagnostics(),
|
||||||
M.LSP_status(),
|
M.LSP_status() or "",
|
||||||
M.cwd(),
|
M.cwd(),
|
||||||
M.cursor_position(),
|
M.cursor_position(),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.statusline.override)
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in a new issue