my-lspconfig.lua (4324B)
1 require "mason".setup() 2 require "mason-lspconfig".setup { 3 ensure_installed = { "lua_ls" }, 4 automatic_installation = true 5 } 6 7 local lspconfig = require "lspconfig" 8 9 local function on_attach(client, bufnr) 10 local function set_keymap(lhs, func, desc) 11 -- vim.api.nvim_echo({ {"Setup "}, {lhs} }, true, {}) 12 vim.keymap.set("n", lhs, "", { 13 remap = false, 14 silent = true, 15 buffer = bufnr, 16 callback = func, 17 desc = desc 18 }) 19 end 20 21 local function set_autocmd(event, func) 22 vim.api.nvim_create_autocmd(event, { 23 buffer = bufnr, 24 callback = function() pcall(func) end, 25 }) 26 end 27 28 -- Mappings. 29 -- See `:help vim.lsp.*` for documentation on any of the below functions 30 if client.server_capabilities and client.server_capabilities.hoverProvider then 31 set_keymap('K', vim.lsp.buf.hover, "Hover / print docs") 32 end 33 set_keymap('<Leader>d', vim.lsp.buf.definition, "Go to definition") 34 set_keymap('<Leader>gd', vim.lsp.buf.declaration, "Go to declaration") 35 set_keymap('<Leader>td', vim.lsp.buf.type_definition, "Go to type definition") 36 set_keymap('gr', vim.lsp.buf.rename, "Rename symbol at point") 37 set_keymap('<Leader>a', vim.lsp.buf.code_action, "Code action at point") 38 set_keymap('<Leader>=', vim.lsp.buf.format, "Format the whole buffer") 39 set_keymap('gR', require "azy.builtins".lsp.references(), "Search for references") 40 set_keymap('<Leader>s', require "azy.builtins".lsp.workspace_symbols(), "Search workspace symbols") 41 42 vim.opt_local.tagfunc = "v:lua.vim.lsp.tagfunc" 43 44 set_keymap('<Leader>e', require "azy.builtins".files(vim.tbl_filter(function(p) 45 return #p > 0 and p ~= vim.fn.expand("$HOME") 46 end, vim.lsp.buf.list_workspace_folders()))) 47 48 if client.supports_method('textDocument/documentHighlight') then 49 set_autocmd("CursorHold", vim.lsp.buf.document_highlight) 50 set_autocmd("CursorMoved", vim.lsp.buf.clear_references) 51 end 52 53 -- if client.supports_method('textDocument/codeLens') then 54 -- set_autocmd({ "BufEnter", "CursorHoldI", "InsertLeave" }, vim.lsp.codelens.refresh) 55 -- set_keymap('<Leader>lr', vim.lsp.codelens.run, "Run codelens") 56 -- end 57 58 -- if client.supports_method 'textDocument/inlayHint' then 59 -- vim.lsp.inlay_hint(bufnr, true) 60 -- end 61 end 62 63 vim.api.nvim_create_autocmd("LspAttach", { 64 callback = function(args) 65 local bufnr = args.buf 66 local client = vim.lsp.get_client_by_id(args.data.client_id) 67 on_attach(client, bufnr) 68 end, 69 }) 70 71 -- SERVERS 72 73 lspconfig.lua_ls.setup { 74 settings = { 75 Lua = { 76 runtime = { 77 -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) 78 version = 'LuaJIT', 79 -- Setup your lua path 80 path = vim.split(package.path, ';'), 81 }, 82 hint = { 83 enable = true 84 }, 85 diagnostics = { 86 -- Get the language server to recognize the `vim` global 87 globals = { 'vim' }, 88 89 workspaceDelay = -1, 90 91 groupFileStatus = { 92 strict = "Opened", 93 strong = "Opened", 94 }, 95 96 groupSeverity = { 97 strong = "Warning", 98 strict = "Warning", 99 }, 100 }, 101 workspace = { 102 -- Make the server aware of Neovim runtime files 103 library = vim.api.nvim_get_runtime_file('', true), 104 checkThirdParty = false, 105 }, 106 -- Do not send telemetry data containing a randomized but unique identifier 107 telemetry = { 108 enable = false, 109 }, 110 completion = { 111 callSnippet = "Replace", 112 } 113 }, 114 }, 115 } 116 117 lspconfig.texlab.setup { 118 settings = { 119 texlab = { 120 build = { 121 onSave = true, 122 forwardSearchAfter = true, 123 args = { "-interaction=nonstopmode", "-f", "-synctex=1", "-shell-escape", "-xelatex", "%f" } 124 }, 125 forwardSearch = { 126 executable = "zathura", 127 args = { "-x", 128 -- First level of escaping is for string.format, second level for escaping is for texlab 129 string.format("nvim --server %s --remote-send '<cmd>edit +%%%%{line} %%%%{input}<cr>'", 130 vim.fn.serverlist()[1]), 131 "--synctex-forward", "%l:1:%f", "%p" } 132 }, 133 } 134 }, 135 } 136 137 lspconfig.pylsp.setup { 138 139 } 140 141 require'lean'.setup { 142 mappings = true, 143 lsp = { 144 init_options = { 145 editDelay = 1000, 146 } 147 } 148 }