natecraddock / workspaces.nvim

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

feat(api): Add workspaces.path() #23

Closed bvtthead closed 1 year ago

bvtthead commented 1 year ago

Goes from:

function M.get_workspace_path()
    local workspaces = require 'workspaces'
    local saved_workspaces = workspaces.get()

    local current_workspace = workspaces.name()
    if current_workspace == nil then
        return
    end

    for _, workspace in ipairs(saved_workspaces) do
        if current_workspace == workspace.name then
            local path = workspace.path
            if path:sub(-1, -1) == '/' then
                path = path:sub(1, -2)
            end
            return path
        end
    end
end

to:

function M.get_workspace_path()
    local workspaces = require 'workspaces'

    local current_workspace_path = workspaces.path()
    if current_workspace_path == nil then
        return
    end

    return vim.fs.normalize(current_workspace_path)
end

I use this to force a root_dir for nvim-lspconfig, useful when go-to-definition brings you to a header file outside your project's root.

natecraddock commented 1 year ago

Thanks, I think this is a good improvement!