From 07c684b283487e481cc134d9322ffaedb000e3db Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 19 Dec 2022 21:17:38 -0500 Subject: [PATCH 1/4] 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 fb7c0972..ed0690d7 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' From 01e80d152ec0d1eac537b86a29912e1f086f0af3 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 20 Dec 2022 13:49:14 -0500 Subject: [PATCH 2/4] fixup: add neodev and disable a bunch of servers by default --- .gitignore | 1 + init.lua | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d699e1d6..1b83131b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ tags test.sh .luarc.json nvim +plugin/packer_compiled.lua diff --git a/init.lua b/init.lua index ed0690d7..7627e356 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,9 @@ require('packer').startup(function(use) -- Useful status updates for LSP 'j-hui/fidget.nvim', + + -- Additional lua configuration, makes nvim stuff amazing + 'folke/neodev.nvim', }, } @@ -341,11 +344,11 @@ table.insert(runtime_path, 'lua/?/init.lua') -- 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 = {}, + -- clangd = {}, + -- gopls = {}, + -- pyright = {}, + -- rust_analyzer = {}, + -- tsserver = {}, sumneko_lua = { Lua = { @@ -360,6 +363,9 @@ local servers = { }, } +-- Setup neovim lua configuration +require('neodev').setup() + -- Setup mason so it can manage external tooling require('mason').setup() From 81aaccd4ae5f980c9b00349c865ec25e6f1e5546 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 20 Dec 2022 15:19:43 -0500 Subject: [PATCH 3/4] new setup --- init.lua | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/init.lua b/init.lua index 7627e356..18780e38 100644 --- a/init.lua +++ b/init.lua @@ -365,26 +365,30 @@ local servers = { -- Setup neovim lua configuration require('neodev').setup() +-- +-- 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) -- Setup mason so it can manage external tooling require('mason').setup() -- Ensure the servers above are installed -require('mason-lspconfig').setup { +local mason_lspconfig = require('mason-lspconfig') + +mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers), } --- 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, settings in ipairs(servers) do - require('lspconfig')[lsp].setup { - on_attach = on_attach, - capabilities = capabilities, - settings = settings, - } -end +mason_lspconfig.setup_handlers { + function(server_name) + require('lspconfig')[server_name].setup { + capabilities = capabilities, + on_attach = on_attach, + settings = servers[server_name], + } + end, +} -- Turn on lsp status information require('fidget').setup() From 40fbcf82536c6f858fa5d44ef992fbfb28bc1538 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 20 Dec 2022 22:11:10 -0500 Subject: [PATCH 4/4] wip --- README.md | 5 +++-- init.lua | 22 +++++----------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f7a6b764..b4240858 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ A starting point for Neovim that is: Kickstart.nvim targets *only* the latest ['stable'](https://github.com/neovim/neovim/releases/tag/stable) and latest ['nightly'](https://github.com/neovim/neovim/releases/tag/nightly) of Neovim. If you are experiencing issues, please make sure you have the latest versions. -This repo is meant to be used as a starting point for a user's own configuration; remove the things you don't use and add what you miss. This configuration serves as the reference configuration for the [lspconfig wiki](https://github.com/neovim/nvim-lspconfig/wiki). +This repo is meant to be used as a starting point for a user's own configuration; remove the things you don't use and add what you miss. Please refrain from leaving comments about enabling / disabling particular languages out of the box. ### Installation @@ -65,5 +65,6 @@ Each PR, especially those which increase the line count, should have a descripti ### FAQ * What should I do if I already have a pre-existing neovim configuration? - * You should back it up, then delete all files associated with it. This includes your existing init.lua and the neovim files in .local which can be deleted with `rm -rf ~/.local/share/nvim/` + * You should back it up, then delete all files associated with it. + * This includes your existing init.lua and the neovim files in `.local` which can be deleted with `rm -rf ~/.local/share/nvim/` diff --git a/init.lua b/init.lua index 18780e38..636d86af 100644 --- a/init.lua +++ b/init.lua @@ -327,22 +327,15 @@ local on_attach = function(_, bufnr) -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - if vim.lsp.buf.format then - vim.lsp.buf.format() - elseif vim.lsp.buf.formatting then - vim.lsp.buf.formatting() - end + vim.lsp.buf.format() 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 +-- the `settings` field of the server config. You must look up that documentation yourself. local servers = { -- clangd = {}, -- gopls = {}, @@ -352,12 +345,7 @@ local servers = { sumneko_lua = { Lua = { - runtime = { version = 'LuaJIT', path = runtime_path }, - diagnostics = { globals = { 'vim' } }, - workspace = { - library = vim.api.nvim_get_runtime_file('', true), - checkThirdParty = false, - }, + workspace = { checkThirdParty = false }, telemetry = { enable = false }, }, }, @@ -374,7 +362,7 @@ capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) require('mason').setup() -- Ensure the servers above are installed -local mason_lspconfig = require('mason-lspconfig') +local mason_lspconfig = require 'mason-lspconfig' mason_lspconfig.setup { ensure_installed = vim.tbl_keys(servers),