Skip to content

Commit

Permalink
feat: prettier debug
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 2, 2024
1 parent 3f56582 commit fe68a25
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
3 changes: 0 additions & 3 deletions lua/lazydev/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ function M.attach(client)
if Config.is_enabled(root) then
local ws = Workspace.get(client, root)
settings = ws.settings
if Config.debug then
ws:debug()
end
end
end

Expand Down
41 changes: 41 additions & 0 deletions lua/lazydev/util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
local M = {}

---@alias NotifyOpts {level?: number, title?: string, once?: boolean}

---@param msg string|string[]
---@param opts? NotifyOpts
function M.notify(msg, opts)
opts = opts or {}
msg = type(msg) == "table" and table.concat(msg, "\n") or msg
---@cast msg string
msg = vim.trim(msg)
return vim[opts.once and "notify_once" or "notify"](msg, opts.level, {
title = opts.title or "lazydev.nvim",
on_open = function(win)
vim.wo.conceallevel = 3
vim.wo.concealcursor = "n"
vim.wo.spell = false
vim.treesitter.start(vim.api.nvim_win_get_buf(win), "markdown")
end,
})
end

---@param msg string|string[]
---@param opts? NotifyOpts
function M.warn(msg, opts)
M.notify(msg, vim.tbl_extend("keep", { level = vim.log.levels.WARN }, opts or {}))
end

---@param msg string|string[]
---@param opts? NotifyOpts
function M.error(msg, opts)
M.notify(msg, vim.tbl_extend("keep", { level = vim.log.levels.ERROR }, opts or {}))
end

---@param msg string|string[]
---@param opts? NotifyOpts
function M.info(msg, opts)
M.notify(msg, vim.tbl_extend("keep", { level = vim.log.levels.INFO }, opts or {}))
end

return M
10 changes: 5 additions & 5 deletions lua/lazydev/workspace.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local Config = require("lazydev.config")

---@class lazydev.Workspace
---@field root string
---@field client_id number
Expand Down Expand Up @@ -105,21 +103,23 @@ function M:update()

if not vim.deep_equal(settings, self.settings) then
self.settings = settings
self:debug()
return true
end
end

function M:debug()
local Util = require("lazy.core.util")
local Util = require("lazydev.util")
local Plugin = require("lazy.core.plugin")
local lines = { "# " .. self.root }
local lines = { "## " .. vim.fn.fnamemodify(self.root, ":~") }
---@type string[]
local library = vim.tbl_get(self.settings, "Lua", "workspace", "library") or {}
for _, lib in ipairs(library) do
lib = vim.fn.fnamemodify(lib, ":~")
local plugin = Plugin.find(lib .. "/")
table.insert(lines, "- " .. (plugin and "**" .. plugin.name .. "** " or "") .. ("`" .. lib .. "`"))
end
Util.info(lines, { title = "lazydev.nvim" })
Util.info(lines)
end

return M

0 comments on commit fe68a25

Please sign in to comment.