From 9b42c5bcb145db0f7ea37144aad2a5eba7ebecc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joly?= Date: Sat, 4 Jun 2022 13:00:28 +0000 Subject: [PATCH 1/3] feat: Add global settings for the commands Fixes #38 --- lua/telescope/_extensions/repo.lua | 2 ++ lua/telescope/_extensions/repo/config.lua | 9 +++++++++ lua/telescope/_extensions/repo/main.lua | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 lua/telescope/_extensions/repo/config.lua diff --git a/lua/telescope/_extensions/repo.lua b/lua/telescope/_extensions/repo.lua index 60226c9..6f8179b 100644 --- a/lua/telescope/_extensions/repo.lua +++ b/lua/telescope/_extensions/repo.lua @@ -1,10 +1,12 @@ local main = require("telescope._extensions.repo.main") +local r_config = require("telescope._extensions.repo.config") local health = require("telescope._extensions.repo.health") local fallback_error = { "Falling back to `:Telescope repo list`, but this behavior may change in the future" } return require("telescope").register_extension({ health = health.check, + setup = r_config.setup, exports = { list = main.list, cached_list = main.cached_list, diff --git a/lua/telescope/_extensions/repo/config.lua b/lua/telescope/_extensions/repo/config.lua new file mode 100644 index 0000000..edf1878 --- /dev/null +++ b/lua/telescope/_extensions/repo/config.lua @@ -0,0 +1,9 @@ +local M = {} + +M.values = {} + +M.setup = function (opts) + M.values = opts +end + +return M diff --git a/lua/telescope/_extensions/repo/main.lua b/lua/telescope/_extensions/repo/main.lua index e8321dc..46743b0 100644 --- a/lua/telescope/_extensions/repo/main.lua +++ b/lua/telescope/_extensions/repo/main.lua @@ -17,6 +17,7 @@ local Path = require("plenary.path") local utils = require("telescope._extensions.repo.utils") local list = require("telescope._extensions.repo.list") local cached_list = require("telescope._extensions.repo.cached_list") +local r_config = require("telescope._extensions.repo.config") local M = {} @@ -187,7 +188,7 @@ end -- List of repos built using locate (or variants) M.cached_list = function(opts) - opts = opts or {} + opts = vim.tbl_deep_extend("force", r_config.values.cached_list or {}, opts or {}) opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_locate_wrapper, opts) local locate_command = cached_list.prepare_command(opts) @@ -196,7 +197,7 @@ end -- Always up to date list of repos built using fd M.list = function(opts) - opts = opts or {} + opts = vim.tbl_deep_extend("force", r_config.values.list or {}, opts or {}) opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_fd, opts) local fd_command = list.prepare_command(opts) From dac32ad6b01d8c69710ff1a1d077c9441cbee1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joly?= Date: Sat, 4 Jun 2022 13:33:01 +0000 Subject: [PATCH 2/3] doc: document the new global configuration --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c011c03..094a37a 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,50 @@ use { ## Usage -### list +### Global Configuration + +You can change the default argument given to subcommands (like [`list`](#list) or [`cached_list`](#cached_list)) using the telescope `setup` function with a table like this: + +```lua +{ + extensions = { + repo = { + = { + = { + "new", + "default", + "value", + }, + }, + }, + }, +} +``` + +for instance, you could do: + +```lua +require("telescope").setup { + extensions = { + repo = { + list = { + fd_opts = { + "--no-ignore-vcs", + }, + search_dirs = { + "~/my_projects", + }, + }, + }, + }, +} + +require("telescope").load_extension "repo" +``` + +**Note**: make sure to have `require("telescope").load_extension "repo"` *after* the call to `require("telescope").setup {…}`, otherwise the global configuration won’t be taken into account. + +### `list` `:Telescope repo list` or `lua require'telescope'.extensions.repo.list{}` @@ -198,7 +241,7 @@ Here is how you can use this plugin with various SCM: Is your favorite SCM missing? It should be straightforward to support it by changing the pattern parameter. If you want it to be considered for addition here, open a PR! -### cached_list +### `cached_list` `:Telescope repo cached_list` @@ -236,7 +279,6 @@ exports the `LOCATE_PATH` variable. Provide instructions on how to setup periodic update of the locate database. - #### Troubleshooting You should try to run: From daaac40b3b97652de2f8fdec270d709e61f82817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joly?= Date: Sat, 4 Jun 2022 13:35:45 +0000 Subject: [PATCH 3/3] style: run stylua --- .github/workflows/lint.yml | 1 + lua/telescope/_extensions/repo/config.lua | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 32572cd..b3fac3a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,3 +28,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} # CLI arguments args: --check . + version: 0.13.1 diff --git a/lua/telescope/_extensions/repo/config.lua b/lua/telescope/_extensions/repo/config.lua index edf1878..eaf84b3 100644 --- a/lua/telescope/_extensions/repo/config.lua +++ b/lua/telescope/_extensions/repo/config.lua @@ -2,7 +2,7 @@ local M = {} M.values = {} -M.setup = function (opts) +M.setup = function(opts) M.values = opts end