"== highlight the occurrance of the word at cursor hi LspReferenceText ctermbg=gray guibg=gray hi LspReferenceRead ctermbg=lightblue guibg=lightblue hi LspReferenceWrite ctermbg=lightgreen guibg=lightgreen "autocmd CursorHold * lua vim.lsp.buf.document_highlight() "autocmd CursorMoved * lua vim.lsp.buf.clear_references() lua << EOF local nvim_lsp = require('lspconfig') local navic = require("nvim-navic") navic.setup { icons = { File = "󰈙 ", Module = " ", Namespace = "󰌗 ", Package = " ", Class = "󰌗 ", Method = "󰆧 ", Property = " ", Field = " ", Constructor = " ", Enum = "󰕘", Interface = "󰕘", Function = "󰊕 ", Variable = "󰆧 ", Constant = "󰏿 ", String = "󰀬 ", Number = "󰎠 ", Boolean = "◩ ", Array = "󰅪 ", Object = "󰅩 ", Key = "󰌋 ", Null = "󰟢 ", EnumMember = " ", Struct = "󰌗 ", Event = " ", Operator = "󰆕 ", TypeParameter = "󰊄 ", }, lsp = { auto_attach = false, preference = nil, }, highlight = false, separator = " > ", depth_limit = 0, depth_limit_indicator = "..", safe_output = true, lazy_update_context = false, click = false, format_text = function(text) return text end, } local working_dir = vim.fn.getcwd() -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) 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 -- 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', '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', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', 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) if client.server_capabilities.documentSymbolProvider then navic.attach(client, bufnr) end end require'lspconfig'.clangd.setup{ cmd = {"/usr/bin/clangd-17", "--background-index", "--compile-commands-dir="..working_dir, "--enable-config", "--header-insertion=never", "--offset-encoding=utf-16"}, on_attach = on_attach, flags = { debounce_text_changes = 150, } } -- lsp for bash -- npm i -g bash-language-server require'lspconfig'.bashls.setup{} -- lsp for python -- pip install pyright require'lspconfig'.pyright.setup{} require'lspconfig'.rust_analyzer.setup{ on_attach=on_attach, settings = { ["rust-analyzer"] = { imports = { granularity = { group = "module", }, prefix = "self", }, cargo = { buildScripts = { enable = true, }, }, procMacro = { enable = true }, } } } EOF