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

Plugin won't open after 2f9b199e5493c556569ecca5ad08c924706110ea #15

Closed
Zeioth opened this issue Oct 22, 2023 · 11 comments
Closed

Plugin won't open after 2f9b199e5493c556569ecca5ad08c924706110ea #15

Zeioth opened this issue Oct 22, 2023 · 11 comments

Comments

@Zeioth
Copy link

Zeioth commented Oct 22, 2023

This is the last commit where I can use nvim leetcode.nvim.

Any other commit I've tried after that one, won't start leetcode.nvim

My config

  -- Last functional commit
  {
    "kawre/leetcode.nvim",
    commit = "2f9b199e5493c556569ecca5ad08c924706110ea",
    event = "VeryLazy",
    dependencies = {
      "nvim-treesitter/nvim-treesitter",
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
      "nvim-tree/nvim-web-devicons",
      "rcarriga/nvim-notify",
    },
    opts = {
      lang = "typescript",
    },
    config = function(_, opts) require("leetcode").setup(opts) end,
  },

Screenshots

Working commit
screenshot_2023-10-22_03-06-16_573320584

After that
screenshot_2023-10-22_03-06-39_148783201

@kawre
Copy link
Owner

kawre commented Oct 22, 2023

What is your neovim version

@kawre
Copy link
Owner

kawre commented Oct 22, 2023

Try removing event = "VeryLazy"

@Zeioth
Copy link
Author

Zeioth commented Oct 22, 2023

@kawre NVIM v0.10.0-dev-1378+gc49cfd89fd (neovim-git on arch linux)

Same result after removing VeryLazy and updating leetcode.nvim to latest.

@Zeioth
Copy link
Author

Zeioth commented Oct 22, 2023

Ok, it actually works if I specify lazy = false

But as I say this necesity was introduced only after the commit I mention.

@kawre
Copy link
Owner

kawre commented Oct 22, 2023

It's because i've changed leetcode.nvim to mount after VimEnter as there were some problems with other plugins/options overriding my local plugin options on boot.

Probably VeryLazy triggers after VimEnter resulting in leetcode.nvim never having a chance to even mount. If you want to mess around with lazy loading you can check out recipes.

@kawre kawre closed this as completed Oct 22, 2023
@Zeioth
Copy link
Author

Zeioth commented Oct 22, 2023

Fixed version just in case someone finds this on google

return {

  -- leetcode.nvim
  -- https://github.com/kawre/leetcode.nvim
  -- You found an easter egg!
  -- To use it, uncomment this, exit nvim and write "nvim leetcode.nvim"
  {
    "kawre/leetcode.nvim",
    lazy = false,
    dependencies = {
      "nvim-treesitter/nvim-treesitter",
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
      "nvim-tree/nvim-web-devicons",
      "rcarriga/nvim-notify",
    },
    opts = {
      -- HOW TO ENABLE TYPESCRIPT/JAVASCRIPT LINTING FOR THIS PLUGIN
      -- -----------------------------------------------------------
      -- * Install the eslint packages:
      -- npm install @typescript-eslint/eslint-plugin @typescript-eslint/parser
      -- * Then copy paste this into ~/.local/share/nvim/leetcode/.eslintrc.json
      -- https://pastebin.com/raw/aQXjpLuE
      lang = "typescript",
    },
    config = function(_, opts)
      -- Require it only if neovim starts with the argument 'leetcode.nvim'
      if vim.tbl_contains(vim.fn.argv(), 'leetcode.nvim') then
        require("leetcode").setup(opts)
      end
    end,
  },

}

@kawre
Copy link
Owner

kawre commented Oct 22, 2023

@Zeioth The problem with this is that it doesn't achieve anything actually. config gets executed after all of the required dependencies were loaded which is the main problem there.

Having a function checking whether to lazy load leetcode.nvim like in recipes will prevent all of the required dependencies from loading when not necessary.

@Zeioth
Copy link
Author

Zeioth commented Oct 23, 2023

Did you try it? It works as expected on my end. It might be redundant though if the plugin is already doing the same.

@Zeioth
Copy link
Author

Zeioth commented Nov 4, 2023

@kawre it would be cool being able to use the plugin with VeryLazy again, because as it is right now, (using lazy=false) it adds a good 30ms to startup time.

@kawre
Copy link
Owner

kawre commented Nov 4, 2023

@Zeioth
This startup time is because from what ive observed lazynvim waits for the dependencies required by my plugin and combines theirs startup time into mine. So if my plugin startup time is lets say 5ms and treesitters is 30ms it will combine it into 35ms.

If you are sure that some of the dependencies will load anyway, you can remove them from the dependencies list.

Right now my leetcode.nvim config has 0 dependencies as i load them elsewhere by events like "VeryLazy" anyway. This reduces the startup time to below 1ms.

You can also play around with lazy loading and see how it works, as i said before.

@Zeioth
Copy link
Author

Zeioth commented Nov 10, 2023

Ok I've been able to fix this by requiring the plugin in init only when the leetcode.nvim argument is passed to nvim.

  {
    "kawre/leetcode.nvim",
    dependencies = {
      "nvim-treesitter/nvim-treesitter",
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
      "nvim-tree/nvim-web-devicons",
      "rcarriga/nvim-notify",
    },
    init = function(_, opts)
      -- Require only when needed
      if vim.tbl_contains(vim.fn.argv(), 'leetcode.nvim') then
        require("leetcode").setup(opts)
      end
    end,
    opts = {
      lang = "typescript",
    },
  },

So same fix I had, but on init, to ensure it is applied on startup.

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

No branches or pull requests

2 participants