local lsp = vim.lsp local api = vim.api local cmd = vim.cmd local lsp_installer = require('nvim-lsp-installer') -- Include the servers you want to have installed by default below local servers = { 'bashls', 'pylsp', 'yamlls', 'eslint', 'jsonls', 'sumneko_lua', 'rust_analyzer', 'clangd', 'gopls', 'tsserver', 'prosemd_lsp', } for _, name in pairs(servers) do local server_is_found, server = lsp_installer.get_server(name) if server_is_found and not server:is_installed() then print('Installing ' .. name) server:install() end end -- lspconfig && lspinstaller local on_attach = function(client, bufnr) local function buf_set_keymap(...) api.nvim_buf_set_keymap(bufnr, ...) end local function buf_set_option(...) api.nvim_buf_set_option(bufnr, ...) end --require "lsp_signature".on_attach() -- Enable completion triggered by --buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. local opts = { noremap = true, silent = true } -- See `:help vim.lsp.*` for documentation on any of the below functions buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'gr', 'Telescope lsp_references', opts) buf_set_keymap('n', 'gd', 'Telescope lsp_definitions', opts) buf_set_keymap('n', 'go', 'Telescope lsp_document_symbols', opts) buf_set_keymap('n', 'gO', 'Telescope lsp_workspace_symbols', opts) --buf_set_keymap("n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) --buf_set_keymap('i', 'f', 'lua vim.lsp.buf.formatting()', opts) if client.resolved_capabilities.document_formatting then vim.cmd([[ augroup Format au! * au BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000) augroup END ]]) end end local capabilities = lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) -- Register a handler that will be called for all installed servers. -- Alternatively, you may also register handlers on specific server instances instead (see example below). lsp_installer.on_server_ready(function(server) local opts = { on_attach = on_attach, capabilities = capabilities, flags = { debounce_text_changes = 150, }, } if server.name == 'sumneko_lua' then local luadev = require('lua-dev').setup({ lspconfig = { settings = { Lua = { workspace = { checkThirdParty = false, }, }, }, }, }) opts = vim.tbl_deep_extend('force', opts, luadev) end if server.name == 'yamlls' then --local yamlls_opts = { --settings = { --yaml = { --filetypes = { 'yaml', 'yml' }, --schemaStore = { --enable = true, --url = 'https://www.schemastore.org/api/json/catalog.json', --}, --validate = false, --schemas = { --['https://json.schemastore.org/github-workflow.json'] = '/.github/workflows/*', --kubernetes = '/*.k8s.yaml', --}, --}, --}, --} local conf = require(string.format('config.lsp_servers.%s', server.name)) opts = vim.tbl_deep_extend('force', opts, conf) end if server.name == 'rust_analyzer' then -- Initialize the LSP via rust-tools instead require('rust-tools').setup({ -- The "server" property provided in rust-tools setup function are the -- settings rust-tools will provide to lspconfig during init. -- -- We merge the necessary settings from nvim-lsp-installer (server:get_default_options()) -- with the user's own settings (opts). server = vim.tbl_deep_extend('force', server:get_default_options(), opts), }) server:attach_buffers() -- Only if standalone support is needed --require('rust-tools').start_standalone_if_required() else -- (optional) Customize the options passed to the server -- if server.name == "tsserver" then -- opts.root_dir = function() ... end -- end -- This setup() function is exactly the same as lspconfig's setup function. -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md server:setup(opts) end end) local null_ls = require('null-ls') null_ls.setup({ sources = { null_ls.builtins.formatting.stylua.with({ extra_args = { '--config-path', vim.fn.expand('~/.config/stylua.toml') }, }), null_ls.builtins.formatting.shfmt, }, on_attach = on_attach, })