mirror of
				https://github.com/NotAShelf/nvf.git
				synced 2025-10-31 11:02:37 +00:00 
			
		
		
		
	languages/clang: convert module
This commit is contained in:
		
					parent
					
						
							
								4a876305f6
							
						
					
				
			
			
				commit
				
					
						75288f33bc
					
				
			
		
					 1 changed files with 26 additions and 47 deletions
				
			
		|  | @ -5,48 +5,36 @@ | ||||||
|   ... |   ... | ||||||
| }: let | }: let | ||||||
|   inherit (builtins) attrNames; |   inherit (builtins) attrNames; | ||||||
|   inherit (lib.lists) isList; |  | ||||||
|   inherit (lib.strings) optionalString; |   inherit (lib.strings) optionalString; | ||||||
|   inherit (lib.options) mkEnableOption mkOption; |   inherit (lib.options) mkEnableOption mkOption; | ||||||
|   inherit (lib.types) bool enum package either listOf str nullOr; |   inherit (lib.types) bool enum package str nullOr; | ||||||
|  |   inherit (lib.meta) getExe getExe'; | ||||||
|   inherit (lib.modules) mkIf mkMerge; |   inherit (lib.modules) mkIf mkMerge; | ||||||
|   inherit (lib.nvim.lua) expToLua; |   inherit (lib.nvim.attrsets) mapListToAttrs; | ||||||
|   inherit (lib.nvim.types) mkGrammarOption; |   inherit (lib.nvim.types) mkGrammarOption mkServersOption; | ||||||
|   inherit (lib.nvim.dag) entryAfter; |   inherit (lib.nvim.dag) entryAfter; | ||||||
| 
 | 
 | ||||||
|   packageToCmd = package: defaultCmd: |  | ||||||
|     if isList cfg.lsp.package |  | ||||||
|     then expToLua cfg.lsp.package |  | ||||||
|     else ''{ "${cfg.lsp.package}/bin/${defaultCmd}" }''; |  | ||||||
| 
 |  | ||||||
|   cfg = config.vim.languages.clang; |   cfg = config.vim.languages.clang; | ||||||
| 
 | 
 | ||||||
|   defaultServer = "clangd"; |   defaultServers = ["clangd"]; | ||||||
|   servers = { |   servers = { | ||||||
|     ccls = { |     ccls = { | ||||||
|       package = pkgs.ccls; |       enable = true; | ||||||
|       lspConfig = '' |       cmd = [(getExe pkgs.ccls)]; | ||||||
|         lspconfig.ccls.setup{ |       filetypes = ["c" "cpp"]; | ||||||
|           capabilities = capabilities; |       root_markers = [".clangd" "compile_commands.json" ".git"]; | ||||||
|           on_attach=default_on_attach; |       init_options = optionalString (cfg.lsp.opts != null) cfg.lsp.opts; | ||||||
|           cmd = ${packageToCmd cfg.lsp.package "ccls"}; |  | ||||||
|           ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"} |  | ||||||
|         } |  | ||||||
|       ''; |  | ||||||
|     }; |     }; | ||||||
|  | 
 | ||||||
|     clangd = { |     clangd = { | ||||||
|       package = pkgs.clang-tools; |       enable = true; | ||||||
|       lspConfig = '' |       cmd = [(getExe' pkgs.clang-tools "clangd")]; | ||||||
|         local clangd_cap = capabilities |       filetypes = ["c" "cpp"]; | ||||||
|         -- use same offsetEncoding as null-ls |       root_markers = [".clangd" "compile_commands.json" ".git"]; | ||||||
|         clangd_cap.offsetEncoding = {"utf-16"} |       capabilities = { | ||||||
|         lspconfig.clangd.setup{ |         offsetEncoding = ["utf-16"]; | ||||||
|           capabilities = clangd_cap; |       }; | ||||||
|           on_attach=default_on_attach; |       init_options = optionalString (cfg.lsp.opts != null) cfg.lsp.opts; | ||||||
|           cmd = ${packageToCmd cfg.lsp.package "clangd"}; |  | ||||||
|           ${optionalString (cfg.lsp.opts != null) "init_options = ${cfg.lsp.opts}"} |  | ||||||
|         } |  | ||||||
|       ''; |  | ||||||
|     }; |     }; | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  | @ -99,19 +87,7 @@ in { | ||||||
| 
 | 
 | ||||||
|     lsp = { |     lsp = { | ||||||
|       enable = mkEnableOption "clang LSP support" // {default = config.vim.lsp.enable;}; |       enable = mkEnableOption "clang LSP support" // {default = config.vim.lsp.enable;}; | ||||||
| 
 |       servers = mkServersOption "clang" servers defaultServers; | ||||||
|       server = mkOption { |  | ||||||
|         description = "The clang LSP server to use"; |  | ||||||
|         type = enum (attrNames servers); |  | ||||||
|         default = defaultServer; |  | ||||||
|       }; |  | ||||||
| 
 |  | ||||||
|       package = mkOption { |  | ||||||
|         description = "clang LSP server package, or the command to run as a list of strings"; |  | ||||||
|         example = ''[lib.getExe pkgs.jdt-language-server " - data " " ~/.cache/jdtls/workspace "]''; |  | ||||||
|         type = either package (listOf str); |  | ||||||
|         default = servers.${cfg.lsp.server}.package; |  | ||||||
|       }; |  | ||||||
| 
 | 
 | ||||||
|       opts = mkOption { |       opts = mkOption { | ||||||
|         description = "Options to pass to clang LSP server"; |         description = "Options to pass to clang LSP server"; | ||||||
|  | @ -150,9 +126,12 @@ in { | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     (mkIf cfg.lsp.enable { |     (mkIf cfg.lsp.enable { | ||||||
|       vim.lsp.lspconfig.enable = true; |       vim.lsp.servers = | ||||||
| 
 |         mapListToAttrs (n: { | ||||||
|       vim.lsp.lspconfig.sources.clang-lsp = servers.${cfg.lsp.server}.lspConfig; |           name = n; | ||||||
|  |           value = servers.${n}; | ||||||
|  |         }) | ||||||
|  |         cfg.lsp.servers; | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     (mkIf cfg.dap.enable { |     (mkIf cfg.dap.enable { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 poz
				poz