MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
832 stars 25 forks source link

grug-far Not Automatically Filling Project Root Path #169

Closed arthur19q3 closed 3 months ago

arthur19q3 commented 3 months ago

Bug Report

Description

When invoking the grug-far plugin with the <leader>sr keybinding, the path parameter is not being automatically filled with the project root. Despite passing the correct path to the grug_far function, the plugin does not seem to recognize or utilize the provided path.

Environment

Steps to Reproduce

  1. Install and configure grug-far plugin as described in the README.

  2. Add the following keybinding to grug-far.lua:

    return {
     "MagicDuck/grug-far.nvim",
     opts = { headerMaxWidth = 80 },
     cmd = "GrugFar",
     config = function()
       require('grug-far').setup({
         -- Any global configuration options
       })
     end,
     keys = {
       {
         "<leader>sr",
         function()
           local grug = require("grug-far")
           local ext = vim.bo.buftype == "" and vim.fn.expand("%:e") or nil
           local project_root = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
    
           if project_root == "" then
             project_root = vim.fn.getcwd()
           end
    
           vim.notify("Final Project Root: " .. project_root, vim.log.levels.INFO)
    
           grug.grug_far({
             transient = true,
             prefills = {
               filesFilter = ext and "*." .. ext or nil,
               path = project_root,
             },
           })
    
           vim.notify("Calling grug_far with: " .. vim.inspect({
             transient = true,
             prefills = {
               filesFilter = ext and "*." .. ext or nil,
               path = project_root,
             },
           }), vim.log.levels.INFO)
         end,
         mode = { "n", "v" },
         desc = "Search and Replace",
       },
     },
    }
  3. Open Neovim in a project with a Git repository.

  4. Trigger the keybinding <leader>sr.

  5. Observe that the path parameter is not correctly set to the project root.

Expected Behavior

The grug-far plugin should automatically use the provided path parameter as the root for search and replace operations.

Actual Behavior

The path parameter does not seem to be utilized, resulting in the plugin not searching in the intended project root directory.

Debug Information

  1. The following debug messages confirm that the path parameter is correctly calculated and passed to the grug_far function:

    Final Project Root: /home/user/project
    Calling grug_far with: {
     transient = true,
     prefills = {
       filesFilter = "*.rs",
       path = "/home/user/project"
     }
    }
  2. The project root is correctly determined using git rev-parse --show-toplevel and falls back to vim.fn.getcwd() if necessary.

choovick commented 3 months ago

@arthur19q3 its paths not path

  prefills = {
    filesFilter = "*.rs",
    paths = "/home/user/project"
  }
MagicDuck commented 3 months ago

@choovick is correct! Always make sure to double-check the options here: https://github.com/MagicDuck/grug-far.nvim/blob/16091184639ca7f2c76734e3a8641d388aebc4e7/lua/grug-far/opts.lua#L155 Also recommend you install https://github.com/folke/lazydev.nvim, that way you get auto-complete:

image
arthur19q3 commented 3 months ago

okk, that was a typo. just have fixed it. thx.