add nvim_gps to statusline | populate renamer popup with old value

This commit is contained in:
siduck 2022-06-02 23:29:15 +05:30
parent 9f48587d63
commit 9b7b44f74f
5 changed files with 319 additions and 191 deletions

View file

@ -0,0 +1,44 @@
local present, gps = pcall(require, "nvim-gps")
if not present then
return
end
local icons = require "plugins.configs.lspkind_icons"
local options = {
icons = {
["class-name"] = "%#CmpItemKindClass#" .. icons.Class .. "%*" .. " ",
["function-name"] = "%#CmpItemKindFunction#" .. icons.Function .. "%*" .. " ",
["method-name"] = "%#CmpItemKindMethod#" .. icons.Method .. "%*" .. " ",
["container-name"] = "%#CmpItemKindProperty#" .. icons.Object .. "%*" .. " ",
["tag-name"] = "%#CmpItemKindKeyword#" .. icons.Tag .. "%*" .. " ",
["mapping-name"] = "%#CmpItemKindProperty#" .. icons.Object .. "%*" .. " ",
["sequence-name"] = "%CmpItemKindProperty#" .. icons.Array .. "%*" .. " ",
["null-name"] = "%CmpItemKindField#" .. icons.Field .. "%*" .. " ",
["boolean-name"] = "%CmpItemKindValue#" .. icons.Boolean .. "%*" .. " ",
["integer-name"] = "%CmpItemKindValue#" .. icons.Number .. "%*" .. " ",
["float-name"] = "%CmpItemKindValue#" .. icons.Number .. "%*" .. " ",
["string-name"] = "%CmpItemKindValue#" .. icons.String .. "%*" .. " ",
["array-name"] = "%CmpItemKindProperty#" .. icons.Array .. "%*" .. " ",
["object-name"] = "%CmpItemKindProperty#" .. icons.Object .. "%*" .. " ",
["number-name"] = "%CmpItemKindValue#" .. icons.Number .. "%*" .. " ",
["table-name"] = "%CmpItemKindProperty#" .. icons.Table .. "%*" .. " ",
["date-name"] = "%CmpItemKindValue#" .. icons.Calendar .. "%*" .. " ",
["date-time-name"] = "%CmpItemKindValue#" .. icons.Table .. "%*" .. " ",
["inline-table-name"] = "%CmpItemKindProperty#" .. icons.Calendar .. "%*" .. " ",
["time-name"] = "%CmpItemKindValue#" .. icons.Watch .. "%*" .. " ",
["module-name"] = "%CmpItemKindModule#" .. icons.Module .. "%*" .. " ",
},
["lua"] = {
icons = {
["container-name"] = "%#CmpItemKindProperty#" .. icons.Table .. "%*" .. " ",
["mapping-name"] = "%#CmpItemKindProperty#" .. icons.Table .. "%*" .. " ",
["object-name"] = "%CmpItemKindProperty#" .. icons.Table .. "%*" .. " ",
},
},
}
gps.setup(options)

View file

@ -1,4 +1,4 @@
local icons = { return {
Text = "", Text = "",
Method = "", Method = "",
Function = "", Function = "",
@ -24,6 +24,13 @@ local icons = {
Event = "", Event = "",
Operator = "", Operator = "",
TypeParameter = "", TypeParameter = "",
Table = "",
Object = "",
Tag = "",
Array = "",
Boolean = "",
Number = "",
String = "",
Calendar = "",
Watch = "",
} }
return icons

View file

@ -127,9 +127,10 @@ M.luasnip = function()
history = true, history = true,
updateevents = "TextChanged,TextChangedI", updateevents = "TextChanged,TextChangedI",
} }
options = load_override(options, "L3MON4D3/LuaSnip")
options = load_override(options, "L3MON4D3/LuaSnip")
luasnip.config.set_config(options) luasnip.config.set_config(options)
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
end end
@ -205,10 +206,10 @@ M.lsp_handlers = function()
-- This is modified version of the above snippet -- This is modified version of the above snippet
vim.lsp.buf.rename = { vim.lsp.buf.rename = {
float = function() float = function()
local currName = vim.fn.expand "<cword>" local currName = vim.fn.expand "<cword>" .. " "
local win = require("plenary.popup").create(" ", { local win = require("plenary.popup").create(currName, {
title = currName, title = "Renamer",
style = "minimal", style = "minimal",
borderchars = { "", "", "", "", "", "", "", "" }, borderchars = { "", "", "", "", "", "", "", "" },
relative = "cursor", relative = "cursor",
@ -223,6 +224,7 @@ M.lsp_handlers = function()
local map_opts = { noremap = true, silent = true } local map_opts = { noremap = true, silent = true }
vim.cmd "normal w"
vim.cmd "startinsert" vim.cmd "startinsert"
vim.api.nvim_buf_set_keymap(0, "i", "<Esc>", "<cmd>stopinsert | q!<CR>", map_opts) vim.api.nvim_buf_set_keymap(0, "i", "<Esc>", "<cmd>stopinsert | q!<CR>", map_opts)
@ -265,6 +267,7 @@ M.gitsigns = function()
if not present then if not present then
return return
end end
local options = { local options = {
signs = { signs = {
add = { hl = "DiffAdd", text = "", numhl = "GitSignsAddNr" }, add = { hl = "DiffAdd", text = "", numhl = "GitSignsAddNr" },

View file

@ -1,4 +1,9 @@
local present, feline = pcall(require, "feline") local present, feline = pcall(require, "feline")
local fn = vim.fn
local function get_color(group, attr)
return fn.synIDattr(fn.synIDtrans(fn.hlID(group)), attr)
end
if not present then if not present then
return return
@ -9,131 +14,124 @@ local options = {
lsp_severity = vim.diagnostic.severity, lsp_severity = vim.diagnostic.severity,
} }
options.icons = {
mode_icon = "",
position_icon = "",
empty_file = " Empty ",
dir = "",
clock = "",
}
options.icon_styles = { options.icon_styles = {
-- mix of slant + round
default = { default = {
left = "", left = "",
right = "", right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
arrow = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
block = {
left = " ",
right = " ",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
}, },
round = { round = {
left = "", left = "",
right = "", right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
}, },
slant = { block = {
left = "", left = "",
right = "", right = "",
main_icon = "", },
vi_mode_icon = "",
position_icon = "", arrow = {
left = "",
right = "",
}, },
} }
options.separator_style = local statusline_opt = require("core.utils").load_config().plugins.options.statusline.separator_style
options.icon_styles[require("core.utils").load_config().plugins.options.statusline.separator_style] options.separator_style = options.icon_styles[statusline_opt]
options.main_icon = { options.mode_icon = {
provider = options.separator_style.main_icon, provider = options.icons.mode_icon,
hl = "FelineIcon", hl = function()
return {
right_sep = { fg = get_color("Feline", "bg#"),
str = options.separator_style.right, bg = get_color(options.mode_hlgroups[fn.mode()][2], "fg#"),
hl = "FelineIconSeparator", }
},
}
options.file_name = {
provider = function()
local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e"
local icon = require("nvim-web-devicons").get_icon(filename, extension)
if icon == nil then
icon = ""
return icon
end
return " " .. icon .. " " .. filename .. " "
end, end,
hl = "FelineFileName",
right_sep = { right_sep = {
str = options.separator_style.right, str = options.separator_style.right,
hl = "FelineFileName_Separator", hl = function()
return {
fg = get_color(options.mode_hlgroups[fn.mode()][2], "fg#"),
bg = get_color("Feline_EmptySpace", "fg#"),
}
end,
}, },
} }
options.dir_name = { -- MODES
options.mode_hlgroups = {
["n"] = { "Normal", "Feline_NormalMode" },
["no"] = { "N-PENDING", "Feline_NormalMode" },
["i"] = { "INSERT", "Feline_InsertMode" },
["ic"] = { "INSERT", "Feline_InsertMode" },
["t"] = { "TERMINAL", "Feline_TerminalMode" },
["v"] = { "VISUAL", "Feline_VisualMode" },
["V"] = { "V-LINE", "Feline_VisualMode" },
[""] = { "V-BLOCK", "Feline_VisualMode" },
["R"] = { "REPLACE", "Feline_ReplaceMode" },
["Rv"] = { "V-REPLACE", "Feline_ReplaceMode" },
["s"] = { "SELECT", "Feline_SelectMode" },
["S"] = { "S-LINE", "Feline_SelectMode" },
[""] = { "S-BLOCK", "Feline_SelectMode" },
["c"] = { "COMMAND", "Feline_CommandMode" },
["cv"] = { "COMMAND", "Feline_CommandMode" },
["ce"] = { "COMMAND", "Feline_CommandMode" },
["r"] = { "PROMPT", "Feline_ConfirmMode" },
["rm"] = { "MORE", "Feline_ConfirmMode" },
["r?"] = { "CONFIRM", "Feline_ConfirmMode" },
["!"] = { "SHELL", "Feline_TerminalMode" },
}
options.vi_mode = {
provider = function() provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") return " " .. options.mode_hlgroups[fn.mode()][1] .. " "
return "" .. dir_name .. " "
end, end,
hl = "FelineDirName", hl = function()
return options.mode_hlgroups[fn.mode()][2]
end,
right_sep = { right_sep = {
str = options.separator_style.right, str = options.separator_style.right,
hl = "FelineDirName_Separator", hl = function()
return {
fg = get_color("Feline_EmptySpace", "bg#"),
bg = get_color("Feline_nvim_gps", "bg#"),
}
end,
}, },
} }
-- Git options.cwd = {
-- icon
options.diff = { left_sep = {
add = { str = " " .. options.icons.dir,
provider = "git_diff_added", hl = "FelineCwd",
hl = "Feline_diffIcons",
icon = "",
}, },
change = { -- dirname
provider = "git_diff_changed", provider = function()
hl = "Feline_diffIcons", local dir_name = fn.fnamemodify(fn.getcwd(), ":t")
return " " .. dir_name .. " "
end,
icon = "", hl = "FelineCwd",
},
remove = {
provider = "git_diff_removed",
hl = "Feline_diffIcons",
icon = "",
},
}
options.git_branch = {
provider = "git_branch",
hl = "Feline_diffIcons",
icon = "",
}
options.empty_space_git = {
provider = " " .. options.separator_style.left,
hl = "Feline_EmptySpace_git",
} }
-- lsp -- lsp
options.diagnostic = { options.diagnostic = {
error = { error = {
provider = "diagnostic_errors", provider = "diagnostic_errors",
@ -174,7 +172,7 @@ options.diagnostic = {
}, },
} }
options.lsp_icon = { options.lsp_status = {
provider = function() provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then if next(vim.lsp.buf_get_clients()) ~= nil then
local lsp_name = vim.lsp.get_active_clients()[1].name local lsp_name = vim.lsp.get_active_clients()[1].name
@ -192,98 +190,129 @@ options.lsp_progress = {
provider = function() provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1] local Lsp = vim.lsp.util.get_progress_messages()[1]
if Lsp then if not Lsp then
return ""
end
local msg = Lsp.message or "" local msg = Lsp.message or ""
local percentage = Lsp.percentage or 0 local percentage = Lsp.percentage or 0
local title = Lsp.title or "" local title = Lsp.title or ""
local spinners = { "", "", "", "", "", "", "", "", "", "" } local spinners = { "", "" }
local success_icon = {
"",
"",
"",
}
local ms = vim.loop.hrtime() / 1000000 local ms = vim.loop.hrtime() / 1000000
local frame = math.floor(ms / 120) % #spinners local frame = math.floor(ms / 120) % #spinners
if percentage >= 70 then
return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage)
end
return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage) return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
end
return ""
end, end,
hl = "Feline_LspProgress", hl = "Feline_LspProgress",
} }
-- MODES -- Git
options.mode_hlgroups = { options.diff = {
["n"] = { "NORMAL", "Feline_NormalMode" }, add = {
["no"] = { "N-PENDING", "Feline_NormalMode" }, provider = "git_diff_added",
["i"] = { "INSERT", "Feline_InsertMode" }, hl = "Feline_diffIcons",
["ic"] = { "INSERT", "Feline_InsertMode" }, icon = "",
["t"] = { "TERMINAL", "Feline_TerminalMode" }, },
["v"] = { "VISUAL", "Feline_VisualMode" },
["V"] = { "V-LINE", "Feline_VisualMode" }, change = {
[""] = { "V-BLOCK", "Feline_VisualMode" }, provider = "git_diff_changed",
["R"] = { "REPLACE", "Feline_ReplaceMode" }, hl = "Feline_diffIcons",
["Rv"] = { "V-REPLACE", "Feline_ReplaceMode" }, icon = "",
["s"] = { "SELECT", "Feline_SelectMode" }, },
["S"] = { "S-LINE", "Feline_SelectMode" },
[""] = { "S-BLOCK", "Feline_SelectMode" }, remove = {
["c"] = { "COMMAND", "Feline_CommandMode" }, provider = "git_diff_removed",
["cv"] = { "COMMAND", "Feline_CommandMode" }, hl = "Feline_diffIcons",
["ce"] = { "COMMAND", "Feline_CommandMode" }, icon = "",
["r"] = { "PROMPT", "Feline_ConfirmMode" }, },
["rm"] = { "MORE", "Feline_ConfirmMode" },
["r?"] = { "CONFIRM", "Feline_ConfirmMode" },
["!"] = { "SHELL", "Feline_TerminalMode" },
} }
local fn = vim.fn options.git_branch = {
provider = "git_branch",
hl = "Feline_diffIcons",
icon = "",
local function get_color(group, attr) right_sep = {
return fn.synIDattr(fn.synIDtrans(fn.hlID(group)), attr) str = " ",
end hl = "Feline_diffIcons",
},
options.empty_space = {
provider = " " .. options.separator_style.left,
hl = "Feline_EmptySpace",
} }
-- this matches the vi mode color options.file_info = {
options.empty_spaceColored = { left_sep = {
provider = options.separator_style.left, str = options.separator_style.left,
hl = function() hl = "Feline_file_info_sep",
return { },
fg = get_color(options.mode_hlgroups[vim.fn.mode()][2], "fg#"),
bg = get_color("Feline_EmptySpace", "bg#"),
}
end,
}
options.mode_icon = { -- file icon
provider = options.separator_style.vi_mode_icon,
hl = function()
return {
fg = get_color("Feline", "bg#"),
bg = get_color(options.mode_hlgroups[vim.fn.mode()][2], "fg#"),
}
end,
}
options.mode_name = {
provider = function() provider = function()
return " " .. options.mode_hlgroups[vim.fn.mode()][1] .. " " local filename = fn.expand "%:t"
local extension = fn.expand "%:e"
local icon = require("nvim-web-devicons").get_icon(filename, extension)
if icon == nil and fn.expand "%:t" == "" then
return options.icons.empty_file
else
icon = icon .. " " or ""
return icon
end
end, end,
hl = "Feline_file_info",
-- file name
right_sep = {
str = function()
local filename = fn.expand "%:t"
return " " .. fn.fnamemodify(filename, ":r") .. " "
end,
hl = function() hl = function()
return options.mode_hlgroups[vim.fn.mode()][2] return {
fg = get_color("Feline_file_info", "bg#"),
bg = get_color("Feline_file_info", "fg#"),
}
end, end,
},
}
options.nvim_gps = {
provider = function()
-- nvim-gps loads at cursorMoved so need to handle this
local gps_loaded, gps = pcall(require, "nvim-gps")
if not gps_loaded then
return
end
return " " .. gps.get_location()
end,
enabled = function()
local gps_loaded, gps = pcall(require, "nvim-gps")
if not gps_loaded then
return false
end
return gps.is_available()
end,
right_sep = {
str = " ",
hl = "Feline_nvim_gps",
},
hl = "Feline_nvim_gps",
}
options.separator_left = {
provider = options.separator_style.right,
hl = "Feline_EmptySpace",
} }
options.separator_right = { options.separator_right = {
@ -291,24 +320,63 @@ options.separator_right = {
hl = "Feline_EmptySpace", hl = "Feline_EmptySpace",
} }
options.separator_right2 = { options.separator_right_file = {
provider = options.separator_style.left, provider = options.separator_style.left,
hl = "Feline_PositionSeparator", hl = function()
return {
fg = get_color("Feline_EmptySpace", "fg#"),
bg = get_color("Feline_nvim_gps", "bg#"),
}
end,
} }
options.position_icon = { options.time = {
provider = options.separator_style.position_icon, left_sep = {
hl = "Feline_PositionIcon", str = options.separator_style.left,
hl = function()
return {
fg = get_color("Feline_time", "fg#"),
bg = get_color("Feline_EmptySpace", "fg#"),
}
end,
},
icon = {
str = options.icons.clock,
hl = function()
return {
fg = get_color("Feline_time", "bg#"),
bg = get_color("Feline_time", "fg#"),
}
end,
},
provider = function()
return " " .. fn.strftime "%H:%M" .. " "
end,
hl = "Feline_time",
} }
options.current_line = { options.current_line = {
left_sep = {
str = options.separator_style.left,
hl = "Feline_PositionSeparator",
},
icon = {
str = options.icons.position_icon,
hl = "Feline_PositionIcon",
},
provider = function() provider = function()
local current_line = vim.fn.line "." local current_line = fn.line "."
local total_line = vim.fn.line "$" local total_line = fn.line "$"
if current_line == 1 then if current_line == 1 then
return " Top " return " Top "
elseif current_line == vim.fn.line "$" then elseif current_line == fn.line "$" then
return " Bot " return " Bot "
end end
local result, _ = math.modf((current_line / total_line) * 100) local result, _ = math.modf((current_line / total_line) * 100)
@ -332,34 +400,33 @@ options.middle = {}
options.right = {} options.right = {}
-- left -- left
add_table(options.left, options.main_icon) add_table(options.left, options.mode_icon)
add_table(options.left, options.file_name) add_table(options.left, options.separator_left)
add_table(options.left, options.dir_name) add_table(options.left, options.vi_mode)
add_table(options.left, options.cwd)
-- lsp -- lsp
add_table(options.left, options.lsp_icon) add_table(options.left, options.lsp_status)
add_table(options.left, options.diagnostic.error) add_table(options.left, options.diagnostic.error)
add_table(options.left, options.diagnostic.warning) add_table(options.left, options.diagnostic.warning)
add_table(options.left, options.diagnostic.hint) add_table(options.left, options.diagnostic.hint)
add_table(options.left, options.diagnostic.info) add_table(options.left, options.diagnostic.info)
add_table(options.middle, options.lsp_progress) add_table(options.middle, options.lsp_progress)
add_table(options.middle, options.nvim_gps)
-- right
-- git diffs -- git diffs
add_table(options.right, options.diff.add) add_table(options.right, options.diff.add)
add_table(options.right, options.diff.change) add_table(options.right, options.diff.change)
add_table(options.right, options.diff.remove) add_table(options.right, options.diff.remove)
add_table(options.right, options.git_branch) add_table(options.right, options.git_branch)
add_table(options.right, options.empty_space_git)
add_table(options.right, options.empty_spaceColored) add_table(options.right, options.separator_right_file)
add_table(options.right, options.mode_icon) add_table(options.right, options.file_info)
add_table(options.right, options.mode_name)
add_table(options.right, options.separator_right)
add_table(options.right, options.time)
add_table(options.right, options.separator_right) add_table(options.right, options.separator_right)
add_table(options.right, options.separator_right2)
add_table(options.right, options.position_icon)
add_table(options.right, options.current_line) add_table(options.right, options.current_line)
-- Initialize the components table -- Initialize the components table

View file

@ -36,6 +36,13 @@ local plugins = {
end, end,
}, },
["SmiteshP/nvim-gps"] = {
event = "CursorMoved",
config = function()
require "plugins.configs.gps"
end,
},
["akinsho/bufferline.nvim"] = { ["akinsho/bufferline.nvim"] = {
after = "nvim-web-devicons", after = "nvim-web-devicons",
config = function() config = function()