A very fast neovim config :D
1local M = {}
2
3M.lsp_signs = { Error = "E", Warn = "W", Hint = "H", Info = "I" }
4
5function M.on_attach(on_attach)
6 vim.api.nvim_create_autocmd("LspAttach", {
7 callback = function(args)
8 local buffer = args.buf
9 local client = vim.lsp.get_client_by_id(args.data.client_id)
10 on_attach(client, buffer)
11 end,
12 })
13end
14
15--[[
16 TODO: cmdlineheight = 0 makes notifications not visible
17 for some reasons notifications in M.toggle_diagnostics() works just fine
18]]
19
20function M.warn(msg, notify_opts)
21 vim.notify(msg, vim.log.levels.WARN, notify_opts)
22end
23
24function M.error(msg, notify_opts)
25 vim.notify(msg, vim.log.levels.ERROR, notify_opts)
26end
27
28function M.info(msg, notify_opts)
29 vim.notify(msg, vim.log.levels.INFO, notify_opts)
30end
31
32---@param silent boolean?
33---@param values? {[1]:any, [2]:any}
34function M.toggle(option, silent, values)
35 if values then
36 if vim.opt_local[option]:get() == values[1] then
37 vim.opt_local[option] = values[2]
38 else
39 vim.opt_local[option] = values[1]
40 end
41 M.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" })
42 else
43 vim.opt_local[option] = not vim.opt_local[option]:get()
44 if not silent then
45 if vim.opt_local[option]:get() then
46 M.info("Enabled " .. option, { title = "Option" })
47 else
48 M.warn("Disabled " .. option, { title = "Option" })
49 end
50 end
51 end
52end
53
54M.diagnostics_active = true
55function M.toggle_diagnostics()
56 M.diagnostics_active = not M.diagnostics_active
57 if M.diagnostics_active then
58 vim.diagnostic.show()
59 M.info("Enabled Diagnostics", { title = "Lsp" })
60
61 vim.lsp.handlers["textDocument/publishDiagnostics"] =
62 vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {})
63 else
64 vim.diagnostic.hide()
65 M.warn("Disabled Diagnostics", { title = "Lsp" })
66
67 vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end
68 end
69end
70
71function M.set_colorcolumn()
72 local colorcolumn = vim.o.colorcolumn
73 if colorcolumn == "80" then
74 vim.o.colorcolumn = "0"
75 M.info("Color Column disabled")
76 else
77 vim.o.colorcolumn = "80"
78 M.info("Color Column set to 80")
79 end
80end
81
82return M