Skip to content

Commit 186228c

Browse files
authored
refactor: organize config, improve logging/debugging(#164)
Moved config.lua to separate dir and modularized config code some BREAKING CHANGE: Removes `use_buffer` opts from `config.log`. Will just write to log file if `use_file` is enabled and when logging meets `level` threshold. This update does make `use_file` enabled by default with a log level of `warn` so that users can at least send in debug info if problems occur. Default log file is at `vim.fn.stdpath("log")` with filename "checkmate.log" (this can be modified with `file_path` opt). Release-As: 0.10.1
1 parent d923c57 commit 186228c

33 files changed

+1719
-1914
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ The Checkmate buffer is **saved as regular Markdown** which means it's compatibl
238238
---
239239
---The states that a todo item may have
240240
---Default: "unchecked" and "checked"
241-
---Note that Github-flavored Markdown specification only includes "checked" and "unchecked".
241+
---Note that Gith[118;1:3uub-flavored Markdown specification only includes "checked" and "unchecked".
242242
---
243243
---If you add additional states here, they may not work in other Markdown apps without special configuration.
244244
---@field todo_states table<string, checkmate.TodoStateDefinition>
@@ -260,7 +260,7 @@ The Checkmate buffer is **saved as regular Markdown** which means it's compatibl
260260
---
261261
---When you change a todo's state, it can automatically update related todos based on their
262262
---hierarchical relationship. Only "checked" and "unchecked" states are propagated - custom
263-
---states remain unchanged but influence the propagation logic based on their behavior type.
263+
---states remain unchanged but influence the propagation logic based on their type.
264264
---@field smart_toggle checkmate.SmartToggleSettings
265265
---
266266
---Enable/disable the todo count indicator (shows number of child todo items incomplete vs complete)
@@ -314,12 +314,13 @@ The Checkmate buffer is **saved as regular Markdown** which means it's compatibl
314314
---@field use_file boolean
315315
---
316316
--- The default path on-disk where log files will be written to.
317-
--- Defaults to `~/.local/share/nvim/checkmate/current.log` (Unix) or `C:\Users\USERNAME\AppData\Local\nvim-data\checkmate\current.log` (Windows)
317+
--- Defaults to `vim.fn.stdpath("log") .. "checkmate.log"`
318318
---@field file_path string?
319319
---
320-
--- Should print log output to a scratch buffer
321-
--- Open with `:Checkate debug log` or `require("checkmate").debug_log()`
322-
---@field use_buffer boolean
320+
--- Max file size (kilobytes)
321+
--- When file size exceeds max, a new file will be overwritten
322+
--- Default: 5120 kb (5 mb)
323+
---@field max_file_size? number
323324

324325
-----------------------------------------------------
325326

@@ -415,7 +416,7 @@ The Checkmate buffer is **saved as regular Markdown** which means it's compatibl
415416
---When a parent should become checked
416417
---i.e, how a checked child affects its parent
417418
---
418-
---Note: Custom states with "complete" behavior count as done, "incomplete" as not done,
419+
---Note: Custom states with "complete" type count as done, "incomplete" as not done,
419420
---and "inactive" states are ignored (as if they don't exist for completion purposes).
420421
---
421422
--- - "all_children": When ALL descendants are complete or inactive, including nested
@@ -550,7 +551,6 @@ The Checkmate buffer is **saved as regular Markdown** which means it's compatibl
550551
---
551552
---Map of issues to diagnostic severity level
552553
---@field severity table<string, vim.diagnostic.Severity>?
553-
--- TODO: @field auto_fix boolean Auto fix on buffer write
554554
---
555555
---Whether to use verbose linter/diagnostic messages
556556
---Default: false
@@ -562,7 +562,7 @@ The Checkmate buffer is **saved as regular Markdown** which means it's compatibl
562562
### Defaults
563563
```lua
564564
---@type checkmate.Config
565-
local defaults = {
565+
return {
566566
enabled = true,
567567
notify = true,
568568
-- Default file matching:
@@ -578,9 +578,8 @@ local defaults = {
578578
"*.todo.md",
579579
},
580580
log = {
581-
level = "info",
582-
use_file = false,
583-
use_buffer = false,
581+
level = "warn",
582+
use_file = true,
584583
},
585584
-- Default keymappings
586585
keys = {

doc/checkmate.txt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*checkmate.txt* For Neovim >= 0.10.0 Last change: 2025 July 26
1+
*checkmate.txt* For Neovim >= 0.10.0 Last change: 2025 July 28
22

33
==============================================================================
44
Table of Contents *checkmate-table-of-contents*
@@ -300,7 +300,7 @@ Config definitions/annotations ~
300300
---
301301
---The states that a todo item may have
302302
---Default: "unchecked" and "checked"
303-
---Note that Github-flavored Markdown specification only includes "checked" and "unchecked".
303+
---Note that Gith[118;1:3uub-flavored Markdown specification only includes "checked" and "unchecked".
304304
---
305305
---If you add additional states here, they may not work in other Markdown apps without special configuration.
306306
---@field todo_states table<string, checkmate.TodoStateDefinition>
@@ -322,7 +322,7 @@ Config definitions/annotations ~
322322
---
323323
---When you change a todo's state, it can automatically update related todos based on their
324324
---hierarchical relationship. Only "checked" and "unchecked" states are propagated - custom
325-
---states remain unchanged but influence the propagation logic based on their behavior type.
325+
---states remain unchanged but influence the propagation logic based on their type.
326326
---@field smart_toggle checkmate.SmartToggleSettings
327327
---
328328
---Enable/disable the todo count indicator (shows number of child todo items incomplete vs complete)
@@ -376,12 +376,13 @@ Config definitions/annotations ~
376376
---@field use_file boolean
377377
---
378378
--- The default path on-disk where log files will be written to.
379-
--- Defaults to `~/.local/share/nvim/checkmate/current.log` (Unix) or `C:\Users\USERNAME\AppData\Local\nvim-data\checkmate\current.log` (Windows)
379+
--- Defaults to `vim.fn.stdpath("log") .. "checkmate.log"`
380380
---@field file_path string?
381381
---
382-
--- Should print log output to a scratch buffer
383-
--- Open with `:Checkate debug log` or `require("checkmate").debug_log()`
384-
---@field use_buffer boolean
382+
--- Max file size (kilobytes)
383+
--- When file size exceeds max, a new file will be overwritten
384+
--- Default: 5120 kb (5 mb)
385+
---@field max_file_size? number
385386

386387
-----------------------------------------------------
387388

@@ -477,7 +478,7 @@ Config definitions/annotations ~
477478
---When a parent should become checked
478479
---i.e, how a checked child affects its parent
479480
---
480-
---Note: Custom states with "complete" behavior count as done, "incomplete" as not done,
481+
---Note: Custom states with "complete" type count as done, "incomplete" as not done,
481482
---and "inactive" states are ignored (as if they don't exist for completion purposes).
482483
---
483484
--- - "all_children": When ALL descendants are complete or inactive, including nested
@@ -612,7 +613,6 @@ Config definitions/annotations ~
612613
---
613614
---Map of issues to diagnostic severity level
614615
---@field severity table<string, vim.diagnostic.Severity>?
615-
--- TODO: @field auto_fix boolean Auto fix on buffer write
616616
---
617617
---Whether to use verbose linter/diagnostic messages
618618
---Default: false
@@ -624,7 +624,7 @@ DEFAULTS ~
624624

625625
>lua
626626
---@type checkmate.Config
627-
local defaults = {
627+
return {
628628
enabled = true,
629629
notify = true,
630630
-- Default file matching:
@@ -640,9 +640,8 @@ DEFAULTS ~
640640
"*.todo.md",
641641
},
642642
log = {
643-
level = "info",
644-
use_file = false,
645-
use_buffer = false,
643+
level = "warn",
644+
use_file = true,
646645
},
647646
-- Default keymappings
648647
keys = {

lua/checkmate/api.lua

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function M.is_valid_buffer(bufnr)
4242
local ok, is_valid = pcall(vim.api.nvim_buf_is_valid, bufnr)
4343
if not ok or not is_valid then
4444
vim.notify("Checkmate: Invalid buffer", vim.log.levels.ERROR)
45+
log.fmt_error("[api] Invalid buffer %d", bufnr)
4546
return false
4647
end
4748

@@ -63,6 +64,7 @@ function M.setup_buffer(bufnr)
6364

6465
-- bail early if we're not running
6566
if not checkmate.is_running() then
67+
log.fmt_error("[api] Call to setup_buffer %d but Checkmate is NOT running", bufnr)
6668
return false
6769
end
6870

@@ -76,7 +78,6 @@ function M.setup_buffer(bufnr)
7678

7779
if config.options.linter and config.options.linter.enabled ~= false then
7880
local linter = require("checkmate.linter")
79-
linter.setup(config.options.linter)
8081
linter.lint_buffer(bufnr)
8182
end
8283

@@ -97,6 +98,8 @@ function M.setup_buffer(bufnr)
9798
vim.b[bufnr].checkmate_setup_complete = true
9899
vim.b[bufnr].checkmate_cleaned_up = false
99100

101+
log.fmt_debug("[api] Setup complete for bufnr %d", bufnr)
102+
100103
return true
101104
end
102105

@@ -154,7 +157,6 @@ function M.setup_keymaps(bufnr)
154157
mapping_config = vim.deepcopy(value)
155158
end
156159
else
157-
log.warn(string.format("Invalid value type for key '%s'", key), { module = "api" })
158160
end
159161

160162
if mapping_config and mapping_config.rhs then
@@ -201,8 +203,6 @@ function M.setup_keymaps(bufnr)
201203
require("checkmate").toggle_metadata(meta_name)
202204
end
203205

204-
log.debug("Mapping " .. mode .. " mode key " .. key .. " to metadata." .. meta_name, { module = "api" })
205-
206206
buffer_map(bufnr, mode, key, rhs, desc)
207207
table.insert(buffer_local_keys[bufnr], { mode, key })
208208
end
@@ -252,7 +252,6 @@ function M.setup_autocmds(bufnr)
252252

253253
local success = parser.convert_unicode_to_markdown(temp_bufnr)
254254
if not success then
255-
log.error("Failed to convert Unicode to Markdown", { module = "api" })
256255
vim.api.nvim_buf_delete(temp_bufnr, { force = true })
257256
vim.notify("Checkmate: Failed to save when attemping to convert to Markdown", vim.log.levels.ERROR)
258257
vim.b[bufnr]._checkmate_writing = false
@@ -285,7 +284,6 @@ function M.setup_autocmds(bufnr)
285284
pcall(function()
286285
uv.fs_unlink(temp_filename)
287286
end)
288-
log.error("Failed to rename temp file: " .. (rename_err or "unknown error"), { module = "api" })
289287
vim.notify("Checkmate: Failed to save file", vim.log.levels.ERROR)
290288
vim.bo[bufnr].modified = was_modified
291289
vim.b[bufnr]._checkmate_writing = false
@@ -386,7 +384,6 @@ function M.process_buffer(bufnr, process_type, reason)
386384
process_type = process_type or "full"
387385
local process_config = M.PROCESS_CONFIGS[process_type]
388386
if not process_config then
389-
log.error("Unknown process type: " .. process_type, { module = "api" })
390387
return
391388
end
392389

@@ -422,11 +419,6 @@ function M.process_buffer(bufnr, process_type, reason)
422419

423420
local end_time = vim.uv.hrtime() / 1000000
424421
local elapsed = end_time - start_time
425-
426-
log.debug(
427-
("Buffer processed (%s) in %d ms, reason: %s"):format(process_type, elapsed, reason or "unknown"),
428-
{ module = "api" }
429-
)
430422
end
431423

432424
M._debounced_processors[bufnr][process_type] = util.debounce(process_impl, {
@@ -435,11 +427,6 @@ function M.process_buffer(bufnr, process_type, reason)
435427
end
436428

437429
M._debounced_processors[bufnr][process_type]()
438-
439-
log.debug(
440-
("Process (%s) scheduled for buffer %d, reason: %s"):format(process_type, bufnr, reason or "unknown"),
441-
{ module = "api" }
442-
)
443430
end
444431

445432
-- Cleans up all checkmate state associated with a buffer
@@ -1115,7 +1102,6 @@ end
11151102
function M.compute_diff_add_metadata(items, meta_name, meta_value)
11161103
local meta_props = meta_module.get_meta_props(meta_name)
11171104
if not meta_props then
1118-
log.error("Metadata type '" .. meta_name .. "' is not configured", { module = "api" })
11191105
return {}, {}
11201106
end
11211107

@@ -1727,7 +1713,6 @@ function M.archive_todos(opts)
17271713
break
17281714
end
17291715
end
1730-
log.debug(("Found existing archive section: lines %d-%d"):format(archive_start_row + 1, archive_end_row + 1))
17311716
break
17321717
end
17331718
end
@@ -1775,7 +1760,6 @@ function M.archive_todos(opts)
17751760
util.notify("No completed todo items to archive", vim.log.levels.INFO)
17761761
return false
17771762
end
1778-
log.debug(("Found %d root todos to archive"):format(archived_root_cnt))
17791763

17801764
table.sort(archived_ranges, function(a, b)
17811765
return a.start_row < b.start_row

lua/checkmate/commands.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local log = require("checkmate.log")
2+
13
local Commands = {}
24

35
---@class checkmate.CommandDefinition
@@ -326,6 +328,7 @@ function Commands.dispatch(opts)
326328
("Usage: Checkmate %s <%s>"):format(path, table.concat(vim.tbl_keys(entry.subcommands), "|")),
327329
vim.log.levels.INFO
328330
)
331+
log.fmt_warn("[commands] `%s %s` is not a valid Checkmate command", opts.name, opts.args)
329332
return
330333
end
331334
entry = entry.subcommands[name]

0 commit comments

Comments
 (0)