echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
5.19k stars 187 forks source link

Default normalize prunes entries with labels #602

Closed towry closed 11 months ago

towry commented 11 months ago

Contributing guidelines

Module(s)

mini.visits

Description

https://github.com/echasnovski/mini.nvim/issues/591#issuecomment-1836353708

vim.g.mapleader = ' '

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)

local init_cwd = vim.uv.cwd()

-- install plugins
local plugins = {
  { 'nvim-lua/plenary.nvim' },
  { 'echasnovski/mini.pick' },
  { 'echasnovski/mini.extra' },
  {
    'echasnovski/mini.visits',
    keys = {
      {
        '<leader>pp',
        function()
          local extra = require('mini.extra')
          extra.pickers.visit_paths({ cwd = init_cwd, filter = 'project', recency_weight = 0 }, {
            source = {
              choose = function(item)
                vim.print(item)
              end
            }
          })
        end,
        desc = 'List projects in cwd',
      },
      {
        '<leader>pa',
        function()
          local visits = require('mini.visits')
          visits.add_label('project', vim.uv.cwd(), init_cwd)
          visits.write_index()
        end,
        desc = 'Add project',
      },
    },
    opts = function()
      return {
        store = {
          autowrite = true,
        },
        track = {
          event = 'BufEnter',
          delay = 1000,
        }
      }
    end,
    config = function(_, opts)
      require('mini.visits').setup(opts)
    end,

  }
  -- add any other pugins here
}

require('lazy').setup({
  spec = plugins,
  root = root .. '/plugins',
  defaults = {
    lazy = false,
  },
  state = root .. '/lazy/state.json',
  performance = {
    cache = {
      enabled = false,
    }
  }
})

-- add anything else here
vim.opt.termguicolors = true

Neovim version

nightly

Steps to reproduce

  1. cd /tmp
  2. create init.lua
  3. mkdir root && mkdir -p root/child
  4. cd root
  5. nvim -u ../init.lua
  6. pwd: /tmp/root
  7. run :lua vim.cmd.tcd('./child')
  8. pwd: /tmp/root/child
  9. press <space>pa add path label.
  10. press <space>pp to list paths. (OK).
  11. :qa quit.
  12. in root dir, start vim: nvim -u ../init.lua
  13. press <space>pp, nothing here (not ok).

Expected behavior

add_label with initial cwd and current cwd should be working.

Actual behavior

not persistent.

echasnovski commented 11 months ago

Thanks for such detailed steps!

I think I can reproduce, but will investigate deeper.

echasnovski commented 11 months ago

So the cause is completely in another direction and has nothing to do with monorepo or directories. The way path is added is without actually visiting it, which leads to have its count equal to 0. This gets pruned before actually writing index to the disk.

As this is indeed a workflow I'd like to support, default normalize now doesn't prune if entry has any label. It should work on latest main.

Thanks again for the repro and interesting case!