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

only_cwd on paths with partial matches #2843

Closed
serranomorante opened this issue Jan 3, 2024 · 1 comment · Fixed by #2845
Closed

only_cwd on paths with partial matches #2843

serranomorante opened this issue Jan 3, 2024 · 1 comment · Fixed by #2845
Labels
bug Something isn't working reproducible Bug that can be reproduced.

Comments

@serranomorante
Copy link

Description

        {only_cwd}              (boolean)   if true, only show buffers in the
                                            current working directory
                                            (default: false)

This doesn't work on directories with partial matches in their names: test1, test12

Neovim version

NVIM v0.10.0-dev-2000+g6fa0f303d
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info

Operating system and version

arch linux

Telescope version / branch / rev

main

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.0.3
- 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: `git_worktree` ~
- No healthcheck provided

Telescope Extension: `undo` ~
- No healthcheck provided

Steps to reproduce

Create the following tree structure on a new folder (any name will do) and cd into it.

.
├── repro.lua
├── test1
│   └── test1.md (content is not necessary)
└── test12
    └── test12.md (content is not necessary)

3 directories, 3 files

Paste the following snippet into repro.lua and open vim with this command nvim --clean +'so repro.lua'

-- DO NOT change the paths
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

--------------------------------------------------------------------------------

vim.g.mapleader = " "

--------------------------------------------------------------------------------

local plugins = {
  { "nvim-lua/plenary.nvim", lazy = true },
  {
    "nvim-telescope/telescope.nvim",
    keys = {
      {
        "<leader>fb",
        function() require("telescope.builtin").buffers() end,
        desc = "Buffers",
      },
    },
    opts = {
      pickers = {
        buffers = {
          only_cwd = true,
        },
      },
    },
  },
}

--------------------------------------------------------------------------------

local lazypath = root .. "/plugins/lazy.nvim"
---@diagnostic disable-next-line: undefined-field
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.runtimepath:prepend(lazypath)

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Steps

  1. Open 2 tabs
  2. Dedicate tab1 to test1 folder tcd test1 and open test1.md file
  3. Dedicate tab2 to test12 folder tcd test12 and open test12.md file
  4. Press the keymap to show the picker (buffers) <leader>fb

You will notice that test12 folder only has 1 buffer (as it should) but test1 folder is not respecting the only_cwd option because it shows 2 buffers.

Expected behavior

only_cwd should work

Actual behavior

only_cwd doesn't work

Minimal config

-- DO NOT change the paths
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

--------------------------------------------------------------------------------

vim.g.mapleader = " "

--------------------------------------------------------------------------------

local plugins = {
  { "nvim-lua/plenary.nvim", lazy = true },
  {
    "nvim-telescope/telescope.nvim",
    keys = {
      {
        "<leader>fb",
        function() require("telescope.builtin").buffers() end,
        desc = "Buffers",
      },
    },
    opts = {
      pickers = {
        buffers = {
          only_cwd = true,
        },
      },
    },
  },
}

--------------------------------------------------------------------------------

local lazypath = root .. "/plugins/lazy.nvim"
---@diagnostic disable-next-line: undefined-field
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.runtimepath:prepend(lazypath)

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
@serranomorante serranomorante added the bug Something isn't working label Jan 3, 2024
@jamestrew
Copy link
Contributor

Thanks for the detailed bug report. I can reproduce this. Let me take a look at what's happening.

@jamestrew jamestrew added the reproducible Bug that can be reproduced. label Jan 3, 2024
jamestrew added a commit that referenced this issue Jan 3, 2024
closes #2843

Previously, bad partial matches between cwd and target buffer path would
result in non-cwd buffers showing up in the picker despite using
`only_cwd=true`.

eg.
cwd = `/foo/bar`
target buffer = `foo/bar1/baz.txt`
The target buffer starts with the cwd path.

This is fixed by appending a path separator before comparing/matching:
eg.
cwd = `/foo/bar/`
target buffer = `foo/bar1/baz.txt`
jamestrew added a commit that referenced this issue Jan 4, 2024
closes #2843

Previously, bad partial matches between cwd and target buffer path would
result in non-cwd buffers showing up in the picker despite using
`only_cwd=true`.

eg.
cwd = `/foo/bar`
target buffer = `foo/bar1/baz.txt`
The target buffer starts with the cwd path.

This is fixed by appending a path separator before comparing/matching:
eg.
cwd = `/foo/bar/`
target buffer = `foo/bar1/baz.txt`
jamestrew added a commit that referenced this issue Jan 4, 2024
closes #2843

Previously, bad partial matches between cwd and target buffer path would
result in non-cwd buffers showing up in the picker despite using
`only_cwd=true`.

eg.
cwd = `/foo/bar`
target buffer = `foo/bar1/baz.txt`
The target buffer starts with the cwd path.

This is fixed by appending a path separator before comparing/matching:
eg.
cwd = `/foo/bar/`
target buffer = `foo/bar1/baz.txt`
jamestrew added a commit that referenced this issue Jan 4, 2024
#2845)

closes #2843

Previously, bad partial matches between cwd and target buffer path would
result in non-cwd buffers showing up in the picker despite using
`only_cwd=true`.

eg.
cwd = `/foo/bar`
target buffer = `foo/bar1/baz.txt`
The target buffer starts with the cwd path.

This is fixed by appending a path separator before comparing/matching:
eg.
cwd = `/foo/bar/`
target buffer = `foo/bar1/baz.txt`
Conni2461 pushed a commit that referenced this issue Mar 11, 2024
#2845)

closes #2843

Previously, bad partial matches between cwd and target buffer path would
result in non-cwd buffers showing up in the picker despite using
`only_cwd=true`.

eg.
cwd = `/foo/bar`
target buffer = `foo/bar1/baz.txt`
The target buffer starts with the cwd path.

This is fixed by appending a path separator before comparing/matching:
eg.
cwd = `/foo/bar/`
target buffer = `foo/bar1/baz.txt`

(cherry picked from commit c621f71)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible Bug that can be reproduced.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants