USER = vim.fn.expand('$USER') -- Language specific key mappings --require('lang.keymappings') local on_attach = function(client, bufnr) require'lsp_signature'.on_attach(client) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') -- Mappings. local opts = {noremap = true, silent = true} 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', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) buf_set_keymap('n', '[l', 'lua vim.diagnostic.show_line_diagnostics()', opts) buf_set_keymap('n', ']l', 'lua vim.diagnostic.set_loclist()', opts) buf_set_keymap('n', 'law', 'lua vim.lsp.buf.add_workspace_folder()', opts) buf_set_keymap('n', 'lrw', 'lua vim.lsp.buf.remove_workspace_folder()', opts) buf_set_keymap('n', 'llw', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) buf_set_keymap('n', 'lt', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'lrn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'lca', 'lua vim.lsp.buf.code_action()', opts) -- Set some keybinds conditional on server capabilities if client.server_capabilities.document_formatting then buf_set_keymap("n", "lf", "lua vim.lsp.buf.formatting()", opts) elseif client.server_capabilities.document_range_formatting then buf_set_keymap("n", "lf", "lua vim.lsp.buf.range_formatting()", opts) end client.server_capabilities.semanticTokensProvider = nil -- Set autocommands conditional on server_capabilities if client.server_capabilities.document_highlight then vim.api.nvim_exec([[ hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow augroup lsp_document_highlight autocmd! * autocmd CursorHold lua vim.lsp.buf.document_highlight() autocmd CursorMoved lua vim.lsp.buf.clear_references() augroup END ]], false) end end require('nvim-treesitter.configs').setup { ensure_installed = { "lua", "rust", "elm", "python", "toml" }, auto_install = true, highlight = { enable = true, additional_vim_regex_highlighting=false, }, ident = { enable = true, }, rainbow = { enable = true, extended_mode = false, max_file_lines = nil, } } vim.api.nvim_set_hl(0, "@variable", { }) vim.api.nvim_set_hl(0, "@parameter", { }) local nvim_lsp = require('lspconfig') local capabilities = vim.lsp.protocol.make_client_capabilities() -- Code actions capabilities.textDocument.codeAction = { dynamicRegistration = true, codeActionLiteralSupport = { codeActionKind = { valueSet = (function() local res = vim.tbl_values(vim.lsp.protocol.CodeActionKind) table.sort(res) return res end)() } } } capabilities.textDocument.completion.completionItem.snippetSupport = true; -- LSPs local servers = {"vimls", "ocamllsp",} for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup {capabilities = capabilities, on_attach = on_attach} end nvim_lsp.pyright.setup({ on_attach = on_attach, }) nvim_lsp.ruff_lsp.setup({ on_attach = on_attach, capabilities = capabilities, init_options = { settings = { -- Any extra CLI arguments for `ruff` go here. args = {}, } } }) nvim_lsp.rust_analyzer.setup({ on_attach = on_attach, capabilities = capabilities, settings = { ["rust-analyzer"] = { imports = { granularity = { group = "module", }, prefix = "self", }, cargo = { buildScripts = { enable = true, }, }, procMacro = { enable = true }, } } }) -- symbols-outline.nvim vim.g.symbols_outline = { highlight_hovered_item = true, show_guides = true, auto_preview = false, -- experimental position = 'right', keymaps = { close = "", goto_location = "", focus_location = "o", hover_symbol = "", rename_symbol = "r", code_actions = "a" }, lsp_blacklist = {} } -- LSP Enable diagnostics vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = false, underline = true, signs = true, update_in_insert = false }) -- Send diagnostics to quickfix list do local method = "textDocument/publishDiagnostics" local default_handler = vim.lsp.handlers[method] vim.lsp.handlers[method] = function(err, method, result, client_id, bufnr, config) default_handler(err, method, result, client_id, bufnr, config) local diagnostics = vim.diagnostic.get() local qflist = {} for bufnr, diagnostic in pairs(diagnostics) do for _, d in ipairs(diagnostic) do d.bufnr = bufnr d.lnum = d.range.start.line + 1 d.col = d.range.start.character + 1 d.text = d.message table.insert(qflist, d) end end -- setqflist(qflist) end end