natecraddock / workspaces.nvim

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

Pass the path to the 'open' hook #15

Closed DeeGeeMan closed 1 year ago

DeeGeeMan commented 1 year ago

I need the both name and path when configing the open hook.

natecraddock commented 1 year ago

Hey! The name, path, and state (in the case of renaming) are passed into all hook functions. See https://github.com/natecraddock/workspaces.nvim/blob/master/lua/workspaces/init.lua#L106

You should be able to access it as the second parameter to your hook function. If that doesn't work, please share the hook you are trying to make so I can help debug.

DeeGeeMan commented 1 year ago

I am getting a nil value when referencing the path parameter:

require("workspaces").setup({
    global_cd = true,
    hooks = {
      open = function(hooks, name, path, state)
        print("path: ", path)
...

Code:

image
natecraddock commented 1 year ago

I just tried this again. I used the telescope picker, the :WorkspacesOpen <name> and the :WorkspacesOpen (opens the vim select UI) with the following config

open = {
  function(name, path)
    print(name, path)
  end
}

And in all cases the workspace name and path were printed. I'm struggling to think of any other situation in which the workspace would be opened and the path not found. Maybe there was an error when your workspace was created and it is going unnoticed? Could you give me any more context on an example name and path that this is failing for you?

natecraddock commented 1 year ago

I'm going to close this because I can't replicate the issue. Please comment if you still need help!