mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-23 20:24:28 +02:00
feat: added NEWS.md and option to automatically show when changed (enabled by default)
This commit is contained in:
parent
442077fca3
commit
73acab1675
5 changed files with 153 additions and 9 deletions
|
@ -19,6 +19,13 @@ local defaults = {
|
|||
-- lazyvim.config.options can't be configured here since that's loaded before lazyvim setup
|
||||
-- if you want to disable loading options, add `package.loaded["lazyvim.config.options"] = true` to the top of your init.lua
|
||||
},
|
||||
news = {
|
||||
-- When enabled, NEWS.md will be shown when changed.
|
||||
-- This only contains big new features and breaking changes.
|
||||
lazyvim = true,
|
||||
-- Same but for Neovim's news.txt
|
||||
neovim = false,
|
||||
},
|
||||
-- icons used by other plugins
|
||||
-- stylua: ignore
|
||||
icons = {
|
||||
|
@ -123,6 +130,7 @@ local defaults = {
|
|||
M.json = {
|
||||
data = {
|
||||
version = nil, ---@type string?
|
||||
hashes = {}, ---@type table<string, string>
|
||||
extras = {}, ---@type string[]
|
||||
},
|
||||
}
|
||||
|
@ -173,6 +181,7 @@ function M.setup(opts)
|
|||
M.load("keymaps")
|
||||
|
||||
Util.format.setup()
|
||||
Util.news.setup()
|
||||
|
||||
vim.api.nvim_create_user_command("LazyRoot", function()
|
||||
Util.root.info()
|
||||
|
|
|
@ -125,7 +125,7 @@ map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit all" })
|
|||
map("n", "<leader>ui", vim.show_pos, { desc = "Inspect Pos" })
|
||||
|
||||
-- LazyVim Changelog
|
||||
map("n", "<leader>L", Util.changelog, {desc = "LazyVim Changelog"})
|
||||
map("n", "<leader>L", function() Util.news.changelog() end, { desc = "LazyVim Changelog" })
|
||||
|
||||
-- floating terminal
|
||||
local lazyterm = function() Util.terminal(nil, { cwd = Util.root() }) end
|
||||
|
|
|
@ -11,6 +11,7 @@ local LazyUtil = require("lazy.core.util")
|
|||
---@field plugin lazyvim.util.plugin
|
||||
---@field extras lazyvim.util.extras
|
||||
---@field inject lazyvim.util.inject
|
||||
---@field news lazyvim.util.news
|
||||
local M = {}
|
||||
|
||||
---@type table<string, string|string[]>
|
||||
|
@ -137,14 +138,6 @@ function M.on_load(name, fn)
|
|||
end
|
||||
end
|
||||
|
||||
function M.changelog()
|
||||
local lv = require("lazy.core.config").plugins.LazyVim
|
||||
local float = require("lazy.util").open(lv.dir .. "/CHANGELOG.md")
|
||||
vim.wo[float.win].spell = false
|
||||
vim.wo[float.win].wrap = false
|
||||
vim.diagnostic.disable(float.buf)
|
||||
end
|
||||
|
||||
-- Wrapper around vim.keymap.set that will
|
||||
-- not create a keymap if a lazy key handler exists.
|
||||
-- It will also set `silent` to true by default.
|
||||
|
|
77
lua/lazyvim/util/news.lua
Normal file
77
lua/lazyvim/util/news.lua
Normal file
|
@ -0,0 +1,77 @@
|
|||
local Config = require("lazyvim.config")
|
||||
local Util = require("lazyvim.util")
|
||||
|
||||
---@class lazyvim.util.news
|
||||
local M = {}
|
||||
|
||||
function M.hash(file)
|
||||
local stat = vim.loop.fs_stat(file)
|
||||
if not stat then
|
||||
return
|
||||
end
|
||||
return stat.size .. ""
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
vim.schedule(function()
|
||||
if Config.news.lazyvim then
|
||||
M.lazyvim(true)
|
||||
end
|
||||
if Config.news.neovim then
|
||||
M.neovim(true)
|
||||
end
|
||||
end)
|
||||
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)
|
||||
opts = opts or {}
|
||||
if opts.plugin then
|
||||
local plugin = require("lazy.core.config").plugins[opts.plugin] --[[@as LazyPlugin?]]
|
||||
if not plugin then
|
||||
return Util.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 Util.error("File not found")
|
||||
end
|
||||
|
||||
if opts.when_changed then
|
||||
local hash = M.hash(file)
|
||||
if hash == Config.json.data.hashes[file] then
|
||||
return
|
||||
end
|
||||
Config.json.data.hashes[file] = hash
|
||||
Config.json.save()
|
||||
end
|
||||
|
||||
local float = require("lazy.util").float({
|
||||
file = file,
|
||||
size = { width = 0.6, height = 0.6 },
|
||||
})
|
||||
vim.wo[float.win].spell = false
|
||||
vim.wo[float.win].wrap = false
|
||||
vim.wo[float.win].signcolumn = "yes"
|
||||
vim.wo[float.win].statuscolumn = " "
|
||||
vim.wo[float.win].conceallevel = 3
|
||||
vim.diagnostic.disable(float.buf)
|
||||
end
|
||||
|
||||
return M
|
Loading…
Add table
Add a link
Reference in a new issue