From 07c684b283487e481cc134d9322ffaedb000e3db Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 19 Dec 2022 21:17:38 -0500 Subject: [PATCH] move server config to easy to extend style --- init.lua | 70 ++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/init.lua b/init.lua index fb7c097..ed0690d 100644 --- a/init.lua +++ b/init.lua @@ -332,63 +332,57 @@ local on_attach = function(_, bufnr) end, { desc = 'Format current buffer with LSP' }) end +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, 'lua/?.lua') +table.insert(runtime_path, 'lua/?/init.lua') + +-- Enable the following language servers +-- Feel free to add/remove any LSPs that you want here. They will automatically be installed. +-- Add any additional override configuration in the following tables. They will be passed to +-- the `settings` field of the server config +local servers = { + clangd = {}, + gopls = {}, + pyright = {}, + rust_analyzer = {}, + tsserver = {}, + + sumneko_lua = { + Lua = { + runtime = { version = 'LuaJIT', path = runtime_path }, + diagnostics = { globals = { 'vim' } }, + workspace = { + library = vim.api.nvim_get_runtime_file('', true), + checkThirdParty = false, + }, + telemetry = { enable = false }, + }, + }, +} + -- 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, + ensure_installed = vim.tbl_keys(servers), } --- nvim-cmp supports additional completion capabilities +-- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) -for _, lsp in ipairs(servers) do +for lsp, settings in ipairs(servers) do require('lspconfig')[lsp].setup { on_attach = on_attach, capabilities = capabilities, + settings = settings, } 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'