refactor: restructured utils module for better code organization
This commit is contained in:
+18
-16
@@ -2,7 +2,8 @@
|
|||||||
-- │ Lualine │
|
-- │ Lualine │
|
||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
local utils = require("utils.rootiest")
|
local utils = require("utils")
|
||||||
|
local rootils = utils.rootiest
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"nvim-lualine/lualine.nvim",
|
"nvim-lualine/lualine.nvim",
|
||||||
@@ -100,22 +101,21 @@ return {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
function()
|
function()
|
||||||
return require("utils.wakatime_stats").get_icon_with_text()
|
return utils.wakatime_stats.get_icon_with_text()
|
||||||
end,
|
end,
|
||||||
color = function()
|
color = function()
|
||||||
local wakatime_stats = require("utils.wakatime_stats")
|
return utils.wakatime_stats.get_color()
|
||||||
return wakatime_stats.get_color()
|
|
||||||
end,
|
end,
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(100)
|
return rootils.is_window_wide_enough(100)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
function()
|
function()
|
||||||
return require("utils.music_stats").get_icon_with_text()
|
return utils.music_stats.get_icon_with_text()
|
||||||
end,
|
end,
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(100)
|
return rootils.is_window_wide_enough(100)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -126,7 +126,7 @@ return {
|
|||||||
end,
|
end,
|
||||||
icon = " ",
|
icon = " ",
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(80)
|
return rootils.is_window_wide_enough(80)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -134,26 +134,26 @@ return {
|
|||||||
separator = " ",
|
separator = " ",
|
||||||
padding = { left = 1, right = 0 },
|
padding = { left = 1, right = 0 },
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(60)
|
return rootils.is_window_wide_enough(60)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"location",
|
"location",
|
||||||
padding = { left = 0, right = 1 },
|
padding = { left = 0, right = 1 },
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(40)
|
return rootils.is_window_wide_enough(40)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"selection_count",
|
"selection_count",
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(120)
|
return rootils.is_window_wide_enough(120)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"filesize",
|
"filesize",
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(100)
|
return rootils.is_window_wide_enough(100)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -161,8 +161,9 @@ return {
|
|||||||
return require("arrow.statusline").text_for_statusline_with_icons()
|
return require("arrow.statusline").text_for_statusline_with_icons()
|
||||||
end,
|
end,
|
||||||
cond = function()
|
cond = function()
|
||||||
return utils.is_window_wide_enough(100)
|
return rootils.is_window_wide_enough(100)
|
||||||
end,
|
end,
|
||||||
|
separator = { left = "", right = "" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lualine_z = {
|
lualine_z = {
|
||||||
@@ -178,9 +179,10 @@ return {
|
|||||||
icon = " ",
|
icon = " ",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
function()
|
"datetime",
|
||||||
return " " .. os.date("%R")
|
-- options: default, us, uk, iso, or your own format string ("%H:%M", etc..)
|
||||||
end,
|
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")
|
return os.date("%Y-%m-%d")
|
||||||
end
|
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
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user