natecraddock / workspaces.nvim

a simple plugin to manage workspace directories in neovim
MIT License
309 stars 15 forks source link

Adding an MRU sort #8

Closed ryansch closed 2 years ago

ryansch commented 2 years ago

I'm working on a plugin that wraps your workspaces.nvim and sessions.nvim: https://github.com/ryansch/habitats.nvim

I'd like to add the ability to sort the list by most recently used and I think I have three options:

  1. Add an ability to track a last opened time to workspaces.nvim
  2. Add an ability to attach arbitrary user data to workspaces in workspaces.nvim
  3. Add my own data structure in habitats.nvim to track the data I'm interested in and link it to a workspace

Would you be interested in either of options 1 or 2?

natecraddock commented 2 years ago

Hi!

I think option 1 is the best and most straightforward option. I can work on it this weekend, unless you were wanting to add the feature.

ryansch commented 2 years ago

@natecraddock Great! I'll defer to you for this weekend, otherwise I can take it on soonish.

natecraddock commented 2 years ago

I created a branch https://github.com/natecraddock/workspaces.nvim/tree/last-opened where you can test this.

I chose to use ISO 8601 for the timestamps. Access the last opened date with the last_opened field of the workspace table. If a workspace has not been opened since this update, the last_opened field will be nil. Let me know if this works, but no rush!

If everything works out, I will document and merge the feature soon.

sibouras commented 2 years ago

how can i use this pls?

natecraddock commented 2 years ago

@sibouras currently this is in a feature branch last-opened. As @ryansch seems busy (that's totally okay! no rush), I think I will just merge this in with a new config option. I'll let you know when I do that, and how it works.

sibouras commented 2 years ago

thanks 🤗

ryansch commented 2 years ago

I ran into issues when integrating with telescope.nvim as it's a bit of a beast. This feature seems to work as discussed!

natecraddock commented 2 years ago

@sibouras I pushed a new config option mru_sort. It requires that the sort option is also true, and when mru_sort is true, then the list of workspaces will be presented sorted.

sibouras commented 2 years ago

when i :Telescope workspaces i get this error

Error executing Lua callback: ...ack\packer\start\workspaces.nvim/lua/workspaces/init.lua:56: invalid order function for sorting
stack traceback:
    [C]: in function 'sort'
    ...ack\packer\start\workspaces.nvim/lua/workspaces/init.lua:56: in function 'get'
    ...workspaces.nvim/lua/telescope/_extensions/workspaces.lua:15: in function 'workspaces_picker'
    ...workspaces.nvim/lua/telescope/_extensions/workspaces.lua:87: in function <...workspaces.nvim/lua/telescope/_extensions/workspaces.lua:86>
    ...ck\packer\start\telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
    ...ck\packer\start\telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
    ...te\pack\packer\start\telescope.nvim\plugin\telescope.lua:109: in function <...te\pack\packer\start\telescope.nvim\plugin\telescope.lua:108>

also i get errors for :WorkspacesAdd and other workspace commands even with empty setup function

E5108: Error executing lua ...ack\packer\start\workspaces.nvim/lua/workspaces/init.lua:56: invalid order function for sorting
stack traceback:
    [C]: in function 'sort'
    ...ack\packer\start\workspaces.nvim/lua/workspaces/init.lua:56: in function 'load_workspaces'
    ...ack\packer\start\workspaces.nvim/lua/workspaces/init.lua:241: in function 'list'
    [string ":lua"]:1: in main chunk
natecraddock commented 2 years ago

@sibouras I was unable to replicate (I know the cause though), and I believe I have fixed the error. Let me know if it works now!

sibouras commented 2 years ago

yess it works! thank you so much!!