kawre / leetcode.nvim

A Neovim plugin enabling you to solve LeetCode problems.
MIT License
655 stars 34 forks source link

Plugin won't open after 2f9b199e5493c556569ecca5ad08c924706110ea #15

Closed Zeioth closed 8 months ago

Zeioth commented 8 months ago

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 commented 8 months ago

What is your neovim version

kawre commented 8 months ago

Try removing event = "VeryLazy"

Zeioth commented 8 months ago

@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 commented 8 months ago

Ok, it actually works if I specify lazy = false

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

kawre commented 8 months ago

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.

Zeioth commented 8 months ago

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 commented 8 months ago

@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 commented 8 months ago

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 commented 8 months ago

@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 commented 8 months ago

@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 commented 7 months ago

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.