mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-22 00:49:01 +02:00
add: tidy up the code, more modular
This commit is contained in:
parent
1545d8335d
commit
1f424a1225
10 changed files with 583 additions and 522 deletions
|
@ -3,173 +3,24 @@ return {
|
|||
"nvim-lualine/lualine.nvim",
|
||||
event = { "InsertEnter", "BufRead", "BufNewFile" },
|
||||
config = function()
|
||||
local hide_in_width = function()
|
||||
return vim.fn.winwidth(0) > 80
|
||||
end
|
||||
local icons = require("user.icons")
|
||||
|
||||
local getLeftSubstring = function(word, length)
|
||||
if #word > length then
|
||||
return string.sub(word, 1, length) .. "..."
|
||||
else
|
||||
return word
|
||||
end
|
||||
end
|
||||
|
||||
local treesitter = {
|
||||
function()
|
||||
return icons.ui.Paint .. " TS"
|
||||
end,
|
||||
color = function()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
local ts = vim.treesitter.highlighter.active[buf]
|
||||
return { fg = ts and not vim.tbl_isempty(ts) and "#50fa7b" or "#FF5555" }
|
||||
end,
|
||||
cond = hide_in_width,
|
||||
}
|
||||
|
||||
-- start for lsp
|
||||
local list_registered_providers_names = function(filetype)
|
||||
local s = require("null-ls.sources")
|
||||
local available_sources = s.get_available(filetype)
|
||||
local registered = {}
|
||||
for _, source in ipairs(available_sources) do
|
||||
for method in pairs(source.methods) do
|
||||
registered[method] = registered[method] or {}
|
||||
table.insert(registered[method], source.name)
|
||||
end
|
||||
end
|
||||
return registered
|
||||
end
|
||||
|
||||
local null_ls = require("null-ls")
|
||||
-- for formatter
|
||||
local list_registered = function(filetype)
|
||||
local method = null_ls.methods.FORMATTING
|
||||
local registered_providers = list_registered_providers_names(filetype)
|
||||
return registered_providers[method] or {}
|
||||
end
|
||||
|
||||
--- for linter
|
||||
local alternative_methods = {
|
||||
null_ls.methods.DIAGNOSTICS,
|
||||
null_ls.methods.DIAGNOSTICS_ON_OPEN,
|
||||
null_ls.methods.DIAGNOSTICS_ON_SAVE,
|
||||
}
|
||||
|
||||
local linter_list_registered = function(filetype)
|
||||
local registered_providers = list_registered_providers_names(filetype)
|
||||
local providers_for_methods = vim.iter(vim.tbl_map(function(m)
|
||||
return registered_providers[m] or {}
|
||||
end, alternative_methods))
|
||||
|
||||
return providers_for_methods
|
||||
end
|
||||
-- end for lsp
|
||||
|
||||
local lsp_info = {
|
||||
function()
|
||||
local msg = "LSP Inactive"
|
||||
local buf_ft = vim.bo.filetype
|
||||
-- start register
|
||||
local buf_clients = {}
|
||||
buf_clients = vim.lsp.get_clients({ bufnr = 0 })
|
||||
local buf_client_names = {}
|
||||
if next(buf_clients) == nil then
|
||||
-- TODO: clean up this if statement
|
||||
if type(msg) == "boolean" or #msg == 0 then
|
||||
return "LSP Inactive"
|
||||
end
|
||||
return msg
|
||||
end
|
||||
-- add client
|
||||
for _, client in pairs(buf_clients) do
|
||||
if client.name ~= "null-ls" and client.name ~= "copilot" then
|
||||
table.insert(buf_client_names, client.name)
|
||||
end
|
||||
end
|
||||
-- add formatter
|
||||
local supported_formatters = list_registered(buf_ft)
|
||||
vim.list_extend(buf_client_names, supported_formatters)
|
||||
-- add linter
|
||||
local supported_linters = linter_list_registered(buf_ft)
|
||||
vim.list_extend(buf_client_names, supported_linters)
|
||||
-- decomple
|
||||
local unique_client_names = vim.fn.uniq(buf_client_names)
|
||||
local msg = table.concat(unique_client_names, ", ")
|
||||
return msg
|
||||
end,
|
||||
icon = icons.ui.Gear .. "",
|
||||
padding = 1,
|
||||
}
|
||||
|
||||
local diagnostics = {
|
||||
"diagnostics",
|
||||
sources = { "nvim_diagnostic" },
|
||||
sections = { "error", "warn" },
|
||||
symbols = {
|
||||
error = icons.diagnostics.BoldError .. " ",
|
||||
warn = icons.diagnostics.BoldWarning .. " ",
|
||||
},
|
||||
colored = true,
|
||||
update_in_insert = false,
|
||||
always_visible = false,
|
||||
}
|
||||
|
||||
local diff = {
|
||||
"diff",
|
||||
colored = true,
|
||||
symbols = {
|
||||
added = icons.git.LineAdded .. " ",
|
||||
modified = icons.git.LineModified .. " ",
|
||||
removed = icons.git.LineRemoved .. " ",
|
||||
},
|
||||
cond = hide_in_width,
|
||||
}
|
||||
|
||||
local spaces = function()
|
||||
return icons.ui.Tab .. " " .. vim.api.nvim_get_option_value(0, "shiftwidth")
|
||||
end
|
||||
|
||||
local mode = {
|
||||
"mode",
|
||||
padding = 1,
|
||||
separator = { left = " " },
|
||||
fmt = function(str)
|
||||
return icons.ui.Neovim .. " " .. str
|
||||
end,
|
||||
}
|
||||
|
||||
local get_branch = function()
|
||||
if vim.b.gitsigns_head ~= nil then
|
||||
return icons.git.Branch2 .. " " .. getLeftSubstring(vim.b.gitsigns_head, 6)
|
||||
else
|
||||
return icons.git.Branch2 .. vim.fn.fnamemodify("", ":t")
|
||||
end
|
||||
end
|
||||
|
||||
local component = require("user.utils.lualine_component")
|
||||
local treesitter = component.treesitter
|
||||
local lsp_info = component.lsp_info
|
||||
local diagnostics = component.diagnostics
|
||||
local diff = component.diff
|
||||
local spaces = component.spaces
|
||||
local mode = component.mode
|
||||
local get_branch = component.get_branch
|
||||
local lsp_progress = {}
|
||||
local data_ok, lspprogress = pcall(require, "lsp-progress")
|
||||
if data_ok then
|
||||
lsp_progress = lspprogress.progress
|
||||
end
|
||||
local colors = {
|
||||
blue = "#50fa7b",
|
||||
cyan = "#f1fa8c",
|
||||
black = "#1a1b26",
|
||||
black_transparant = "none",
|
||||
white = "#c6c6c6",
|
||||
red = "#ff757f",
|
||||
skyblue_1 = "#bd93f9",
|
||||
grey = "#5f6a8e",
|
||||
yellow = "#ffb86c",
|
||||
fg_gutter = "#3b4261",
|
||||
green1 = "#bd93f9",
|
||||
}
|
||||
local colors = component.colors
|
||||
|
||||
-- check config for theme
|
||||
local set_theme
|
||||
local bubbles_theme = {}
|
||||
local bubbles_theme
|
||||
local data_exists, config = pcall(require, "core.config")
|
||||
if data_exists then
|
||||
if config.colorscheme ~= nil then
|
||||
|
@ -204,40 +55,7 @@ return {
|
|||
end
|
||||
end
|
||||
|
||||
bubbles_theme = {
|
||||
normal = {
|
||||
a = { fg = colors.black, bg = colors.skyblue_1 },
|
||||
b = { fg = colors.white, bg = colors.grey },
|
||||
c = { fg = colors.white, bg = colors.black_transparant },
|
||||
},
|
||||
|
||||
insert = {
|
||||
a = { fg = colors.black, bg = colors.blue },
|
||||
b = { fg = colors.blue, bg = colors.grey },
|
||||
},
|
||||
visual = {
|
||||
a = { fg = colors.black, bg = colors.cyan },
|
||||
b = { fg = colors.cyan, bg = colors.grey },
|
||||
},
|
||||
replace = {
|
||||
a = { bg = colors.red, fg = colors.black },
|
||||
b = { bg = colors.fg_gutter, fg = colors.red },
|
||||
},
|
||||
command = {
|
||||
a = { bg = colors.yellow, fg = colors.black },
|
||||
b = { bg = colors.fg_gutter, fg = colors.yellow },
|
||||
},
|
||||
terminal = {
|
||||
a = { bg = colors.green1, fg = colors.black },
|
||||
b = { bg = colors.fg_gutter, fg = colors.green1 },
|
||||
},
|
||||
inactive = {
|
||||
a = { fg = colors.white, bg = colors.black_transparant },
|
||||
b = { fg = colors.white, bg = colors.black_transparant },
|
||||
c = { fg = colors.black, bg = colors.black_transparant },
|
||||
},
|
||||
}
|
||||
|
||||
bubbles_theme = component.bubbles_theme(colors)
|
||||
if set_theme == "auto" then
|
||||
bubbles_theme = vim.fn.fnamemodify("auto", ":t")
|
||||
end
|
||||
|
@ -269,7 +87,7 @@ return {
|
|||
},
|
||||
lualine_b = { get_branch },
|
||||
lualine_c = { diff, lsp_info, lsp_progress },
|
||||
lualine_x = { diagnostics, treesitter, spaces, "filetype" },
|
||||
lualine_x = { diagnostics, spaces, treesitter, "filetype" },
|
||||
lualine_y = { "progress" },
|
||||
lualine_z = {
|
||||
{ "location", separator = { right = " " }, padding = 1 },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue