local Remap = require("halfdan.keymap") local nnoremap = Remap.nnoremap local inoremap = Remap.inoremap vim.fn.sign_define("DiagnosticSignError", {text = "", texthl = "DiagnosticSignError"}) vim.fn.sign_define("DiagnosticSignWarn", {text = "", texthl = "DiagnosticSignWarn"}) vim.fn.sign_define("DiagnosticSignInfo", {text = "", texthl = "DiagnosticSignInfo"}) -- vim.fn.sign_define("DiagnosticSignHint", {text = "", texthl = "DiagnosticSignHint"}) -- Set Default Prefix. -- Note: You can set a prefix per lsp server in the lv-globals.lua file vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( vim.lsp.diagnostic.on_publish_diagnostics, { signs = true, underline = true, } ) -- Setup for nvim-notify vim.lsp.set_log_level(2) local convert_lsp_log_level_to_neovim_log_level = function(lsp_log_level) if lsp_log_level == 1 then return 4 elseif lsp_log_level == 2 then return 3 elseif lsp_log_level == 3 then return 2 elseif lsp_log_level == 4 then return 1 end end local levels = { "ERROR", "WARN", "INFO", "DEBUG", [0] = "TRACE", } ---@diagnostic disable-next-line: unused-vararg vim.lsp.handlers["window/showMessage"] = function(_, result, ...) if require("vim.lsp.log").should_log(convert_lsp_log_level_to_neovim_log_level(result.type)) then vim.notify(result.message, levels[result.type]) end end -- symbols for autocomplete vim.lsp.protocol.CompletionItemKind = { "  (Text) ", "  (Method)", "  (Function)", "  (Constructor)", " ﴲ (Field)", "[] (Variable)", "  (Class)", " ﰮ (Interface)", "  (Module)", " 襁 (Property)", "  (Unit)", "  (Value)", " 練 (Enum)", "  (Keyword)", "  (Snippet)", "  (Color)", "  (File)", "  (Reference)", "  (Folder)", "  (EnumMember)", " ﲀ (Constant)", " ﳤ (Struct)", "  (Event)", "  (Operator)", "  (TypeParameter)" } -- Diagnostic keymaps vim.api.nvim_set_keymap('n', 'e', 'Lspsaga show_line_diagnostics', { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', { noremap = true, silent = true }) -- LSP settings local lsp_status = require('lsp-status') lsp_status.register_progress() local lspconfig = require 'lspconfig' local on_attach = function(client, bufnr) nnoremap("gd", "Lspsaga peek_definition") nnoremap("gd", function () vim.lsp.buf.definition() end) nnoremap("gD", function() vim.lsp.buf.declaration() end) nnoremap("K", "Lspsaga hover_doc") nnoremap("gW", function() vim.lsp.buf.workspace_symbol() end) nnoremap("vd", function() vim.diagnostic.open_float() end) nnoremap("[d", "Lspsaga diagnostic_jump_next") nnoremap("]d", "Lspsaga diagnostic_jump_prev") nnoremap("ca", "Lspsaga code_action") nnoremap("gr", function() vim.lsp.buf.references() end) nnoremap("rn", "Lspsaga rename") nnoremap("cl", function() vim.lsp.codelens.run() end) nnoremap("fa", function() vim.lsp.buf.format{async = true} end) inoremap("", function() vim.lsp.buf.signature_help() end) lsp_status.on_attach(client, bufnr) end local function config(_config) _config = vim.tbl_deep_extend("force", { log_level = vim.lsp.protocol.MessageType.Log, message_level = vim.lsp.protocol.MessageType.Log, capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()), on_attach = on_attach, }, _config or {}) -- Set default client capabilities plus window/workDoneProgress _config.capabilities = vim.tbl_extend('keep', _config.capabilities or {}, lsp_status.capabilities) return _config end local elixir = require('elixir') elixir.setup(config({ -- repo = "mhanberg/elixir-ls", -- defaults to elixir-lsp/elixir-ls -- branch = "mh/all-workspace-symbols", -- defaults to nil, just checkouts out the default branch, mutually exclusive with the `tag` option cmd = {"/usr/local/opt/elixir-ls/rel/language_server.sh"}, settings = elixir.settings({ dialyzerEnabled = true, fetchDeps = false, enableTestLenses = true, suggestSpecs = false, }), on_attach = function(client, bufnr) on_attach(client, bufnr) local map_opts = { buffer = true, noremap = true} -- remove the pipe operator vim.keymap.set("n", "fp", ":ElixirFromPipe", map_opts) -- add the pipe operator vim.keymap.set("n", "tp", ":ElixirToPipe", map_opts) vim.keymap.set("v", "em", ":ElixirExpandMacro", map_opts) end })) -- Enable the following language servers local servers = { 'gopls', 'julials', 'rust_analyzer', 'pyright' } for _, lsp in ipairs(servers) do lspconfig[lsp].setup(config()) end lspconfig.sumneko_lua.setup(config({ settings = { Lua = { diagnostics = { globals = { 'vim' } } } } })) require('rust-tools').setup({ tools = { runnables = { use_telescope = true, }, inlay_hints = { auto = true, parameter_hints_prefix = "", other_hints_prefix = "", } }, server = { on_attach = on_attach, settings = { ["rust-analyzer"] = { checkOnSave = { command = "clippy", }, }, }, }, })