Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filename_first does not work if config key is present #3162

Closed
rtalexk opened this issue Jun 10, 2024 · 2 comments
Closed

filename_first does not work if config key is present #3162

rtalexk opened this issue Jun 10, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@rtalexk
Copy link

rtalexk commented Jun 10, 2024

Description

Long story

A few weeks ago I came across the filename_first setting, I thought it was great. I added it to my Telescope config and it didn't work, I tried adding it in the opts and config keys, no luck.

I just leave it there because it wasn't a blocker to do my job.

Today that I have some spare time I gave it a deeper look and I committed to figure it out why it wasn't working.

I decided to start with a minimal config and little by little replicate my own config.

I started with this minimal opts:

opts = {
  defaults = {
    layout_strategy = 'vertical',
    path_display = { filename_first = { reverse_directories = false } },
  },
},

And as soon as I added the config key I noticed that

When you add the path_display = { filename_first = ... } setting and the config function (for lazy.nvim), it doesn't work.

Not sure if this is really the expected behavior but I think it shouldn't.

Neovim version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1713517273

Operating system and version

macOS 14.5

Telescope version / branch / rev

0.1.x

checkhealth telescope

telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 14.1.0
- OK fd: found fd 9.0.0

===== Installed extensions ===== ~

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Telescope Extension: `ui-select` ~
- No healthcheck provided

Steps to reproduce

  1. nvim -nu minimal.lua
  2. :Telescope find_files
  3. Comment out the config = function() end, line
  4. Restart nvim :qa then nvim -nu minimal.lua
  5. :Telescope find_files

Expected behavior

It displays the filename first followed by the filepath whether the config key is present or not.

Actual behavior

When the config key is present, the filename_first setting doesn't work.

telescope_bug

Minimal config

local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs { 'config', 'data', 'state', 'cache' } do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system {
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    'nvim-telescope/telescope.nvim',
    dependencies = { 'nvim-lua/plenary.nvim' },
    opts = {
      defaults = {
        layout_strategy = 'vertical',
        path_display = { 'filename_first' },
        -- path_display = { filename_first = { reverse_directories = false } },
      },
    },
    config = function() end, -- Try commenting this out
  },
}
require('lazy').setup(plugins, {
  root = root .. '/plugins',
})
@rtalexk rtalexk added the bug Something isn't working label Jun 10, 2024
@jamestrew
Copy link
Contributor

jamestrew commented Jun 10, 2024

This is a lazy config issue.
If you're using the opt field and additionally want to use the config field, you have to handle the opts table yourself and properly call telescope's setup function with those options.

{
  opts = { --[[ your opts]] },
  config = function(_, opts)
    -- this `opts` is the `opts` table from above
    require('telescope').setup(opts)
  end
}

@rtalexk
Copy link
Author

rtalexk commented Jun 10, 2024

For the record. That wasn't the real issue.

Turned out I had a key binding for a Telescope picker in my LSP config:

-- plugins/lsp.lua

  -- ...
  config = function()
    -- ...
    vim.keymap.set(
      'n',
      'gd',
      require('telescope.builtin').lsp_definitions,
      { desc = 'Goto Definition' }
    )
  end,
  -- ...

^ This single piece of code was somehow messing up with the configuration, not sure if there was some sort of race condition, but just by moving it to the Telescope config fixed the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants