nvim-telescope / telescope-project.nvim

MIT License
596 stars 53 forks source link

Order projects by last access time #21

Closed davidscotson closed 3 years ago

davidscotson commented 3 years ago

It would be nice if the projects were ordered by last access time. Then the initial order would act like the MRU lists in the startify plugin. I think that plugin uses the info from the oldfiles variable (which Telescope also provides a builtin picker for) and I assume it would be possible to use that per file information to sort the project directory list.

claidler commented 3 years ago

@davidscotson good idea. I'll have a look into it. @Conni2461 my initial idea would be to log a timestamp in the projects file whenever a project is opened and then sort by those. Do you have any better ideas?

davidscotson commented 3 years ago

I was suprised how tricky accessing MRU info in neovim was, so filed an upstream feature request about it:

https://github.com/neovim/neovim/issues/14390

claidler commented 3 years ago

This is great. Thanks. I started some work locally to timestamp projects, so will continue continue down that route if nothing else.

Conni2461 commented 3 years ago

You can always check the last access time with vim.loop.fs_stat(full_path_of_project_dir). It will return you a pretty big table. (https://github.com/luvit/luv/blob/master/docs.md#uvfs_statpath-callback) I think interesting is atime. From man 2 stat:

struct timespec st_atim;  /* Time of last access */
struct timespec st_mtim;  /* Time of last modification */
struct timespec st_ctim;  /* Time of last status change */

From man system_data_types:

timespec
  Include: <time.h>.  Alternatively, <aio.h>, <mqueue.h>, <sched.h>, <signal.h>, <sys/select.h>, or <sys/stat.h>.

  struct timespec {
    time_t  tv_sec;  /* Seconds */
    long    tv_nsec; /* Nanoseconds */
  };

  Describes times in seconds and nanoseconds.

Not this is the last access to this directory from a user system wide, so probably not perfect but at least something because i don't see how neovim could make this better

claidler commented 3 years ago

This is great, thanks again @Conni2461!

claidler commented 3 years ago

@Conni2461 do you know what I'm doing wrong here? - https://github.com/nvim-telescope/telescope-project.nvim/pull/28/files I feel like it must be pretty close, but isn't updating for some reason

claidler commented 3 years ago

@davidscotson this hopefully is resolved now with the fix @Conni2461 suggested. I think it's the best we can do at this moment in time. It may need more work, so let me know if you're still having issues and I'll reopen.