natecraddock / workspaces.nvim

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

Add support for lsp workspace variable #29

Closed eyalk11 closed 2 months ago

eyalk11 commented 8 months ago

(In fact I thought this is the whole purpose of this plugin, to manage lsp workspace settings)

I failed to understand the purpose of listdir and syncdir. What is the point in assigning dirs to workspace?

Please improve the documentation. Thanks!

I would just write the purpose clearly:

Choosing workspace by default would just change the cwd, but you can add hooks. And additional functionality.

eyalk11 commented 8 months ago

OK, implemented it myself. Kind of cool.

Feel free to add to suggestions. A function to update lsp workspace folder on hook.

function _G.set_workspace_dir(dir)
    vim.lsp.buf.add_workspace_folder(dir)
    local folders = vim.lsp.buf.list_workspace_folders()
    for i = 1, #folders do
        if dir ~= folders[i] then
            vim.lsp.buf.remove_workspace_folder(folders[i])
        end
    end
end

require("workspaces").setup({
path = vim.fn.stdpath("data") .. "/workspaces",
 hooks = {
        open =  function()
 set_workspace_dir(require'workspaces'.path())
 print("workspace dir is " .. require'workspaces'.path())
end,
}})

Explanation: Telescope lsp_workspace_symbolsis tricky function as it requires all workspaces paths to be correct. And it adds them automatically. So I created a hook to update lsp workspace folder to single one (when opening workspace).

natecraddock commented 8 months ago

In fact I thought this is the whole purpose of this plugin, to manage lsp workspace settings

Hey! Thank you for the suggestion. Although this shares language with LSP (worksapce), this plugin does not interact with LSP workspaces. I also don't think it makes sense to add LSP workspace support.

This just adds some project directories (called workspaces) to nvim.

Please improve the documentation

Sorry you found it confusing! Feel free to open a PR if you have anything specific you would like me to improve. Or just point out specifically where you find it confusing.

eyalk11 commented 8 months ago

What does it mean add project directories to nvim ?

Perhaps it was more wishful thinking than bad documentation.

natecraddock commented 8 months ago

A project directory is a commonly used project folder. Some people (myself included) want to open nvim in any directory, and then have an option to open a project from within nvim.

For example. I open my terminal in my home directory and then open nvim. From there I can run :WorkspacesOpen <project> to open my project. Or :Telescope workspaces to use telescope to select from my projects.

The alternative is to cd to the project directory and open nvim.

eyalk11 commented 8 months ago

I understand this usage. But what does WorkspacesSyncDirs does?

natecraddock commented 8 months ago

The way that WorkspacesAddDir works, it adds a directory that contains subdirectories that are all individual projects. I explained this on another issue in more detail, so look here if you want more info on that: https://github.com/natecraddock/workspaces.nvim/issues/30

So WorkspacesSyncDirs is used to automatically add all of those subdirectories as a workspace. The implementation was done this way to keep things more performant. But it may also be confusing.