Skip to content

Commit

Permalink
Add more debugging info about completion
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Mar 21, 2024
1 parent dd1e7ad commit be075a1
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion lua/obsidian/commands/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ local log = require "obsidian.log"
local util = require "obsidian.util"
local VERSION = require "obsidian.version"

---@return { available: boolean, refs: boolean|?, tags: boolean|?, new: boolean|?, sources: string[]|? }
local function check_completion()
local ok, cmp = pcall(require, "cmp")
if not ok then
return { available = false }
end

local cmp_refs = false
local cmp_tags = false
local cmp_new = false

---@type string[]
local sources = vim.tbl_map(function(source)
if source.name == "obsidian" then
cmp_refs = true
elseif source.name == "obsidian_tags" then
cmp_tags = true
elseif source.name == "obsidian_new" then
cmp_new = true
end
return source.name
end, cmp.get_config().sources)

return { available = true, refs = cmp_refs, tags = cmp_tags, new = cmp_new, sources = sources }
end

---@param client obsidian.Client
return function(client, data)
data = data or {}
Expand Down Expand Up @@ -34,7 +60,29 @@ return function(client, data)

log.lazy_info "Integrations:"
log.lazy_info(" βœ“ picker: %s", client:picker())
log.lazy_info(" βœ“ completion: %s", client.opts.completion.nvim_cmp and "enabled (nvim-cmp)" or "disabled")

if client.opts.completion.nvim_cmp then
local cmp_status = check_completion()
if cmp_status.available then
log.lazy_info(
" βœ“ completion: enabled (nvim-cmp) %s refs, %s tags, %s new",
cmp_status.refs and "βœ“" or "βœ—",
cmp_status.tags and "βœ“" or "βœ—",
cmp_status.new and "βœ“" or "βœ—"
)

if cmp_status.sources then
log.lazy_info " all sources:"
for _, source in ipairs(cmp_status.sources) do
log.lazy_info(" β€’ %s", source)
end
end
else
log.lazy_info " βœ“ completion: unavailable"
end
else
log.lazy_info " βœ— completion: disabled"
end

log.lazy_info "Tools:"
log.lazy_info(" βœ“ rg: %s", util.get_external_dependency_info "rg" or "not found")
Expand Down

0 comments on commit be075a1

Please sign in to comment.