-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a
LazyDev
debugging command that shows libraries and se…
…ttings for the current buffer
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
local Util = require("lazydev.util") | ||
local Workspace = require("lazydev.workspace") | ||
|
||
local M = {} | ||
|
||
---@type table<string, fun(args: string[])> | ||
M.commands = { | ||
debug = function() | ||
local buf = vim.api.nvim_get_current_buf() | ||
local ws = Workspace.find(buf) | ||
if not ws then | ||
return Util.warn("No **LuaLS** workspace found.\nUse `:LazyDev lsp` to see settings of attached LSP clients.") | ||
end | ||
ws:debug({ details = true }) | ||
end, | ||
lsp = function() | ||
local clients = vim.lsp.get_clients({ bufnr = 0 }) | ||
local lines = {} ---@type string[] | ||
for _, client in ipairs(clients) do | ||
lines[#lines + 1] = "## " .. client.name | ||
lines[#lines + 1] = "```lua" | ||
lines[#lines + 1] = "settings = " .. vim.inspect(client.settings) | ||
lines[#lines + 1] = "```" | ||
end | ||
Util.info(lines) | ||
end, | ||
} | ||
|
||
function M.execute(input) | ||
local prefix, args = M.parse(input.args) | ||
prefix = prefix and prefix ~= "" and prefix or "debug" | ||
if not M.commands[prefix or ""] then | ||
return Util.error("Invalid command") | ||
end | ||
M.commands[prefix](args) | ||
end | ||
|
||
function M.complete(_, line) | ||
local prefix, args = M.parse(line) | ||
if #args > 0 then | ||
return {} | ||
end | ||
|
||
---@param key string | ||
return vim.tbl_filter(function(key) | ||
return key:find(prefix, 1, true) == 1 | ||
end, vim.tbl_keys(M.commands)) | ||
end | ||
|
||
---@return string, string[] | ||
function M.parse(args) | ||
local parts = vim.split(vim.trim(args), "%s+") | ||
if parts[1]:find("LazyDev") then | ||
table.remove(parts, 1) | ||
end | ||
if args:sub(-1) == " " then | ||
parts[#parts + 1] = "" | ||
end | ||
return table.remove(parts, 1) or "", parts | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters