mirror of
				https://github.com/NotAShelf/nvf.git
				synced 2025-10-31 02:52:37 +00:00 
			
		
		
		
	feat(copilot): custom setup opts
This commit is contained in:
		
					parent
					
						
							
								62b0791b75
							
						
					
				
			
			
				commit
				
					
						88c22ef026
					
				
			
		
					 2 changed files with 65 additions and 66 deletions
				
			
		|  | @ -4,10 +4,10 @@ | ||||||
|   ... |   ... | ||||||
| }: let | }: let | ||||||
|   inherit (builtins) toJSON; |   inherit (builtins) toJSON; | ||||||
|  |   inherit (lib.nvim.lua) toLuaObject; | ||||||
|   inherit (lib.modules) mkIf mkMerge; |   inherit (lib.modules) mkIf mkMerge; | ||||||
|   inherit (lib.nvim.dag) entryAnywhere; |   inherit (lib.nvim.dag) entryAnywhere; | ||||||
|   inherit (lib.lists) optionals; |   inherit (lib.lists) optionals; | ||||||
|   inherit (lib.trivial) boolToString; |  | ||||||
|   inherit (lib.nvim.binds) mkLuaBinding; |   inherit (lib.nvim.binds) mkLuaBinding; | ||||||
| 
 | 
 | ||||||
|   cfg = config.vim.assistant.copilot; |   cfg = config.vim.assistant.copilot; | ||||||
|  | @ -28,55 +28,47 @@ in { | ||||||
|     vim.startPlugins = |     vim.startPlugins = | ||||||
|       [ |       [ | ||||||
|         "copilot-lua" |         "copilot-lua" | ||||||
|         cfg.copilotNodePackage |         # cfg.copilotNodePackage | ||||||
|       ] |       ] | ||||||
|       ++ optionals (cfg.cmp.enable) [ |       ++ optionals (cfg.cmp.enable) [ | ||||||
|         "copilot-cmp" |         "copilot-cmp" | ||||||
|       ]; |       ]; | ||||||
| 
 | 
 | ||||||
|     vim.luaConfigRC.copilot = entryAnywhere '' |     vim.luaConfigRC.copilot = entryAnywhere '' | ||||||
|       require("copilot").setup({ |       require("copilot").setup(${toLuaObject cfg.setupOpts}) | ||||||
|         -- available options: https://github.com/zbirenbaum/copilot.lua |  | ||||||
|         copilot_node_command = "${cfg.copilotNodeCommand}", |  | ||||||
|         panel = { |  | ||||||
|           enabled = ${boolToString (!cfg.cmp.enable)}, |  | ||||||
|           keymap = { |  | ||||||
|             jump_prev = false, |  | ||||||
|             jump_next = false, |  | ||||||
|             accept = false, |  | ||||||
|             refresh = false, |  | ||||||
|             open = false, |  | ||||||
|           }, |  | ||||||
|           layout = { |  | ||||||
|             position = "${cfg.panel.position}", |  | ||||||
|             ratio = ${toString cfg.panel.ratio}, |  | ||||||
|           }, |  | ||||||
|         }, |  | ||||||
|         suggestion = { |  | ||||||
|           enabled = ${boolToString (!cfg.cmp.enable)}, |  | ||||||
|           keymap = { |  | ||||||
|             accept = false, |  | ||||||
|             accept_word = false, |  | ||||||
|             accept_line = false, |  | ||||||
|             next = false, |  | ||||||
|             prev = false, |  | ||||||
|             dismiss = false, |  | ||||||
|           }, |  | ||||||
|         }, |  | ||||||
|       }) |  | ||||||
| 
 | 
 | ||||||
|       ${lib.optionalString (cfg.cmp.enable) '' |       ${lib.optionalString (cfg.cmp.enable) '' | ||||||
|         require("copilot_cmp").setup() |         require("copilot_cmp").setup() | ||||||
|       ''} |       ''} | ||||||
|     ''; |     ''; | ||||||
| 
 | 
 | ||||||
|  |     # Disable plugin handled keymaps. | ||||||
|  |     # Setting it here so that it doesn't show up in user docs | ||||||
|  |     vim.assistant.copilot.setupOpts = { | ||||||
|  |       panel.keymap = { | ||||||
|  |         jump_prev = lib.mkDefault false; | ||||||
|  |         jump_next = lib.mkDefault false; | ||||||
|  |         accept = lib.mkDefault false; | ||||||
|  |         refresh = lib.mkDefault false; | ||||||
|  |         open = lib.mkDefault false; | ||||||
|  |       }; | ||||||
|  |       suggestion.keymap = { | ||||||
|  |         accept = lib.mkDefault false; | ||||||
|  |         accept_word = lib.mkDefault false; | ||||||
|  |         accept_line = lib.mkDefault false; | ||||||
|  |         next = lib.mkDefault false; | ||||||
|  |         prev = lib.mkDefault false; | ||||||
|  |         dismiss = lib.mkDefault false; | ||||||
|  |       }; | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|     vim.maps.normal = mkMerge [ |     vim.maps.normal = mkMerge [ | ||||||
|       (mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion") |       (mkLuaBinding cfg.mappings.panel.jumpPrev (wrapPanelBinding "require(\"copilot.panel\").jump_prev" cfg.mappings.panel.jumpPrev) "[copilot] Accept suggestion") | ||||||
|       (mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion") |       (mkLuaBinding cfg.mappings.panel.jumpNext (wrapPanelBinding "require(\"copilot.panel\").jump_next" cfg.mappings.panel.jumpNext) "[copilot] Accept suggestion") | ||||||
|       (mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion") |       (mkLuaBinding cfg.mappings.panel.accept (wrapPanelBinding ''require("copilot.panel").accept'' cfg.mappings.panel.accept) "[copilot] Accept suggestion") | ||||||
|       (mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion") |       (mkLuaBinding cfg.mappings.panel.refresh (wrapPanelBinding "require(\"copilot.panel\").refresh" cfg.mappings.panel.refresh) "[copilot] Accept suggestion") | ||||||
|       (mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding '' |       (mkLuaBinding cfg.mappings.panel.open (wrapPanelBinding '' | ||||||
|           function() require("copilot.panel").open({ position = "${cfg.panel.position}", ratio = ${toString cfg.panel.ratio}, }) end |           function() require("copilot.panel").open({ position = "${cfg.setupOpts.panel.layout.position}", ratio = ${toString cfg.setupOpts.panel.layout.ratio}, }) end | ||||||
|         '' |         '' | ||||||
|         cfg.mappings.panel.open) "[copilot] Accept suggestion") |         cfg.mappings.panel.open) "[copilot] Accept suggestion") | ||||||
|     ]; |     ]; | ||||||
|  |  | ||||||
|  | @ -4,31 +4,56 @@ | ||||||
|   lib, |   lib, | ||||||
|   ... |   ... | ||||||
| }: let | }: let | ||||||
|  |   inherit (lib) mkRenamedOptionModule; | ||||||
|   inherit (lib.options) mkEnableOption mkOption; |   inherit (lib.options) mkEnableOption mkOption; | ||||||
|   inherit (lib.types) enum float nullOr str package; |   inherit (lib.types) nullOr str enum float; | ||||||
|   inherit (lib.meta) getExe; |   inherit (lib.nvim.types) mkPluginSetupOption; | ||||||
| 
 | 
 | ||||||
|   cfg = config.vim.assistant.copilot; |   cfg = config.vim.assistant.copilot; | ||||||
| in { | in { | ||||||
|  |   imports = [ | ||||||
|  |     (mkRenamedOptionModule ["vim" "assistant" "copilot" "panel"] ["vim" "assistant" "copilot" "setupOpts" "panel"]) | ||||||
|  |     (mkRenamedOptionModule ["vim" "assistant" "copilot" "copilotNodeCommand"] ["vim" "assistant" "copilot" "setupOpts" "copilot_node_command"]) | ||||||
|  |     (mkRenamedOptionModule ["vim" "assistant" "copilot" "copilotNodePackage"] ["vim" "assistant" "copilot" "setupOpts" "copilot_node_command"]) | ||||||
|  |   ]; | ||||||
|  | 
 | ||||||
|   options.vim.assistant.copilot = { |   options.vim.assistant.copilot = { | ||||||
|     enable = mkEnableOption "GitHub Copilot AI assistant"; |     enable = mkEnableOption "GitHub Copilot AI assistant"; | ||||||
|     cmp.enable = mkEnableOption "nvim-cmp integration for GitHub Copilot"; |     cmp.enable = mkEnableOption "nvim-cmp integration for GitHub Copilot"; | ||||||
| 
 | 
 | ||||||
|     panel = { |     setupOpts = mkPluginSetupOption "Copilot" { | ||||||
|       position = mkOption { |       copilot_node_command = mkOption { | ||||||
|         type = enum [ |         type = str; | ||||||
|           "bottom" |         default = "${lib.getExe pkgs.nodejs-slim}"; | ||||||
|           "top" |         description = '' | ||||||
|           "left" |           The command that will be executed to initiate nodejs for GitHub Copilot. | ||||||
|           "right" |           Recommended to leave as default. | ||||||
|         ]; |         ''; | ||||||
|         default = "bottom"; |  | ||||||
|         description = "Panel position"; |  | ||||||
|       }; |       }; | ||||||
|       ratio = mkOption { |       panel = { | ||||||
|         type = float; |         enabled = mkEnableOption "Completion Panel" // {default = !cfg.cmp.enable;}; | ||||||
|         default = 0.4; |         layout = { | ||||||
|         description = "Panel size"; |           position = mkOption { | ||||||
|  |             type = enum [ | ||||||
|  |               "bottom" | ||||||
|  |               "top" | ||||||
|  |               "left" | ||||||
|  |               "right" | ||||||
|  |             ]; | ||||||
|  |             default = "bottom"; | ||||||
|  |             description = "Panel position"; | ||||||
|  |           }; | ||||||
|  |           ratio = mkOption { | ||||||
|  |             type = float; | ||||||
|  |             default = 0.4; | ||||||
|  |             description = "Panel size"; | ||||||
|  |           }; | ||||||
|  |         }; | ||||||
|  |       }; | ||||||
|  | 
 | ||||||
|  |       suggestion = { | ||||||
|  |         enabled = mkEnableOption "Suggestions" // {default = !cfg.cmp.enable;}; | ||||||
|  |         # keymap = { }; | ||||||
|       }; |       }; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | @ -102,23 +127,5 @@ in { | ||||||
|         }; |         }; | ||||||
|       }; |       }; | ||||||
|     }; |     }; | ||||||
| 
 |  | ||||||
|     copilotNodeCommand = mkOption { |  | ||||||
|       type = str; |  | ||||||
|       default = "${getExe cfg.copilotNodePackage}"; |  | ||||||
|       description = '' |  | ||||||
|         The command that will be executed to initiate nodejs for GitHub Copilot. |  | ||||||
|         Recommended to leave as default. |  | ||||||
|       ''; |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     copilotNodePackage = mkOption { |  | ||||||
|       type = nullOr package; |  | ||||||
|       default = pkgs.nodejs-slim; |  | ||||||
|       description = '' |  | ||||||
|         The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command |  | ||||||
|         you may want to set this option to null so that the package is not pulled from nixpkgs. |  | ||||||
|       ''; |  | ||||||
|     }; |  | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ching Pei Yang
				Ching Pei Yang