Skip to content
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

feat(loader): always load plugins in order of priority #1607

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hoofcushion
Copy link

Problem :

The plugins stored in require("lazy.core.handler").handlers[type]active is a hash map, it will be disordered to use require("lazy.core.loader").load to load it.

Solution:

Convert every plugin that passed in require("lazy.core.loader").load to a list at first, and use table.sort to make them in order of priority.

My plugin list:

图片

Before:

图片

After:

图片

Note that the plugins with higher priority will be loaded first.

@hoofcushion
Copy link
Author

Sorry for force push, I do that because I didn't format the file, sorry.

@hoofcushion hoofcushion changed the title feat(ui): always load plugins in order of priority feat(loader): always load plugins in order of priority Jul 10, 2024
@hoofcushion
Copy link
Author

hoofcushion commented Jul 10, 2024

It may be unclear with my previous statement.

So, when invoking the command :=require("lazy.core.handler").handlers.event.active, the output will look like this:

{
  InsertEnter = {
    LuaSnip = "LuaSnip",
    ["cmp-spell"] = "cmp-spell",
    ["fittencode.nvim"] = "fittencode.nvim",
    ["nvim-treesitter-endwise"] = "nvim-treesitter-endwise"
  },
  LspAttach = {
    ["cmp-nvim-lsp"] = "cmp-nvim-lsp",
    ["cmp-nvim-lsp-document-symbol"] = "cmp-nvim-lsp-document-symbol",
    ["lspsaga.nvim"] = "lspsaga.nvim",
    ["nvim-navic"] = "nvim-navic",
    ["symbol-usage.nvim"] = "symbol-usage.nvim"
  },
}

And in this code:

-- load the plugins
Loader.load(self.active[event.id], { [self.type] = event.id })

The event handler uses the table as an argument for the function require("lazy.core.loader").load. Note that this table is a hash map, which means that the order of the elements is not guaranteed.

And what I do is just make every plugin table that passed into require("lazy.core.loader").load to convert to a list first, then sort them to make them loads in order of priority.

Copy link
Contributor

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the stale label Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant