From 7a0a7273002c6ad0c02185b7d2d0f414dfdb06ad Mon Sep 17 00:00:00 2001 From: Calvin Bochulak Date: Sun, 17 Mar 2024 19:48:30 -0600 Subject: [PATCH] feat: configure default command (#127) * feat: make default tag select command configurable * docs: update settings section in readme to reflect new command option --- README.md | 6 +++++- lua/grapple.lua | 2 +- lua/grapple/settings.lua | 6 +++++- lua/grapple/tag.lua | 5 ++++- tests/grapple/settings_spec.lua | 18 +++++++++++++----- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bef4eb0..95110eb 100644 --- a/README.md +++ b/README.md @@ -243,10 +243,14 @@ require("grapple").setup({ style = "relative", ---A string of characters used for quick selecting in Grapple windows - ---An empty string or nil will disable quick select + ---An empty string or false will disable quick select ---@type string | nil quick_select = "123456789", + ---Default command to use when selecting a tag + ---@type fun(path: string) + command = vim.cmd.edit, + ---User-defined tags title function for Grapple windows ---By default, uses the resolved scope's ID ---@type fun(scope: grapple.resolved_scope): string? diff --git a/lua/grapple.lua b/lua/grapple.lua index 6398f8a..0a69fe6 100644 --- a/lua/grapple.lua +++ b/lua/grapple.lua @@ -22,7 +22,7 @@ end ---@field index? integer ---@field cursor? integer[] ---@field scope? string ----@field command? fun(path: string) undocumented +---@field command? fun(path: string) ---Extract a valid path from the provided path or buffer options. ---@param opts grapple.options diff --git a/lua/grapple/settings.lua b/lua/grapple/settings.lua index bfa6003..640e1d1 100644 --- a/lua/grapple/settings.lua +++ b/lua/grapple/settings.lua @@ -40,10 +40,14 @@ local DEFAULT_SETTINGS = { style = "relative", ---A string of characters used for quick selecting in Grapple windows - ---An empty string will disable quick select + ---An empty string or false will disable quick select ---@type string quick_select = "123456789", + ---Default command to use when selecting a tag + ---@type fun(path: string) + command = vim.cmd.edit, + ---@class grapple.scope_definition ---@field name string ---@field force? boolean diff --git a/lua/grapple/tag.lua b/lua/grapple/tag.lua index 51a2055..63daaa7 100644 --- a/lua/grapple/tag.lua +++ b/lua/grapple/tag.lua @@ -24,9 +24,12 @@ end ---@param command? fun(path: string) function Tag:select(command) + local App = require("grapple.app") + local app = App.get() + local short_path = Path.fs_short(self.path) - command = command or vim.cmd.edit + command = command or app.settings.command command(short_path) if self.cursor then diff --git a/tests/grapple/settings_spec.lua b/tests/grapple/settings_spec.lua index eed2706..ba6f1f3 100644 --- a/tests/grapple/settings_spec.lua +++ b/tests/grapple/settings_spec.lua @@ -11,22 +11,30 @@ describe("Settings", function() end) it("has the correct scope default", function() - local settings = Settings:new() - assert.same("git", settings.scope) + assert.same("git", Settings:new().scope) + end) + + it("has the correct command default", function() + assert.same(vim.cmd.edit, Settings:new().command) end) end) describe(".quick_select", function() it("has the correct quick_select default", function() - local settings = Settings:new() - assert.same({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, settings:quick_select()) + assert.same({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, Settings:new():quick_select()) end) - it("can be set to nothing", function() + it("can be set to an empty string to disable quick select", function() local settings = Settings:new() settings:update({ quick_select = "" }) assert.same({}, settings:quick_select()) end) + + it("can be set to false to disable quick select", function() + local settings = Settings:new() + settings:update({ quick_select = false }) + assert.same({}, settings:quick_select()) + end) end) describe(".scopes", function()