@@ -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' })
333332end
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
348358local capabilities = vim .lsp .protocol .make_client_capabilities ()
349359capabilities = 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
393385local cmp = require ' cmp'
394386local luasnip = require ' luasnip'
0 commit comments