Skip to content

Commit

Permalink
chore: debug as configurable as option
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 6, 2024
1 parent a66ec63 commit 51fcd62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ require("various-textobjs").setup {
icon = "󰠱", -- only used with notification plugins like `nvim-notify`
whenObjectNotFound = true,
},

-- show debugging messages on use of certain text objects
debug = false,
}
```

Expand Down
3 changes: 3 additions & 0 deletions lua/various-textobjs/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ local defaultConfig = {
icon = "󰠱", -- only used with notification plugins like `nvim-notify`
whenObjectNotFound = true,
},

-- show debugging messages on use of certain text objects
debug = false,
}
M.config = defaultConfig

Expand Down
9 changes: 7 additions & 2 deletions lua/various-textobjs/textobjs/charwise/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
---@return integer? startCol
---@return integer? endCol
function M.selectClosestTextobj(patterns, scope, lookForwLines)
local enableLogging = false -- DEBUG
local enableLogging = require("various-textobjs.config").config.debug
local objLogging = {}

-- initialized with values to always loose comparisons
Expand All @@ -111,6 +111,7 @@ function M.selectClosestTextobj(patterns, scope, lookForwLines)
cur.distance = cur.startCol - cursorCol
cur.endDistance = cursorCol - cur.endCol
cur.cursorOnObj = cur.distance <= 0 and cur.endDistance <= 0
cur.patternName = patternName

-- INFO Here, we cannot simply use the absolute value of the distance.
-- If the cursor is standing on a big textobj A, and there is a
Expand Down Expand Up @@ -149,7 +150,11 @@ function M.selectClosestTextobj(patterns, scope, lookForwLines)
if enableLogging then
local textobj = debug.getinfo(3, "n").name
objLogging._closest = closest.patternName
vim.notify(vim.inspect(objLogging), nil, { ft = "lua", title = scope .. " " .. textobj })
vim.notify(
vim.inspect(objLogging),
vim.log.levels.DEBUG,
{ ft = "lua", title = scope .. " " .. textobj }
)
end
return closest.row, closest.startCol, closest.endCol
end
Expand Down

0 comments on commit 51fcd62

Please sign in to comment.