Files
LazyVim/lua/lazyvim/util/news.lua
Folke Lemaitre 2f4697443c feat(core)!: move a bunch of LazyVim features to snacks.nvim (#4706)
## Description

LazyVim comes with a bunch of smaller QoL plugin like features, but it's
not easy for non LazyVim users to use them.

That's why I started working on
[snacks.nvim](https://github.com/folke/snacks.nvim), a collection of
small QoL plugins for Neovim.

Snacks also includes a bunch of new improvements to these features.

This PR fully integrates with snacks.

## Todo

- [ ] add proper deprecations where needed
- [ ] create snacks docs
- [ ] document all the new improvements relevant to LazyVim users

## Closes

- [ ] #4492 
- [ ] #4333
- [ ] #4687

## Screenshots

<!-- Add screenshots of the changes if applicable. -->

## Checklist

- [ ] I've read the
[CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md)
guidelines.
2024-11-07 15:54:47 +01:00

100 lines
2.1 KiB
Lua

---@class lazyvim.util.news
local M = {}
function M.hash(file)
local stat = vim.uv.fs_stat(file)
if not stat then
return
end
return stat.size .. ""
end
function M.setup()
vim.schedule(function()
if LazyVim.config.news.lazyvim then
if not LazyVim.config.json.data.news["NEWS.md"] then
M.welcome()
end
M.lazyvim(true)
end
if LazyVim.config.news.neovim then
M.neovim(true)
end
end)
end
function M.welcome()
LazyVim.info("Welcome to LazyVim!")
end
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)
local ref = file
opts = opts or {}
if opts.plugin then
local plugin = require("lazy.core.config").plugins[opts.plugin] --[[@as LazyPlugin?]]
if not plugin then
return LazyVim.error("plugin not found: " .. opts.plugin)
end
file = plugin.dir .. "/" .. file
elseif opts.rtp then
file = vim.api.nvim_get_runtime_file(file, false)[1]
end
if not file then
return LazyVim.error("File not found")
end
if opts.when_changed then
local is_new = not LazyVim.config.json.data.news[ref]
local hash = M.hash(file)
if hash == LazyVim.config.json.data.news[ref] then
return
end
LazyVim.config.json.data.news[ref] = hash
LazyVim.json.save()
-- don't open if file has never been opened
if is_new then
return
end
end
Snacks.config.style("news", {
width = 0.6,
height = 0.6,
wo = {
spell = false,
wrap = false,
signcolumn = "yes",
statuscolumn = " ",
conceallevel = 3,
},
})
local float = Snacks.win({
file = file,
style = "news",
})
if vim.diagnostic.enable then
pcall(vim.diagnostic.enable, false, { bufnr = float.buf })
else
pcall(vim.diagnostic.disable, float.buf)
end
end
return M