nvim-telescope / telescope-frecency.nvim

A telescope.nvim extension that offers intelligent prioritization when selecting files from your editing history.
MIT License
688 stars 35 forks source link

Neovim config misconfigured after installing this plugin? #178

Closed Myzel394 closed 3 months ago

Myzel394 commented 4 months ago

I'm facing a very strange bug where my neovim config seems to be misconfigured after loading this extension. Some opts such as vim.o.number are changed (unset for me) and LSP suddenly became very wanky.

I'm loading frecency like any other plugin:

local builtin = require("telescope.builtin")
local telescope_actions = require("telescope.actions")

local function send_to_quickfix(promtbufnr)
    telescope_actions.smart_send_to_qflist(promtbufnr)
    vim.cmd([[botright copen]])
end

require("telescope").setup({
    extensions = {
        undo = {
            use_delta = true,
            side_by_side = false,
            diff_context_lines = 10,
        },
        emoji = {
            action = function(emoji)
                -- argument emoji is a table.
                -- {name="", value="", cagegory="", description=""}

                -- insert emoji when picked
                vim.api.nvim_put({ emoji.value }, 'c', false, true)
            end,
        },
        frecency = {
            ignore_patterns = { "*.git/*", "*/tmp/*", "*/node_modules/*", "*/.venv/*" },
        }
    },
    defaults = {
        layout_strategy = "vertical",
        layout_config = {
            mirror = true,
            preview_height = 0.65,
            prompt_position = "top",
        },
        mappings = {
            ["n"] = {
                ["<C-q>"] = send_to_quickfix,
            },
            ["i"] = {
                ["<C-q>"] = send_to_quickfix,
            },
        },
        vimgrep_arguments = {
            "rg",
            "--color=never",
            "--no-heading",
            "--with-filename",
            "--line-number",
            "--column",
            "--smart-case",
            -- Own additions
            "--trim",
        },
    },
})
require("telescope").load_extension("frecency")
require("telescope").load_extension("yank_history")
require("telescope").load_extension("undo")
require("telescope").load_extension("last_positions")
require("telescope").load_extension("emoji")

vim.keymap.set("n", "<leader>f", "<cmd>Telescope frecency<cr>", { desc = "Find frecent files" })
vim.keymap.set("n", "<leader>i", builtin.find_files, { desc = "Find files" })
vim.keymap.set("n", "<leader>s", builtin.live_grep, { desc = "Find files with live grep" })
vim.keymap.set("n", "<leader>w", builtin.resume, { desc = "Resume your last search" })
vim.keymap.set("n", "<leader>b", builtin.buffers, { desc = "Open buffers" })
vim.keymap.set("n", "<leader>ss", builtin.grep_string, { desc = "Find files with live grep" })

vim.keymap.set("n", "<leader>cb", builtin.buffers, { desc = "Show buffers" })
vim.keymap.set("n", "<leader>ct", builtin.treesitter, { desc = "Show treesitter" })
vim.keymap.set("n", "<leader>cu", "<cmd>Telescope undo<cr>", { desc = "Show undo history" })
vim.keymap.set("n", "<leader>cl", "<cmd>Telescope last_positions<cr>", { desc = "Show last positions" })
vim.keymap.set("n", "<leader>cs", "<cmd>Telescope git_status<cr>", { desc = "Show git status" })
vim.keymap.set("n", "<leader>cb", "<cmd>Telescope git_branches<cr>", { desc = "Show git branches" })
vim.keymap.set("n", "<leader>cc", "<cmd>Telescope git_commits<cr>", { desc = "Show git commits" })
vim.keymap.set("n", "<leader>cy", "<cmd>Telescope yank_history<cr>", { desc = "Show yank history" })
vim.keymap.set("n", "<leader>ce", "<cmd>Telescope emoji<cr>", { desc = "Show emoji selection" })

When I remove the require("telescope").load_extension("frecency"), everything is fine again. Strangely, only vim.o.number and LSP seem to be wanky when loading frecency (or maybe I just haven't noticed anything else).

delphinus commented 4 months ago

Can you share the whole config for Neovim? At least, this plugin does not change any option including 'number' and LSP features.

Myzel394 commented 4 months ago

@delphinus you can find my dotfiles for neovim here https://github.com/Myzel394/dotfiles/tree/main/nvim, telescope is located here https://github.com/Myzel394/dotfiles/blob/main/nvim/after/plugin/telescope.lua.

Strangely, this really only occurs when the frecency plugin is enabled. I don't know much about neovim, but could this be caused by the custom database frecency uses? Maybe it overwrites old config stuff? I tried setting a custom db_root but was unable to do so successfully.

Myzel394 commented 4 months ago

Can confirm this also breaks on NixOS

delphinus commented 4 months ago

Your config is too complex to find out the problem. At first, you should create and try a minimal configs that contains telescope, plenary, telescope-frecency only and confirm whether it work or not.

minimal init.lua to work with frecency ```lua local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system { "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", -- latest stable release lazypath, } end vim.opt.rtp:prepend(lazypath) require("lazy").setup { { "nvim-telescope/telescope.nvim", dependencies = { { "nvim-lua/plenary.nvim" }, { "nvim-telescope/telescope-frecency.nvim"}, }, cmd = { "Telescope" }, config = true, }, } ```
  1. Save ↑this config into ~/.config/nvim-frecency/init.lua.
  2. Run env NVIM_APPNAME=nvim-frecency nvim in your shell.
  3. Run :Telescope frecency workspace=CWD to confirm telescope-frecency works.

$NVIM_APPNAME variable is used not to pollute the env you're usually using. Neovim will use a different folders to store settings (See :h NVIM_APPNAME).

If frecency works validly (probably does), then you should add your own configs gradually until strange behavior you've reported appears. If occurs, report here again.

For the present, we can regard your config, other plugins, stored configs (shada, for example) and the combination with them and frecency as the cause of your problems.

delphinus commented 4 months ago

Ah, one point. What version of Neovim are you using? You should use the latest release version (v0.9.5) or HEAD to work frecency properly.

delphinus commented 3 months ago

Please write further information for more investigation and open again.

Myzel394 commented 3 months ago

Ah sorry I thought I already wrote you back. I'm using neovim 0.9.5:

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"

Run :checkhealth for more info

If frecency works validly (probably does), then you should add your own configs gradually until strange behavior you've reported appears. If occurs, report here again.

I'll try this