feat: More user friendly language server installation
This commit is contained in:
		
							parent
							
								
									6dccf03fd2
								
							
						
					
					
						commit
						b4173c7a4e
					
				
							
								
								
									
										53
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										53
									
								
								init.lua
								
								
								
								
							| 
						 | 
				
			
			@ -3,7 +3,7 @@ local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nv
 | 
			
		|||
local is_bootstrap = false
 | 
			
		||||
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
 | 
			
		||||
  is_bootstrap = true
 | 
			
		||||
  vim.fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
 | 
			
		||||
  vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }
 | 
			
		||||
  vim.cmd [[packadd packer.nvim]]
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -335,37 +335,35 @@ end
 | 
			
		|||
-- Setup mason so it can manage external tooling
 | 
			
		||||
require('mason').setup()
 | 
			
		||||
 | 
			
		||||
-- Enable the following language servers
 | 
			
		||||
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed
 | 
			
		||||
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', 'gopls' }
 | 
			
		||||
 | 
			
		||||
-- Ensure the servers above are installed
 | 
			
		||||
require('mason-lspconfig').setup {
 | 
			
		||||
  ensure_installed = servers,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- nvim-cmp supports additional completion capabilities
 | 
			
		||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
 | 
			
		||||
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
 | 
			
		||||
 | 
			
		||||
for _, lsp in ipairs(servers) do
 | 
			
		||||
  require('lspconfig')[lsp].setup {
 | 
			
		||||
    on_attach = on_attach,
 | 
			
		||||
-- Configure language servers
 | 
			
		||||
--  Automatically install language servers
 | 
			
		||||
--  Set up a default handler for language servers, and a custom one as an example
 | 
			
		||||
local mason_lspconfig = require 'mason-lspconfig'
 | 
			
		||||
mason_lspconfig.setup {
 | 
			
		||||
  automatic_installation = true,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
mason_lspconfig.setup_handlers {
 | 
			
		||||
  -- Default handler
 | 
			
		||||
  function(server_name)
 | 
			
		||||
    require('lspconfig')[server_name].setup {
 | 
			
		||||
      capabilities = capabilities,
 | 
			
		||||
      on_attach = on_attach,
 | 
			
		||||
    }
 | 
			
		||||
end
 | 
			
		||||
  end,
 | 
			
		||||
  ['sumneko_lua'] = function()
 | 
			
		||||
    -- Example custom configuration for lua
 | 
			
		||||
    --
 | 
			
		||||
    -- Make runtime files discoverable to the server
 | 
			
		||||
    local runtime_path = vim.split(package.path, ';')
 | 
			
		||||
    table.insert(runtime_path, 'lua/?.lua')
 | 
			
		||||
    table.insert(runtime_path, 'lua/?/init.lua')
 | 
			
		||||
 | 
			
		||||
-- Turn on lsp status information
 | 
			
		||||
require('fidget').setup()
 | 
			
		||||
 | 
			
		||||
-- Example custom configuration for lua
 | 
			
		||||
--
 | 
			
		||||
-- Make runtime files discoverable to the server
 | 
			
		||||
local runtime_path = vim.split(package.path, ';')
 | 
			
		||||
table.insert(runtime_path, 'lua/?.lua')
 | 
			
		||||
table.insert(runtime_path, 'lua/?/init.lua')
 | 
			
		||||
 | 
			
		||||
require('lspconfig').sumneko_lua.setup {
 | 
			
		||||
    require('lspconfig').sumneko_lua.setup {
 | 
			
		||||
      on_attach = on_attach,
 | 
			
		||||
      capabilities = capabilities,
 | 
			
		||||
      settings = {
 | 
			
		||||
| 
						 | 
				
			
			@ -387,8 +385,13 @@ require('lspconfig').sumneko_lua.setup {
 | 
			
		|||
          telemetry = { enable = false },
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  end,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- Turn on lsp status information
 | 
			
		||||
require('fidget').setup()
 | 
			
		||||
 | 
			
		||||
-- nvim-cmp setup
 | 
			
		||||
local cmp = require 'cmp'
 | 
			
		||||
local luasnip = require 'luasnip'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue