smart-open.nvim icon indicating copy to clipboard operation
smart-open.nvim copied to clipboard

Add ability to pass in picker options through telescope setup

Open dlvhdr opened this issue 2 years ago • 4 comments

I would like to customize smart-open like so:

telescope.setup({
  extensions = {
    smart_open = {
      preview = { hide_on_startup = true },
      layout_config = {
        width = 0.65,
      },
      mappings = {
        i = {
          ["<esc>"] = require("telescope.actions").close,
        },
      },
    },
  },

Many plugins allow passing in these standard telescope picker options

dlvhdr avatar Nov 16 '23 11:11 dlvhdr

This should work on the 0.2.x branch now.

danielfalk avatar Jun 12 '24 13:06 danielfalk

I can't seem to reproduce the config provided by the OP in the 0.2.x branch. The pass-through options appear to be ignored.

Below is the lazy.nvim configuration I used to configure telescope.nvim and smart-open.nvim:

Click to reveal full config
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
  -- spec = "ebk.plugins",
  {
    "nvim-telescope/telescope.nvim",
    event = "VimEnter",
    dependencies = {
      "nvim-lua/plenary.nvim",
      {
        "nvim-telescope/telescope-fzf-native.nvim",
        build = "make",
        cond = function()
          return vim.fn.executable("make") == 1
        end,
      },
      {
        "danielfalk/smart-open.nvim",
        branch = "0.2.x",
        dependencies = { "kkharji/sqlite.lua" },
        config = true,
      },
      { "nvim-telescope/telescope-ui-select.nvim" },
      { "nvim-tree/nvim-web-devicons" },
    },
    config = function()
      require("telescope").setup({
        defaults = {
          file_ignore_patterns = {
            ".git/",
            "node_modules/",
            "target/",
            "%.gif",
            "%.jpeg",
            "%.jpg",
            "%.png",
          },
        },
        extensions = {
          smart_open = {
            preview = { hide_on_startup = true },
            layout_config = {
              width = 0.65,
            },
            mappings = {
              i = {
                ["<esc>"] = require("telescope.actions").close,
              },
            },
          },
          ["ui-select"] = {
            require("telescope.themes").get_dropdown(),
          },
        },
      })

      pcall(require("telescope").load_extension, "fzf")
      pcall(require("telescope").load_extension, "smart_open")
      pcall(require("telescope").load_extension, "ui-select")

      local builtin = require("telescope.builtin")
      vim.keymap.set("n", "<leader>sh", builtin.help_tags, { desc = "[S]earch [h]elp" })
      vim.keymap.set("n", "<leader>sH", builtin.highlights, { desc = "[S]earch [H]ighlight Groups" })
      vim.keymap.set("n", "<leader>sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" })
      vim.keymap.set("n", "<leader>sf", builtin.find_files, { desc = "[S]earch [F]iles" })
      vim.keymap.set("n", "<leader>ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" })
      vim.keymap.set("n", "<leader>sw", builtin.grep_string, { desc = "[S]earch current [W]ord" })
      vim.keymap.set("n", "<leader>sg", builtin.live_grep, { desc = "[S]earch by [G]rep" })
      vim.keymap.set("n", "<leader>sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" })
      vim.keymap.set("n", "<leader>sr", builtin.resume, { desc = "[S]earch [R]esume" })
      vim.keymap.set("n", "<leader>s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
      vim.keymap.set("n", "<leader><leader>", builtin.buffers, { desc = "[ ] Find existing buffers" })
    end,
  },
})

In fact, it seems as if several smart-open.nvim options aren't being respected anymore with the above Neovim configuration applied (e.g. disable_devicons, show_scores, open_buffer_indicators) but others are (ignore_patterns). Would someone kindly provide a sanity-check?

ebkalderon avatar Jun 15 '24 02:06 ebkalderon

I'm able to pass in these options which works, so thanks!

dlvhdr avatar Jun 20 '24 21:06 dlvhdr

Hmm, it seems that extensions.smart_open.mappings = { ... } is being applied for me, using the full config above, but extensions.smart_open.preview.hide_on_startup = true and extensions.smart_open.layout_config.width = 0.65 appear to not be applied. Not sure why this is, exactly. :man_shrugging: Is anyone able to reproduce?

ebkalderon avatar Jun 21 '24 01:06 ebkalderon