Skip to content

Commit cc4d1ea

Browse files
Hystic diagnostics is a new misery
1 parent 6adfdf4 commit cc4d1ea

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

nvim/lua/prototypes/misery.lua

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,93 @@ local deranged_register = {
206206
end,
207207
}
208208

209+
local lvl = vim.diagnostic.severity
210+
local hysteric_diagnostics = {
211+
name = "hysteric diagnostics",
212+
desc = "Inject fake diagnostics",
213+
namespace = vim.api.nvim_create_namespace("misery.hysteric_diagnostics"),
214+
augroup = "misery.hysteric_diagnostics",
215+
timer = nil,
216+
messages = {
217+
{ severity = lvl.ERROR, message = "syntax error, try once more with feeling" },
218+
{ severity = lvl.ERROR, message = "unreachable code, unachievable dreams" },
219+
{ severity = lvl.HINT, message = "possible null reference, reconsider the choices that have brought you to this moment" },
220+
{ severity = lvl.WARN, message = "this variable is shadowed by its own ambition" },
221+
-- From Alan Perlis <https://www.cs.yale.edu/homes/perlis-alan/quotes.html>
222+
{ severity = lvl.ERROR, message = "it is often the early bird that makes the worm" },
223+
{ severity = lvl.ERROR, message = "simplicity does not precede complexity, but follows it" },
224+
{ severity = lvl.ERROR, message = "there are two ways to write error-free programs; only the third way works" },
225+
{ severity = lvl.HINT, message = "is it possible that software is not like anything else, that it is meant to be discarded: that the whole point is to see it as a soap bubble?" },
226+
{ severity = lvl.HINT, message = "it is easier to change the specification to fit the program than vice versa" },
227+
{ severity = lvl.HINT, message = "it is easier to write an incorrect program than understand a correct one" },
228+
{ severity = lvl.HINT, message = "the proof of a system's value is its existence" },
229+
{ severity = lvl.HINT, message = "there will always be things we wish to say in our programs that in all known languages can only be said poorly" },
230+
{ severity = lvl.WARN, message = "in seeking the unattainable, simplicity only gets in the way" },
231+
{ severity = lvl.WARN, message = "one man's constant is another man's variable" },
232+
{ severity = lvl.WARN, message = "optimization hinders evolution" },
233+
{ severity = lvl.WARN, message = "string is a perfect vehicle for hiding information" },
234+
{ severity = lvl.WARN, message = "syntactic sugar causes cancer of the semicolon" },
235+
},
236+
start = function(self)
237+
local function sprinkle()
238+
local buf = vim.api.nvim_get_current_buf()
239+
if not vim.api.nvim_buf_is_valid(buf) then
240+
return
241+
end
242+
local line_count = vim.api.nvim_buf_line_count(buf)
243+
if line_count == 0 then
244+
return
245+
end
246+
local diagnostics = {}
247+
local count = math.random(1, 3)
248+
for _ = 1, count do
249+
local pick = self.messages[math.random(#self.messages)]
250+
local lnum = math.random(0, line_count - 1)
251+
local line = vim.api.nvim_buf_get_lines(buf, lnum, lnum + 1, false)[1] or ""
252+
table.insert(diagnostics, {
253+
lnum = lnum,
254+
col = 0,
255+
end_lnum = lnum,
256+
end_col = #line,
257+
severity = pick.severity,
258+
message = pick.message,
259+
source = self.name,
260+
})
261+
end
262+
vim.diagnostic.set(self.namespace, buf, diagnostics)
263+
end
264+
265+
self.timer = vim.uv.new_timer()
266+
self.timer:start(2000, 30000, vim.schedule_wrap(sprinkle))
267+
268+
local group = vim.api.nvim_create_augroup(self.augroup, { clear = true })
269+
vim.api.nvim_create_autocmd({ "BufEnter", "TextChanged", "TextChangedI" }, {
270+
group = group,
271+
callback = function()
272+
if math.random() < 0.3 then
273+
sprinkle()
274+
end
275+
end,
276+
})
277+
end,
278+
stop = function(self)
279+
if self.timer then
280+
self.timer:stop()
281+
self.timer:close()
282+
self.timer = nil
283+
end
284+
pcall(vim.api.nvim_clear_autocmds, { group = self.augroup })
285+
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
286+
if vim.api.nvim_buf_is_valid(buf) then
287+
vim.diagnostic.reset(self.namespace, buf)
288+
end
289+
end
290+
end,
291+
}
292+
209293
M.effects = {
210294
invisiline,
295+
hysteric_diagnostics,
211296
deranged_register,
212297
hidden_cursor,
213298
random_theme,

0 commit comments

Comments
 (0)