local nvim_lsp = require('lspconfig') local configs = require('lspconfig.configs') -- harepls if not configs.harepls then configs.harepls = { default_config = { cmd = { '/home/leo/code/hare/harepls/harepls' }; filetypes = { 'hare' }; root_dir = function(fname) return nvim_lsp.util.find_git_ancestor(fname) end; settings = {}; }; } end -- nvim_lsp.harepls.setup {} -- keybindings local on_attach = function(client, bufrn) Mapper = require("nvim-mapper") local function buf_set_keymap(...) Mapper.map_buf(bufrn, ...) end local function buf_set_option(...) vim.api.nvim_buf_set_option(bufrn, ...) end 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, "LSP", "declaration", "Go to declaration") buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts, "LSP", "definition", "Go to definition") buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts, "LSP", "hover", "Hover") buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts, "LSP", "implementation", "Go to implementation") buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts, "LSP", "signature_help", "Show signature help") buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts, "LSP", "add_workspace_folder", "Add workspace folder") buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts, "LSP", "remove_workspace_folder", "Remove workspace folder") buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts, "LSP" , "list_workspace_folders", "List workspace folder") buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts, "LSP", "type_definition", "Show type definition") buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts, "LSP", "rename", "Rename") buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts, "LSP", "code_action", "Show code actions") buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts, "LSP", "references", "Show references") buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts, "LSP", "show_line_diagnostics", "Show line diagnostic") buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts, "LSP", "goto_prev", "Go to previous") buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts, "LSP", "goto_next", "Go to next") buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts, "LSP", "set_loclist", "Set loclist") buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts, "LSP", "formatting", "Format") end -- Launch language servers local servers = { 'harepls', 'pyright', 'pylsp', 'gopls', 'rust_analyzer', 'tsserver', 'elixirls', 'dartls', 'denols', 'clangd', 'zls', } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, flags = { debounce_text_changes = 150, } } end local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true require 'lspconfig'.jsonls.setup { cmd = { "vscode-json-languageserver", "--stdio" }, capabilities = capabilities, commands = { Format = { function() vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 }) end }, }, } 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 { settings = { Lua = { runtime = { -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) version = 'LuaJIT', -- Setup your lua path path = runtime_path, }, 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, }, }, }, } -- lsp_lines require('lsp_lines').setup() vim.diagnostic.config({ virtual_text = false, }) vim.keymap.set( "", "l", require("lsp_lines").toggle, { desc = "Toggle lsp_lines" } ) -- Format on save vim.cmd [[autocmd BufWritePre lua vim.lsp.buf.formatting_sync()]]