folke / lazy.nvim

đŸ’¤ A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14k stars 337 forks source link

feature: check is plugin loaded programmatically #712

Closed ArtAndreev closed 1 year ago

ArtAndreev commented 1 year ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

I have a statusline (lualine) that has a component dap (https://github.com/mfussenegger/nvim-dap) status:

lualine_c = {
  {
    function() return require("dap").status() end,
    cond = function()
      local session = require("dap").session()
      return session ~= nil
    end,
  },
}

The package dap is set to be loaded lazily, but loading is triggered by lualine, but my debugger isn't running at this moment and I don't want to load the package. Is there a way to check dap is loaded and not to trigger loading by require?

Describe the solution you'd like

A function that allows to check is package loaded or not.

So the condition in lualine will be something like that:

cond = function()
  if not require("lazy").is_loaded("dap") then
    return false
  end
  local session = require("dap").session()
  return session ~= nil
end,

Describe alternatives you've considered

Search in code and found private API package._.loaded.

Additional context

No response

ArtAndreev commented 1 year ago

Just remembered about package.loaded.

My condition is now:

cond = function()
  if not package.loaded.dap then
    return false
  end
  local session = require("dap").session()
  return session ~= nil
end,