diff --git a/init.lua b/init.lua index 106f994..617d4ef 100644 --- a/init.lua +++ b/init.lua @@ -562,43 +562,86 @@ require('lazy').setup({ -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ - local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs - -- - -- Some languages (like typescript) have entire language plugins that can be useful: - -- https://github.com/pmizio/typescript-tools.nvim - -- - -- But for many setups, the LSP (`tsserver`) will work just fine - -- tsserver = {}, - -- + local lspconfig = require 'lspconfig' - lua_ls = { - -- cmd = {...}, - -- filetypes = { ...}, - -- capabilities = {}, - settings = { - Lua = { - completion = { - callSnippet = 'Replace', - }, - -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, + lspconfig.clangd.setup { + capabilities = capabilities, + } + lspconfig.gopls.setup { + capabilities = capabilities, + } + lspconfig.pylsp.setup { + capabilities = capabilities, + } + + local on_attach = function(client, bufnr) + -- require'completion'.on_attach(client) + vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) + end + + lspconfig.rust_analyzer.setup { + capabilities = capabilities, + on_attach = on_attach, + ['rust-analyzer'] = { + diagnostics = { + enable = true, + }, + imports = { + granularity = { + group = 'module', }, + prefix = 'self', + }, + cargo = { + buildScripts = { + enable = true, + }, + }, + procMacro = { + enable = true, }, }, } - - -- Ensure the servers and tools above are installed - -- To check the current status of installed tools and/or manually install - -- other tools, you can run - -- :Mason + -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- - -- You can press `g?` for help in this menu. - require('mason').setup() + -- Some languages (like typescript) have entire language plugins that can be useful: + -- https://github.com/pmizio/typescript-tools.nvim + -- + -- But for many setups, the LSP (`tsserver`) will work just fine + -- tsserver = {}, + -- + + lspconfig.lua_ls.setup { + -- cmd = {...}, + -- filetypes = { ...}, + -- capabilities = {}, + capabilities = capabilities, + settings = { + Lua = { + completion = { + callSnippet = 'Replace', + }, + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file('', true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + -- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings + -- diagnostics = { disable = { 'missing-fields' } }, + }, + }, + } -- You can add other tools here that you want Mason to install -- for you, so that they are available from within Neovim. @@ -606,20 +649,6 @@ require('lazy').setup({ vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code }) - require('mason-tool-installer').setup { ensure_installed = ensure_installed } - - require('mason-lspconfig').setup { - handlers = { - function(server_name) - local server = servers[server_name] or {} - -- This handles overriding only values explicitly passed - -- by the server configuration above. Useful when disabling - -- certain features of an LSP (for example, turning off formatting for tsserver) - server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {}) - require('lspconfig')[server_name].setup(server) - end, - }, - } end, },