From 908379c3ceb679d371cba0cc8b1b10450f67132f Mon Sep 17 00:00:00 2001 From: Philippe Richard Date: Tue, 4 Jun 2024 18:22:40 -0400 Subject: [PATCH] feat: add telescope `grep_string` support --- README.md | 12 +++++++----- doc/vwd.txt | 12 +++++++----- lua/telescope/_extensions/vwd.lua | 7 +++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index eb8b05a..b2a207a 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,9 @@ function still has to be called to configure the commands: ### Telescope -vwd.nvim extends Telescope's `find_files` and `live_grep` functionality by -setting the CWD to the VWD. Here is a sample Telescope configuration: +vwd.nvim extends Telescope's `find_files`, `live_grep` and `grep_string` +functionalities by setting the CWD to the VWD. Here is a sample Telescope +configuration: ```lua local telescope = require('telescope') @@ -45,10 +46,11 @@ setting the CWD to the VWD. Here is a sample Telescope configuration: -- Register the vwd extension. telescope.load_extension('vwd') - -- Configures find_files and live_grep to use VWD. You can still provide + -- Configures find_files, live_grep and grep_string to use VWD. You can still provide -- regular Telescope arguments to the finders. - vim.api.nvim_set_keymap('n', 'ff', 'lua require"telescope".extensions.vwd.find_files{}', opts) - vim.api.nvim_set_keymap('n', 'fg', 'lua require"telescope".extensions.vwd.live_grep{}', opts) + vim.api.nvim_set_keymap('n', 'ff', 'lua require"telescope".extensions.vwd.find_files({})', opts) + vim.api.nvim_set_keymap('n', 'fg', 'lua require"telescope".extensions.vwd.live_grep({})', opts) + vim.api.nvim_set_keymap('n', 'fs', 'lua require"telescope".extensions.vwd.grep_string({})', opts) ``` ## Usage diff --git a/doc/vwd.txt b/doc/vwd.txt index 4433e4e..05b0ba3 100644 --- a/doc/vwd.txt +++ b/doc/vwd.txt @@ -31,18 +31,20 @@ function still has to be called to configure the commands: < *vwd-configure-telescope* -This plugin extends Telescope's `find_files` and `live_grep` functionality by -setting the CWD to the VWD. Here is a sample Telescope configuration: +This plugin extends Telescope's `find_files`, `live_grep` and `grep_string` +functionalities by setting the CWD to the VWD. Here is a sample Telescope +configuration: >lua local telescope = require('telescope') -- Register the vwd extension. telescope.load_extension('vwd') - -- Configures find_files and live_grep to use VWD. You can still provide + -- Configures find_files, live_grep and grep_string to use VWD. You can still provide -- regular Telescope arguments to the finders. - vim.api.nvim_set_keymap('n', 'ff', 'lua require"telescope".extensions.vwd.find_files{}', opts) - vim.api.nvim_set_keymap('n', 'fg', 'lua require"telescope".extensions.vwd.live_grep{}', opts) + vim.api.nvim_set_keymap('n', 'ff', 'lua require"telescope".extensions.vwd.find_files({})', opts) + vim.api.nvim_set_keymap('n', 'fg', 'lua require"telescope".extensions.vwd.live_grep({})', opts) + vim.api.nvim_set_keymap('n', 'fs', 'lua require"telescope".extensions.vwd.grep_string({})', opts) < ============================================================================== COMMANDS diff --git a/lua/telescope/_extensions/vwd.lua b/lua/telescope/_extensions/vwd.lua index 244de55..d6aa2ed 100644 --- a/lua/telescope/_extensions/vwd.lua +++ b/lua/telescope/_extensions/vwd.lua @@ -13,6 +13,12 @@ local live_grep = function(opts) builtin.live_grep(opts) end +local grep_string = function(opts) + opts = opts or {} + opts.cwd = vwd.get_vwd() + builtin.grep_string(opts) +end + local file_browser = function(opts) opts = opts or {} opts.cwd = vwd.get_vwd() @@ -23,6 +29,7 @@ return require("telescope").register_extension({ exports = { find_files = find_files, live_grep = live_grep, + grep_string = grep_string, file_browser = file_browser, actions = require("telescope._extensions.vwd.actions"), },