Skip to content
Gnik edited this page Dec 8, 2022 · 2 revisions

projections.nvim

Make sure you read README.md first. I won't be repeating stuff from there unless absolutely necessary.

FAQ

Syntax highlighting / LSP doesn't work on session load

Make sure to enable "localoptions" in session options.

vim.opt.sessionoptions:append("localoptions")

Writing a status line component for projections

Session.info() is the function you are looking for.

-- Returns the path of the session file as well as project information
-- Returns nil if path is not a valid project path
-- @args spath The path to project root
-- @returns nil | path of session file and project information
function Session.info(spath) ... end

So, suppose if you want to display project name in your status line,

local project_name_display = function ()
    local projections_available, Session = pcall(require, 'projections.session')
    if projections_available then
        local info = Session.info(vim.loop.cwd())
        if info ~= nil then
            -- local session_file_path = tostring(info.path)
            -- local project_workspace_patterns = info.project.workspace.patterns
            -- local project_workspace_path = tostring(info.project.workspace)
            local project_name = info.project.name
            return '' .. project_name
        end
    end
    return vim.fs.basename(vim.loop.cwd())
end

Now, depending on your status line plugin, you can use this function. For example, with lualine.

require('lualine').setup({
    sections = { lualine_c = { { project_name_display } } }
})

Can projections ship with some of this code? There are some major problems.

  1. There are a lot of statusline plugins. And I need to ship code for quite a few of them. lualine, galaxyline, neoline, bubbly etc..
  2. Some plugins like lualine have extension code in their own repository. So, the following snippet would be present in lualine, not in projections
  3. There is no way to make sure that everyone is satisfied. People might want, among various other things, the ability to show icons only, show project name, show session path, show custom icon, etc.