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

limiting the frecency to only files within the working dir, e.g. within sessions? #182

Closed emilBeBri closed 3 months ago

emilBeBri commented 3 months ago

Hi, this plugin looks great, but is there any way to - or any plans for - a way to automatically limit the scope so that it only uses files within the session, e.g. the working directory? I use the plugin auto-session, and almost always, this means that I will have several nvim sessions open in different directories, and the files that are relevant to one session is almost always different than the ones from another session. So if there was some way that the frecency database(s) were attached to the session file, or just the working dir?

delphinus commented 3 months ago

The most simple way to do so is using workspace feature. You can use pre-defined workspace: CWD. :Telescope frecency workspace=CWD shows files under current working directory only.

Or you can set your own workspaces.

telescope.setup {
  extensions = {
    frecency = {
      workspaces = {
        PJT_A = "/path/to/project_a",
        PJT_B = "/path/to/project_b",
        PJT_C = "/path/to/project_c",
        ……
      },
    },
  },
}

When you run :Telescope frecency workspace=PJT_A, it shows files under /path/to/project_a only. When :Telescope frecency simply, it shows all files under project_a, project_b, project_c, and others. CWD workspace is also working with this config.

In addition, there is default_workspace option to use for that. This makes always it limit candidates into ones under current working directory, as long as you don't specify workspace parameter in calling frecency.

telescope.setup {
  workspaces = {
    ……
  },
  default_workspace = "CWD",  -- always show candidates under cwd.
}
emilBeBri commented 3 months ago

Thank you, this works! This works well, except that symlinks are not followed, and there seems to be no option to set for that.

For me, the best way of utilizing frecency would be if, instead of looking at files, it could have an option to look at the open buffers only.

this would provide the greatest flexibility in the work flow I use. I find Telescope find_files and Telescope find_files search_dirs=$HOME to be completely satisfactory for finding stuff that needs to be opened in a buffer - the problem is with a lot of buffers open, it is often the case that I switch between the same 5-10 buffers with Telescope current_buffer_fuzzy_find, and then once in a while go into 20-30 other files. Right now I use Telescope current_buffer_fuzzy_find for this, with sort_mru = true, so that the most recently used buffers are at the top.

however, a frecency-based listing of the buffers would be alot better. I thought about using harpoon for this, but I actually don't need manual control of the files, frecency would be alot more smooth.

I don' think I have the developer skill set to implement that my self though, just yet. Perhaps GPT could help me :)