Skip to content

Commit 5219406

Browse files
authored
move server config to easy to extend style (nvim-lua#71)
Move servers to new configuration style. I will probably cover this in a new shorter video, or maybe in combination with something else. This should hopefully remove getting so many people making issues about LSPs that they don't want to. I can update documentation if what is happening is not clear.
1 parent aa660e6 commit 5219406

File tree

3 files changed

+48
-54
lines changed

3 files changed

+48
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ tags
22
test.sh
33
.luarc.json
44
nvim
5+
plugin/packer_compiled.lua

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A starting point for Neovim that is:
99

1010
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.
1111

12-
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).
12+
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.
1313

1414
### Installation
1515

@@ -65,5 +65,6 @@ Each PR, especially those which increase the line count, should have a descripti
6565
### FAQ
6666

6767
* What should I do if I already have a pre-existing neovim configuration?
68-
* 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/`
68+
* You should back it up, then delete all files associated with it.
69+
* This includes your existing init.lua and the neovim files in `.local` which can be deleted with `rm -rf ~/.local/share/nvim/`
6970

init.lua

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ require('packer').startup(function(use)
2020

2121
-- Useful status updates for LSP
2222
'j-hui/fidget.nvim',
23+
24+
-- Additional lua configuration, makes nvim stuff amazing
25+
'folke/neodev.nvim',
2326
},
2427
}
2528

@@ -324,71 +327,60 @@ local on_attach = function(_, bufnr)
324327

325328
-- Create a command `:Format` local to the LSP buffer
326329
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
327-
if vim.lsp.buf.format then
328-
vim.lsp.buf.format()
329-
elseif vim.lsp.buf.formatting then
330-
vim.lsp.buf.formatting()
331-
end
330+
vim.lsp.buf.format()
332331
end, { desc = 'Format current buffer with LSP' })
333332
end
334333

335-
-- Setup mason so it can manage external tooling
336-
require('mason').setup()
337-
338334
-- Enable the following language servers
339-
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed
340-
local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'sumneko_lua', 'gopls' }
341-
342-
-- Ensure the servers above are installed
343-
require('mason-lspconfig').setup {
344-
ensure_installed = servers,
335+
-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
336+
--
337+
-- Add any additional override configuration in the following tables. They will be passed to
338+
-- the `settings` field of the server config. You must look up that documentation yourself.
339+
local servers = {
340+
-- clangd = {},
341+
-- gopls = {},
342+
-- pyright = {},
343+
-- rust_analyzer = {},
344+
-- tsserver = {},
345+
346+
sumneko_lua = {
347+
Lua = {
348+
workspace = { checkThirdParty = false },
349+
telemetry = { enable = false },
350+
},
351+
},
345352
}
346353

347-
-- nvim-cmp supports additional completion capabilities
354+
-- Setup neovim lua configuration
355+
require('neodev').setup()
356+
--
357+
-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
348358
local capabilities = vim.lsp.protocol.make_client_capabilities()
349359
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
350360

351-
for _, lsp in ipairs(servers) do
352-
require('lspconfig')[lsp].setup {
353-
on_attach = on_attach,
354-
capabilities = capabilities,
355-
}
356-
end
361+
-- Setup mason so it can manage external tooling
362+
require('mason').setup()
357363

358-
-- Turn on lsp status information
359-
require('fidget').setup()
364+
-- Ensure the servers above are installed
365+
local mason_lspconfig = require 'mason-lspconfig'
360366

361-
-- Example custom configuration for lua
362-
--
363-
-- Make runtime files discoverable to the server
364-
local runtime_path = vim.split(package.path, ';')
365-
table.insert(runtime_path, 'lua/?.lua')
366-
table.insert(runtime_path, 'lua/?/init.lua')
367-
368-
require('lspconfig').sumneko_lua.setup {
369-
on_attach = on_attach,
370-
capabilities = capabilities,
371-
settings = {
372-
Lua = {
373-
runtime = {
374-
-- Tell the language server which version of Lua you're using (most likely LuaJIT)
375-
version = 'LuaJIT',
376-
-- Setup your lua path
377-
path = runtime_path,
378-
},
379-
diagnostics = {
380-
globals = { 'vim' },
381-
},
382-
workspace = {
383-
library = vim.api.nvim_get_runtime_file('', true),
384-
checkThirdParty = false,
385-
},
386-
-- Do not send telemetry data containing a randomized but unique identifier
387-
telemetry = { enable = false },
388-
},
389-
},
367+
mason_lspconfig.setup {
368+
ensure_installed = vim.tbl_keys(servers),
369+
}
370+
371+
mason_lspconfig.setup_handlers {
372+
function(server_name)
373+
require('lspconfig')[server_name].setup {
374+
capabilities = capabilities,
375+
on_attach = on_attach,
376+
settings = servers[server_name],
377+
}
378+
end,
390379
}
391380

381+
-- Turn on lsp status information
382+
require('fidget').setup()
383+
392384
-- nvim-cmp setup
393385
local cmp = require 'cmp'
394386
local luasnip = require 'luasnip'

0 commit comments

Comments
 (0)