From 2b506374a8f9b316e620a21abce73ad3f7b0f383 Mon Sep 17 00:00:00 2001 From: Atif Date: Sun, 24 Aug 2025 12:57:23 +0600 Subject: [PATCH 1/2] feat(snacks): add `snacks` picker support --- lua/makeit/init.lua | 47 ++++++++++++++++++++++++++++++++----------- lua/makeit/snacks.lua | 29 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 lua/makeit/snacks.lua diff --git a/lua/makeit/init.lua b/lua/makeit/init.lua index a17cb73..decd264 100644 --- a/lua/makeit/init.lua +++ b/lua/makeit/init.lua @@ -5,31 +5,54 @@ local cmd = vim.api.nvim_create_user_command local M = {} -M.setup = function(ctx) +---@class MakeitConfig +---@field picker string "telescope" or "snacks" +local config = { + picker = "telescope", -- "telescope" or "snacks" +} + +---@param opts MakeitConfig +M.setup = function(opts) + if opts then config = vim.tbl_extend("force", config, opts) end + cmd("MakeitOpen", function() - require("makeit.telescope").show() + if opts.picker == "snacks" then + require("makeit.snacks").show() + else + require("makeit.telescope").show() + end end, { desc = "Open makeit" }) - cmd("MakeitToggleResults", function() - vim.cmd("OverseerToggle") - end, { desc = "Toggle makeit results" }) + cmd( + "MakeitToggleResults", + function() vim.cmd("OverseerToggle") end, + { desc = "Toggle makeit results" } + ) cmd("MakeitRedo", function() -- If the user didn't select an option yet, send a notification. if _G.makeit_redo == nil then - vim.notify("Open makeit and select an option before doing redo.", vim.log.levels.INFO, { - title = "Makeit.nvim" - }) + vim.notify( + "Open makeit and select an option before doing redo.", + vim.log.levels.INFO, + { + title = "Makeit.nvim", + } + ) return end -- Redo - require "makeit.backend".run_makefile(_G.makeit_redo) + require("makeit.backend").run_makefile(_G.makeit_redo) end, { desc = "Redo the last selected makeit option" }) cmd("MakeitStop", function() - vim.notify("SUCCESS - All tasks have been disposed.", vim.log.levels.INFO, { - title = "Compiler.nvim" - }) + vim.notify( + "SUCCESS - All tasks have been disposed.", + vim.log.levels.INFO, + { + title = "Compiler.nvim", + } + ) local overseer = require("overseer") local tasks = overseer.list_tasks({ unique = false }) for _, task in ipairs(tasks) do diff --git a/lua/makeit/snacks.lua b/lua/makeit/snacks.lua new file mode 100644 index 0000000..48abbcb --- /dev/null +++ b/lua/makeit/snacks.lua @@ -0,0 +1,29 @@ +local M = {} + +function M.show() + local utils = require("makeit.utils") + local options = + utils.get_makefile_options(utils.os_path(vim.fn.getcwd() .. "/Makefile")) + + local items = vim.tbl_map( + function(entry) + return { + txt = entry.text, + value = entry.value, + } + end, + options + ) + + require("snacks").picker.select(items, { + prompt = "Makeit", + format_item = function(item) return item.txt end, + }, function(choice) + if choice then + _G.makeit_redo = choice.value + require("makeit.backend").run_makefile(choice.value) + end + end) +end + +return M From e37b3b70e4b96a0197f1f7b70342abf7c557e572 Mon Sep 17 00:00:00 2001 From: Atif Date: Sun, 24 Aug 2025 12:58:23 +0600 Subject: [PATCH 2/2] fix(utils): update match pattern to ignore commented lines --- lua/makeit/utils.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lua/makeit/utils.lua b/lua/makeit/utils.lua index 9f2fed7..67b617b 100644 --- a/lua/makeit/utils.lua +++ b/lua/makeit/utils.lua @@ -2,7 +2,6 @@ local M = {} - --- Given a string, convert 'slash' to 'inverted slash' if on windows, and vice versa on UNIX. -- Then return the resulting string. ---@param path string @@ -10,8 +9,8 @@ local M = {} function M.os_path(path) if path == nil then return nil end -- Get the platform-specific path separator - local separator = package.config:sub(1,1) - return string.gsub(path, '[/\\]', separator) + local separator = package.config:sub(1, 1) + return string.gsub(path, "[/\\]", separator) end --- Given a path, open the file, extract all the Makefile keys, @@ -32,7 +31,7 @@ function M.get_makefile_options(path) -- Iterate through each line in the Makefile for line in file:lines() do -- Check for lines starting with a target rule (e.g., "target: dependencies") - local target = line:match "^(.-):" + local target = line:match("^([%.%w_-]+):") if target then in_target = true count = count + 1