2023-10-12 14:38:25 +02:00
|
|
|
---@class lazyvim.util.news
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.hash(file)
|
2024-03-22 09:02:34 +01:00
|
|
|
local stat = vim.uv.fs_stat(file)
|
2023-10-12 14:38:25 +02:00
|
|
|
if not stat then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return stat.size .. ""
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.setup()
|
|
|
|
vim.schedule(function()
|
2024-06-16 15:35:38 +02:00
|
|
|
if LazyVim.config.news.lazyvim then
|
|
|
|
if not LazyVim.config.json.data.news["NEWS.md"] then
|
2023-10-14 16:56:48 +02:00
|
|
|
M.welcome()
|
|
|
|
end
|
2023-10-12 14:38:25 +02:00
|
|
|
M.lazyvim(true)
|
|
|
|
end
|
2024-06-16 15:35:38 +02:00
|
|
|
if LazyVim.config.news.neovim then
|
2023-10-12 14:38:25 +02:00
|
|
|
M.neovim(true)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2023-10-14 16:56:48 +02:00
|
|
|
function M.welcome()
|
2024-03-22 09:15:09 +01:00
|
|
|
LazyVim.info("Welcome to LazyVim!")
|
2023-10-14 16:56:48 +02:00
|
|
|
end
|
|
|
|
|
2023-10-12 14:38:25 +02:00
|
|
|
function M.changelog()
|
|
|
|
M.open("CHANGELOG.md", { plugin = "LazyVim" })
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.lazyvim(when_changed)
|
|
|
|
M.open("NEWS.md", { plugin = "LazyVim", when_changed = when_changed })
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.neovim(when_changed)
|
|
|
|
M.open("doc/news.txt", { rtp = true, when_changed = when_changed })
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param file string
|
|
|
|
---@param opts? {plugin?:string, rtp?:boolean, when_changed?:boolean}
|
|
|
|
function M.open(file, opts)
|
2023-10-12 17:48:49 +02:00
|
|
|
local ref = file
|
2023-10-12 14:38:25 +02:00
|
|
|
opts = opts or {}
|
|
|
|
if opts.plugin then
|
|
|
|
local plugin = require("lazy.core.config").plugins[opts.plugin] --[[@as LazyPlugin?]]
|
|
|
|
if not plugin then
|
2024-03-22 09:15:09 +01:00
|
|
|
return LazyVim.error("plugin not found: " .. opts.plugin)
|
2023-10-12 14:38:25 +02:00
|
|
|
end
|
|
|
|
file = plugin.dir .. "/" .. file
|
|
|
|
elseif opts.rtp then
|
|
|
|
file = vim.api.nvim_get_runtime_file(file, false)[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
if not file then
|
2024-03-22 09:15:09 +01:00
|
|
|
return LazyVim.error("File not found")
|
2023-10-12 14:38:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if opts.when_changed then
|
2024-06-16 15:35:38 +02:00
|
|
|
local is_new = not LazyVim.config.json.data.news[ref]
|
2023-10-12 14:38:25 +02:00
|
|
|
local hash = M.hash(file)
|
2024-06-16 15:35:38 +02:00
|
|
|
if hash == LazyVim.config.json.data.news[ref] then
|
2023-10-12 14:38:25 +02:00
|
|
|
return
|
|
|
|
end
|
2024-06-16 15:35:38 +02:00
|
|
|
LazyVim.config.json.data.news[ref] = hash
|
2024-03-22 09:15:09 +01:00
|
|
|
LazyVim.json.save()
|
2023-10-14 16:56:48 +02:00
|
|
|
-- don't open if file has never been opened
|
|
|
|
if is_new then
|
|
|
|
return
|
|
|
|
end
|
2023-10-12 14:38:25 +02:00
|
|
|
end
|
|
|
|
|
2024-11-07 15:54:47 +01:00
|
|
|
Snacks.config.style("news", {
|
|
|
|
width = 0.6,
|
|
|
|
height = 0.6,
|
|
|
|
wo = {
|
|
|
|
spell = false,
|
|
|
|
wrap = false,
|
|
|
|
signcolumn = "yes",
|
|
|
|
statuscolumn = " ",
|
|
|
|
conceallevel = 3,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
local float = Snacks.win({
|
2023-10-12 14:38:25 +02:00
|
|
|
file = file,
|
2024-11-07 15:54:47 +01:00
|
|
|
style = "news",
|
2023-10-12 14:38:25 +02:00
|
|
|
})
|
2024-11-07 15:54:47 +01:00
|
|
|
|
2024-07-23 06:55:34 +02:00
|
|
|
if vim.diagnostic.enable then
|
2024-07-25 10:55:06 +02:00
|
|
|
pcall(vim.diagnostic.enable, false, { bufnr = float.buf })
|
2024-07-23 06:55:34 +02:00
|
|
|
else
|
2024-07-25 10:55:06 +02:00
|
|
|
pcall(vim.diagnostic.disable, float.buf)
|
2024-07-23 06:55:34 +02:00
|
|
|
end
|
2023-10-12 14:38:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|