Skip to content

Add support for lsp workspace variable #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eyalk11 opened this issue Jan 6, 2024 · 6 comments
Closed

Add support for lsp workspace variable #29

eyalk11 opened this issue Jan 6, 2024 · 6 comments

Comments

@eyalk11
Copy link

eyalk11 commented Jan 6, 2024

(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
Copy link
Author

eyalk11 commented Jan 6, 2024

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_symbols is 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
Copy link
Owner

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
Copy link
Author

eyalk11 commented Jan 8, 2024

What does it mean add project directories to nvim ?

Perhaps it was more wishful thinking than bad documentation.

@natecraddock
Copy link
Owner

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
Copy link
Author

eyalk11 commented Jan 12, 2024

I understand this usage. But what does WorkspacesSyncDirs does?

@natecraddock
Copy link
Owner

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: #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants