refactor: restructured utils module for better code organization
This commit is contained in:
+18
-16
@@ -2,7 +2,8 @@
|
||||
-- │ Lualine │
|
||||
-- ╰─────────────────────────────────────────────────────────╯
|
||||
|
||||
local utils = require("utils.rootiest")
|
||||
local utils = require("utils")
|
||||
local rootils = utils.rootiest
|
||||
|
||||
return {
|
||||
"nvim-lualine/lualine.nvim",
|
||||
@@ -100,22 +101,21 @@ return {
|
||||
},
|
||||
{
|
||||
function()
|
||||
return require("utils.wakatime_stats").get_icon_with_text()
|
||||
return utils.wakatime_stats.get_icon_with_text()
|
||||
end,
|
||||
color = function()
|
||||
local wakatime_stats = require("utils.wakatime_stats")
|
||||
return wakatime_stats.get_color()
|
||||
return utils.wakatime_stats.get_color()
|
||||
end,
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(100)
|
||||
return rootils.is_window_wide_enough(100)
|
||||
end,
|
||||
},
|
||||
{
|
||||
function()
|
||||
return require("utils.music_stats").get_icon_with_text()
|
||||
return utils.music_stats.get_icon_with_text()
|
||||
end,
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(100)
|
||||
return rootils.is_window_wide_enough(100)
|
||||
end,
|
||||
},
|
||||
},
|
||||
@@ -126,7 +126,7 @@ return {
|
||||
end,
|
||||
icon = " ",
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(80)
|
||||
return rootils.is_window_wide_enough(80)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -134,26 +134,26 @@ return {
|
||||
separator = " ",
|
||||
padding = { left = 1, right = 0 },
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(60)
|
||||
return rootils.is_window_wide_enough(60)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"location",
|
||||
padding = { left = 0, right = 1 },
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(40)
|
||||
return rootils.is_window_wide_enough(40)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"selection_count",
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(120)
|
||||
return rootils.is_window_wide_enough(120)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"filesize",
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(100)
|
||||
return rootils.is_window_wide_enough(100)
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -161,8 +161,9 @@ return {
|
||||
return require("arrow.statusline").text_for_statusline_with_icons()
|
||||
end,
|
||||
cond = function()
|
||||
return utils.is_window_wide_enough(100)
|
||||
return rootils.is_window_wide_enough(100)
|
||||
end,
|
||||
separator = { left = "", right = "" },
|
||||
},
|
||||
},
|
||||
lualine_z = {
|
||||
@@ -178,9 +179,10 @@ return {
|
||||
icon = " ",
|
||||
},
|
||||
{
|
||||
function()
|
||||
return " " .. os.date("%R")
|
||||
end,
|
||||
"datetime",
|
||||
-- options: default, us, uk, iso, or your own format string ("%H:%M", etc..)
|
||||
style = "%a %R",
|
||||
icon = " ",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
local cache = require("utils.cache_stats")
|
||||
local git = require("utils.git")
|
||||
local wakatime = require("utils.wakatime_stats")
|
||||
local music = require("utils.music_stats")
|
||||
local highlight = require("utils.highlight")
|
||||
local rootiest = require("utils.rootiest")
|
||||
|
||||
return {
|
||||
cache_stats = cache,
|
||||
git = git,
|
||||
wakatime_stats = wakatime,
|
||||
music_stats = music,
|
||||
highlight = highlight,
|
||||
rootiest = rootiest,
|
||||
}
|
||||
@@ -45,4 +45,56 @@ function M.get_date()
|
||||
return os.date("%Y-%m-%d")
|
||||
end
|
||||
|
||||
function M.code_action_on_selection()
|
||||
-- Capture the current mode
|
||||
local mode = vim.fn.mode()
|
||||
|
||||
-- Proceed only if in Visual mode
|
||||
if mode == "v" or mode == "V" or mode == "" then
|
||||
-- Capture the start and end positions of the selected text
|
||||
local start_pos = vim.fn.getpos("'<")
|
||||
local end_pos = vim.fn.getpos("'>")
|
||||
|
||||
-- Ensure positions are valid (non-nil)
|
||||
if start_pos and end_pos then
|
||||
-- Convert positions to zero-indexed (LSP format)
|
||||
local start_row = start_pos[2]
|
||||
local start_col = start_pos[3]
|
||||
local end_row = end_pos[2]
|
||||
local end_col = end_pos[3]
|
||||
|
||||
-- Ensure that the range is valid
|
||||
if
|
||||
start_row >= 0
|
||||
and start_col >= 0
|
||||
and end_row >= 0
|
||||
and end_col >= 0
|
||||
then
|
||||
-- Create the range
|
||||
local range = {
|
||||
start = { line = start_row, character = start_col },
|
||||
["end"] = { line = end_row, character = end_col },
|
||||
}
|
||||
|
||||
-- Invoke code action with the range
|
||||
vim.lsp.buf.code_action({
|
||||
range = range,
|
||||
})
|
||||
else
|
||||
-- Fallback if the range is invalid
|
||||
vim.notify(
|
||||
"Invalid selection range for code action",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
end
|
||||
else
|
||||
-- Fallback if positions are nil
|
||||
vim.notify("Could not capture selection range", vim.log.levels.ERROR)
|
||||
end
|
||||
else
|
||||
-- If not in Visual mode, just run code action normally
|
||||
vim.lsp.buf.code_action()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user