ahmedkhalf / project.nvim

The superior project management solution for neovim.
Apache License 2.0
1.29k stars 119 forks source link

Allow customization of getting the current directory for find_pattern_root #144

Closed synic closed 4 months ago

synic commented 5 months ago

Allow customization of the method that find_pattern_root obtains the current working directory.

Right now it uses vim.fn.expand("%:p:h", true), but this does not work for all buffer types (for instance, it doesn't work for oil.nvim, because vim.fn.expand returns a URI and not the local file path).

An example of usage for oil.nvim (with lazy.nvim):

  {
    "ahmedkhalf/project.nvim",
    config = function()
      require("project_nvim").setup({
        manual_mode = false,
        silent_chdir = true,
        detection_methods = { "pattern", "lsp" },
        pattern_get_current_dir_fn = function()
          local status, oil = pcall(require, "oil")

          if status then
            local dir = oil.get_current_dir()

            if dir ~= nil then
              return dir
            end
          end
          return vim.fn.expand("%:p:h", true)
        end,
        show_hidden = false,
        datapath = vim.fn.stdpath("data"),
      })

      utils.on_load("telescope.nvim", function()
        require("telescope").load_extension("projects")
      end)
    end,
  },

The default setting remains as vim.vn.expand("%:p:h"), so functionality will be the same for anyone that doesn't configure a pattern_get_current_dir_fn.