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

Plugins load ahead of dependency plugins #557

Closed
Avimitin opened this issue Aug 17, 2021 · 20 comments
Closed

Plugins load ahead of dependency plugins #557

Avimitin opened this issue Aug 17, 2021 · 20 comments
Labels

Comments

@Avimitin
Copy link

  • nvim --version: NVIM v0.6.0-dev+132-g7d2233fad
  • git --version: git version 2.32.0
  • Operating system/version: Linux 5.13.10-arch1-1 x86_64 GNU/Linux
  • Terminal name/version: simple terminal

Steps to reproduce

Using configuration:

  use {
    'simrat39/rust-tools.nvim',
    ft={"rust"},
    config=function()
      print("loading")
      require("plugins.rust")
    end,
  }

Actual behaviour

Use the command :messages after opening the main.rs file, there is no line printed. Also, the require plugin is not loaded too.

Expected behaviour

The config should be loaded after I open the rust file.

packer files

Plugin specification file(s)

https://github.com/Avimitin/nvim/blob/master/lua/plug.lua#L305

packer log file

Post the contents of ~/.cache/nvim/packer.nvim.log here

packer compiled file

http://fars.ee/sAl9

@Avimitin Avimitin added the bug label Aug 17, 2021
@B3RR10
Copy link

B3RR10 commented Sep 3, 2021

I can confirm the same behavior for type http.

    use {
      'NTBBloodbath/rest.nvim',
      requires = { 'nvim-lua/plenary.nvim' },
      ft = { 'http' },
      config = function()
        print 'before'
        require 'plugins.rest'
      end
    }

I see neither the printed message, nor is the lua file loaded.

If I remove the ft parameter and execute PackerSync, then it works...

@wbthomason
Copy link
Owner

Hi, sorry for my very delayed response! I'm still catching up on issues that came in during my time away (#562).

@Avimitin: In trying to reproduce your example, I see that the FileType rust autocommand packer generates is being triggered, but the load function it's supposed to call is never running...

I'm trying to figure out why this would be (since it runs for other lazy-load events correctly).

@wbthomason
Copy link
Owner

In fact none of the FileType autocommands seem to be running as they should, though every other autocommand type (e.g. InsertEnter, etc.) that I've tried does.

@wbthomason
Copy link
Owner

This might be an upstream bug - when I remove the ++once specifier from the autocommand, it runs as expected.

@wbthomason
Copy link
Owner

A bit more information: this seems to be related to this difference between Neovim and Vim: https://github.com/neovim/neovim/wiki/FAQ#calling-inputlist-echomsg-etc-in-filetype-plugins-and-autocmd-does-not-work

Can I ask how you were verifying that the require in your example was not running? If it was by printing a message, then it may actually be loading correctly and just not displaying for this same reason.

@Avimitin
Copy link
Author

Avimitin commented Sep 7, 2021

Yes, I put the print line inside the require Lua file. But the Lua file contains some settings which is not activated. So I think the require step is not called. I will try to test option shortmess-=F later.

@wbthomason
Copy link
Owner

Ok - if you can let me know what your testing shows, that would be helpful to determine if this is a real problem (i.e. configs aren't running) or an annoyance with Neovim differing from Vim (i.e. configs are running but prints don't show during this particular autocommand).

@Avimitin
Copy link
Author

Avimitin commented Sep 12, 2021

After setting the shortmess-=F options, the print message appears correctly. But I got something unexpected now. As I set the requires field like below:

    use {
        'simrat39/rust-tools.nvim',
        ft = {"rust"},
        requires = {{"nvim-lspconfig"}, {"telescope.nvim"}},
        config = function()
            print("loading")
            require("plugins.rust")
        end
    }

But it still reporting errors that lspconfig does not exist.

image

And it works fine if I deleted the ft field.

image

@Avimitin
Copy link
Author

Also, this reminds me that why I can't get the plugin set up. I write if statement to handle error message:

local ok, error = pcall(require, 'rust-tools')
if not ok then
    print(error)
    return
end

And after I unset the option shortmess-=F, I can't see any error report. So it seems like the problem is not rust filetype not triggered, it is a problem about the rust-tools.nvim plugin loaded before the nvim-lspconfig plugin, but error not report because of neovim silent it.

@Avimitin Avimitin changed the title Filetype "rust" can't be triggered Plugins load ahead of dependency plugins Sep 12, 2021
@wbthomason
Copy link
Owner

Ah - if you want sequencing, then you should use the wants (to load a set of plugins before the given plugin) or after (to load the given plugin after one or more other plugins) keys.

You probably want something like

use {
        'simrat39/rust-tools.nvim',
        ft = {"rust"},
        requires = {{"nvim-lspconfig"}, {"telescope.nvim"}},
        wants = 'nvim-lspconfig',
        config = function()
            print("loading")
            require("plugins.rust")
        end
    }

@Avimitin
Copy link
Author

I don't see want field in README. But I've tried the after field, which is not working, the rust-tools plugin still load before lspconfig.

use {
        'simrat39/rust-tools.nvim',
        ft = {"rust"},
        requires = {{"nvim-lspconfig"}, {"telescope.nvim"}},
        after = {'nvim-lspconfig'},
        config = function()
            require("plugins.rust")
        end
    }

Above snip is not working. But if I removed the lazy loading, the after fields works as expected.

@Avimitin
Copy link
Author

I've tried wants which works fine.

And below is what happen when try to sequence with after field.

Screenshot_20210914-112059_Termius
Screenshot_20210914-111955_Termius

Maybe you should add the wants description in the https://github.com/wbthomason/packer.nvim#specifying-plugins part.

@wbthomason
Copy link
Owner

Documentation of wants is currently intentionally missing; it was only intended to be a temporary feature before we merged the functionality of it and after and requires to be less confusing. Enough people are using it as-is that I should probably just document it until I get around to the functionality merge.

For the problem with after: when do you load lspconfig?

@Avimitin
Copy link
Author

After BufRead event

@wbthomason
Copy link
Owner

I'm not 100% certain, but from the docs (:h BufRead) I think that BufRead may trigger after FileType, meaning that the ft condition for loading rust_tools is met, and loading it before lspconfig.

@Avimitin
Copy link
Author

How to check the sequence between these auto commands? I want to have a test on them.

@Avimitin
Copy link
Author

Avimitin commented Sep 16, 2021

With a try that set nvim-lspconfig with VimEnter and rust-tools.nvim with FileType and BufRead, the plugins are not loaded as expected.

With a try that set nvim-lspconfig to keep the BufRead event, and rust-tools.nvim with VimEnter event, the plugins load as expected.

So this maybe can prove that your guess is right. But I only know that VimEnter is the last auto command, so I am not 100% percent sure too. Is there any auto command to run before BufRead?

@Avimitin
Copy link
Author

Another detail: if the rust-tools.nvim and nvim-lspconfig are all set to BufRead, the rust-tools.nvim is still loaded before nvim-lspconfig. Maybe the after command has some internal error?

@akinsho
Copy link
Collaborator

akinsho commented Sep 16, 2021

This seems more like an issue with autocommands events and ordering than a specific packer bug at this point (sorry for weighing in pretty late). @Avimitin you can find all the available autocommands and when they all run using :h autocmd-events there is BufReadPre but that might not be early enough for what you want. In either case it does seem at this point that it's more about figuring out how you want to structure this in your config rather than anything packer is or isn't doing.

As for after maybe being buggy, if you set two plugins to load on the exact same autocommand I think you will face a race condition since there is no clear way that I know (could be wrong) to know that one will load before the other or vice versa.

Lastly lspconfig's maintainer has on many occasions warned users against trying to lazy load the plugin since it already handles its setup lazily, so lazy loading it isn't advised/useful (except in the case where it's setup calls another expensive plugin and you are trying to avoid that)

@Avimitin
Copy link
Author

My current workaround is to set wants field in rust-tools.nvim. Also, I've test that deletes lazyloading in lspconfig, and yes, it's not making neovim laggy. The start-up time is still the same. So maybe there is no need for finding an auto command to make the rust-tools.nvim plugin load after lspconfig.

Thx for your help!

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

No branches or pull requests

4 participants