mirror of
				https://github.com/NotAShelf/nvf.git
				synced 2025-10-31 11:02:37 +00:00 
			
		
		
		
	treewide: implement lazy loading via lz.n for selected plugins (#407)
* flake: add lz.n and lzn-auto-require * lazy: init module * lzn-auto-require: add init lua code * wrapper: fix opt plugin format * lib.binds: add lz.n variant of bind functions * telescope: lazy load * nvim-tree: lazy load * dapui: lazy load * trouble: lazy load * toggleterm: lazy load * cheatsheet: lazy load * diffview: lazy load * icon-picker: lazy load * leap: lazy load * fidget: lazy load * docs: add section on lazy plugins * lazy: support lazy.enable=false * comment-nvim: lazy load * surround-nvim: lazy load * neo-tree: lazy load * fixup! lazy: init module * dap: appease the nix gods (fix statix lint) * flake.lock: fix merge mistake * doc: update release note * fixup! doc: update release note * neo-tree: fix duplicate neo-tree install * lazy: use attrsOf for lazy.plugins * treewide: update lazy.plugins syntax * docs: update lazy.plugins syntax * lazy: cleanup * Update docs/manual/hacking/additional-plugins.md Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * formatting nitpick Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * typo tee hee :3 Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * typo tee hee :4 Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * flake: update lz.n * lazy: update lz.n plugin spec * lazy: allow lines in place of str for lua code * copilot: lazy load * cmp: lazy load this moves cmp itself to lazy.plugins but other plugins that call cmp are not yet lazy so cmp is technically not yet lazy * luasnip: lazy load * flake: add rtp.nvim * cmp: actually lazy load source * fixup! cmp: actually lazy load source * format * docs: fix broken link * cmp-nvim-lsp: lazy load * lazy: allow key mode of str type * cmp: install sourcess via cmp.sourcePlugins * Update docs/manual/hacking/additional-plugins.md Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * lazy: refactor common var * nvim-dap-ui: add setupOpts * refactor: re-order plugin and lz.n configs lazy: make lzn-auto-require togglable * docs: update dag-entries * trouble: remove redundant import * lazy: remove unused module arg * toggleterm: make lazygit keybind optional * toggleterm: use toLuaObject for clarity * surround: rework keymap config * remove stale FIXME * lsp: use cmp_nvim_lsp capabilities * cmp: deduplicate attr key * theme: ensure themes load before lazy plugins * doc: update description of `theme` dag entry * lsp: avoid loading cmp on startup * doc: update configuration docs on custom plugins * cmp: skip trigger_load if lazy disabled * treesitter: remove redundant code * lsp: mark hack as HACK * comment: remove redundant plugin * Squash merge v0.7 into feature/lzn --------- Co-authored-by: raf <raf@notashelf.dev> Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
This commit is contained in:
		
					parent
					
						
							
								0e763161e2
							
						
					
				
			
			
				commit
				
					
						21fcace3ed
					
				
			
		
					 42 changed files with 1226 additions and 501 deletions
				
			
		|  | @ -1,12 +1,32 @@ | |||
| # Configuring {#sec-configuring-plugins} | ||||
| 
 | ||||
| Just making the plugin to your Neovim configuration available might not always | ||||
| be enough. In that case, you can write custom lua config using either | ||||
| `config.vim.extraPlugins` (which has the `setup` field) or | ||||
| `config.vim.luaConfigRC`. The first option uses an attribute set, which maps DAG | ||||
| section names to a custom type, which has the fields `package`, `after`, | ||||
| `setup`. They allow you to set the package of the plugin, the sections its setup | ||||
| code should be after (note that the `extraPlugins` option has its own DAG | ||||
| Just making the plugin to your Neovim configuration available might not always be enough. In that | ||||
| case, you can write custom lua config using either `config.vim.lazy.plugins.*.setupOpts` | ||||
| `config.vim.extraPlugins.*.setup` or `config.vim.luaConfigRC`.  | ||||
| 
 | ||||
| The first option uses an extended version of `lz.n`'s PluginSpec. `setupModule` and `setupOpt` can | ||||
| be used if the plugin uses a `require('module').setup(...)` pattern. Otherwise, the `before` and | ||||
| `after` hooks should do what you need. | ||||
| 
 | ||||
| ```nix | ||||
| { | ||||
|   config.vim.lazy.plugins = { | ||||
|     aerial-nvim = { | ||||
|       # ^^^^^^^^^ this name should match the package.pname or package.name | ||||
|       package = aerial-nvim; | ||||
| 
 | ||||
|       setupModule = "aerial"; | ||||
|       setupOpts = {option_name = false;}; | ||||
| 
 | ||||
|       after = "print('aerial loaded')"; | ||||
|     }; | ||||
|   }; | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| The second option uses an attribute set, which maps DAG section names to a custom type, which has | ||||
| the fields `package`, `after`, `setup`. They allow you to set the package of the plugin, the | ||||
| sections its setup code should be after (note that the `extraPlugins` option has its own DAG | ||||
| scope), and the its setup code respectively. For example: | ||||
| 
 | ||||
| ```nix | ||||
|  | @ -24,7 +44,7 @@ config.vim.extraPlugins = with pkgs.vimPlugins; { | |||
| } | ||||
| ``` | ||||
| 
 | ||||
| The second option also uses an attribute set, but this one is resolved as a DAG | ||||
| The third option also uses an attribute set, but this one is resolved as a DAG | ||||
| directly. The attribute names denote the section names, and the values lua code. | ||||
| For example: | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										40
									
								
								docs/manual/configuring/custom-plugins/lazy-method.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								docs/manual/configuring/custom-plugins/lazy-method.md
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,40 @@ | |||
| # Lazy Method {#sec-lazy-method} | ||||
| 
 | ||||
| As of version **0.7**, we exposed an API for configuring lazy-loaded plugins via | ||||
| `lz.n` and `lzn-auto-require`. | ||||
| 
 | ||||
| ```nix | ||||
| { | ||||
|   config.vim.lazy.plugins = { | ||||
|     aerial = { | ||||
|       package = pkgs.vimPlugins.aerial-nvim; | ||||
|       setupModule = aerial; | ||||
|       setupOpts = { | ||||
|         option_name = true; | ||||
|       }; | ||||
|       after = '' | ||||
|         -- custom lua code to run after plugin is loaded | ||||
|         print('aerial loaded') | ||||
|       ''; | ||||
| 
 | ||||
|       # Explicitly mark plugin as lazy. You don't need this if you define one of | ||||
|       # the trigger "events" below | ||||
|       lazy = true; | ||||
| 
 | ||||
|       # load on command | ||||
|       cmd = ["AerialOpen"]; | ||||
| 
 | ||||
|       # load on event | ||||
|       event = ["BufEnter"]; | ||||
| 
 | ||||
|       # load on keymap | ||||
|       keys = [ | ||||
|         { | ||||
|           key = "<leader>a"; | ||||
|           action = ":AerialToggle<CR>"; | ||||
|         } | ||||
|       ]; | ||||
|     }; | ||||
|   }; | ||||
| } | ||||
| ``` | ||||
|  | @ -1,4 +1,4 @@ | |||
| # Old Method {#sec-old-method} | ||||
| # Legacy Method {#sec-legacy-method} | ||||
| 
 | ||||
| Prior to version 0.5, the method of adding new plugins was adding the plugin | ||||
| package to `vim.startPlugins` and add its configuration as a DAG under one of | ||||
|  | @ -1,4 +1,4 @@ | |||
| # New Method {#sec-new-method} | ||||
| # Non-lazy Method {#sec-non-lazy-method} | ||||
| 
 | ||||
| As of version **0.5**, we have a more extensive API for configuring plugins, | ||||
| under `vim.extraPlugins`. Instead of using DAGs exposed by the library, you may | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ching Pei Yang
				Ching Pei Yang