mirror of
				https://github.com/NotAShelf/nvf.git
				synced 2025-10-31 19:12:38 +00:00 
			
		
		
		
	astro module overhaul
This commit is contained in:
		
					parent
					
						
							
								0bf6912626
							
						
					
				
			
			
				commit
				
					
						72d129f69a
					
				
			
		
					 1 changed files with 43 additions and 26 deletions
				
			
		|  | @ -12,25 +12,46 @@ | ||||||
|   inherit (lib.types) enum either listOf package str; |   inherit (lib.types) enum either listOf package str; | ||||||
|   inherit (lib.generators) mkLuaInline; |   inherit (lib.generators) mkLuaInline; | ||||||
|   inherit (lib.nvim.lua) expToLua; |   inherit (lib.nvim.lua) expToLua; | ||||||
|  |   inherit (lib.nvim.attrsets) mapListToAttrs; | ||||||
|   inherit (lib.nvim.types) mkGrammarOption diagnostics; |   inherit (lib.nvim.types) mkGrammarOption diagnostics; | ||||||
| 
 | 
 | ||||||
|   cfg = config.vim.languages.astro; |   cfg = config.vim.languages.astro; | ||||||
| 
 | 
 | ||||||
|   defaultServer = "astro"; |   defaultServers = ["astro"]; | ||||||
|   servers = { |   servers = { | ||||||
|     astro = { |     astro = { | ||||||
|       package = pkgs.astro-language-server; |       enable = true; | ||||||
|       lspConfig = '' |       cmd = [(getExe pkgs.astro-language-server) "--stdio"]; | ||||||
|         lspconfig.astro.setup { |       filetypes = ["astro"]; | ||||||
|           capabilities = capabilities, |       root_markers = ["package.json" "tsconfig.json" "jsconfig.json" ".git"]; | ||||||
|           on_attach = attach_keymaps, |       init_options = { | ||||||
|           cmd = ${ |         typescript = {}; | ||||||
|           if isList cfg.lsp.package |       }; | ||||||
|           then expToLua cfg.lsp.package |       before_init = | ||||||
|           else ''{"${cfg.lsp.package}/bin/astro-ls", "--stdio"}'' |         mkLuaInline | ||||||
|         } |         /* | ||||||
|         } |         lua | ||||||
|       ''; |         */ | ||||||
|  |         '' | ||||||
|  |           function(_, config) | ||||||
|  |             -- TODO: Make this a shared util function | ||||||
|  |             local get_typescript_server_path = function(root_dir) | ||||||
|  |               local project_roots = vim.fs.find('node_modules', { path = root_dir, upward = true, limit = math.huge }) | ||||||
|  |               for _, project_root in ipairs(project_roots) do | ||||||
|  |                 local typescript_path = project_root .. '/typescript' | ||||||
|  |                 local stat = vim.loop.fs_stat(typescript_path) | ||||||
|  |                 if stat and stat.type == 'directory' then | ||||||
|  |                   return typescript_path .. '/lib' | ||||||
|  |                 end | ||||||
|  |               end | ||||||
|  |               return ''' | ||||||
|  |             end | ||||||
|  | 
 | ||||||
|  |             if config.init_options and config.init_options.typescript and not config.init_options.typescript.tsdk then | ||||||
|  |               config.init_options.typescript.tsdk = get_typescript_server_path(config.root_dir) | ||||||
|  |             end | ||||||
|  |           end | ||||||
|  |         ''; | ||||||
|     }; |     }; | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  | @ -82,18 +103,10 @@ in { | ||||||
| 
 | 
 | ||||||
|     lsp = { |     lsp = { | ||||||
|       enable = mkEnableOption "Astro LSP support" // {default = config.vim.lsp.enable;}; |       enable = mkEnableOption "Astro LSP support" // {default = config.vim.lsp.enable;}; | ||||||
| 
 |       servers = mkOption { | ||||||
|       server = mkOption { |  | ||||||
|         type = enum (attrNames servers); |  | ||||||
|         default = defaultServer; |  | ||||||
|         description = "Astro LSP server to use"; |         description = "Astro LSP server to use"; | ||||||
|       }; |         type = listOf (enum (attrNames servers)); | ||||||
| 
 |         default = defaultServers; | ||||||
|       package = mkOption { |  | ||||||
|         type = either package (listOf str); |  | ||||||
|         default = servers.${cfg.lsp.server}.package; |  | ||||||
|         example = ''[lib.getExe pkgs.astro-language-server "--minify" "--stdio"]''; |  | ||||||
|         description = "Astro LSP server package, or the command to run as a list of strings"; |  | ||||||
|       }; |       }; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | @ -131,8 +144,12 @@ in { | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     (mkIf cfg.lsp.enable { |     (mkIf cfg.lsp.enable { | ||||||
|       vim.lsp.lspconfig.enable = true; |       vim.lsp.servers = | ||||||
|       vim.lsp.lspconfig.sources.astro-lsp = servers.${cfg.lsp.server}.lspConfig; |         mapListToAttrs (n: { | ||||||
|  |           name = n; | ||||||
|  |           value = servers.${n}; | ||||||
|  |         }) | ||||||
|  |         cfg.lsp.servers; | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     (mkIf cfg.format.enable { |     (mkIf cfg.format.enable { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 sjcobb
				sjcobb