feat: More user friendly language server installation
This commit is contained in:
		
							parent
							
								
									6dccf03fd2
								
							
						
					
					
						commit
						b4173c7a4e
					
				
							
								
								
									
										97
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										97
									
								
								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,60 +335,63 @@ 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,
 | 
			
		||||
    capabilities = capabilities,
 | 
			
		||||
  }
 | 
			
		||||
end
 | 
			
		||||
-- 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,
 | 
			
		||||
  ['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')
 | 
			
		||||
 | 
			
		||||
    require('lspconfig').sumneko_lua.setup {
 | 
			
		||||
      on_attach = on_attach,
 | 
			
		||||
      capabilities = capabilities,
 | 
			
		||||
      settings = {
 | 
			
		||||
        Lua = {
 | 
			
		||||
          runtime = {
 | 
			
		||||
            -- Tell the language server which version of Lua you're using (most likely LuaJIT)
 | 
			
		||||
            version = 'LuaJIT',
 | 
			
		||||
            -- Setup your lua path
 | 
			
		||||
            path = runtime_path,
 | 
			
		||||
          },
 | 
			
		||||
          diagnostics = {
 | 
			
		||||
            globals = { 'vim' },
 | 
			
		||||
          },
 | 
			
		||||
          workspace = {
 | 
			
		||||
            library = vim.api.nvim_get_runtime_file('', true),
 | 
			
		||||
            checkThirdParty = false,
 | 
			
		||||
          },
 | 
			
		||||
          -- Do not send telemetry data containing a randomized but unique identifier
 | 
			
		||||
          telemetry = { enable = false },
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  end,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- 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 {
 | 
			
		||||
  on_attach = on_attach,
 | 
			
		||||
  capabilities = capabilities,
 | 
			
		||||
  settings = {
 | 
			
		||||
    Lua = {
 | 
			
		||||
      runtime = {
 | 
			
		||||
        -- Tell the language server which version of Lua you're using (most likely LuaJIT)
 | 
			
		||||
        version = 'LuaJIT',
 | 
			
		||||
        -- Setup your lua path
 | 
			
		||||
        path = runtime_path,
 | 
			
		||||
      },
 | 
			
		||||
      diagnostics = {
 | 
			
		||||
        globals = { 'vim' },
 | 
			
		||||
      },
 | 
			
		||||
      workspace = {
 | 
			
		||||
        library = vim.api.nvim_get_runtime_file('', true),
 | 
			
		||||
        checkThirdParty = false,
 | 
			
		||||
      },
 | 
			
		||||
      -- Do not send telemetry data containing a randomized but unique identifier
 | 
			
		||||
      telemetry = { enable = false },
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- nvim-cmp setup
 | 
			
		||||
local cmp = require 'cmp'
 | 
			
		||||
local luasnip = require 'luasnip'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue