Skip to content

Commit

Permalink
feat: add new command for show debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Jan 4, 2024
1 parent ce6705e commit 321305e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
</p>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![IT Man - Effortless APIs with Hurl.nvim: A Developer's Guide to Neovim Tooling [Vietnamese]](https://i.ytimg.com/vi/nr_RbHvnnwk/hqdefault.jpg)](https://www.youtube.com/watch?v=nr_RbHvnnwk)
Expand Down Expand Up @@ -161,7 +163,7 @@ These key mappings are active within the popup windows that `hurl.nvim` displays
```lua
local default_config = {
-- Toggle debugging information
debug = false, -- If true, logs will be saved at ~/.cache/nvim/hurl.nvim.log
debug = false, -- If true, logs will be saved at ~/.local/state/nvim/hurl.nvim.log

-- Set the display mode for the response: 'split' or 'popup'
mode = 'split',
Expand Down Expand Up @@ -216,7 +218,7 @@ Adjust the settings as per your needs to enhance your development experience wit

### Tips

- Enable debug mode with `debug = true` for detailed logs. Logs are saved at `~/.cache/nvim/hurl.nvim.log` on macOS.
- Enable debug mode with `debug = true` for detailed logs. Logs are saved at `~/.local/state/nvim/hurl.nvim.log` on macOS.
- **Split Mode with Edgy:** `hurl.nvim` can be used with [edgy.nvim](https://github.com/folke/edgy.nvim) to manage layout when using the split mode.

```lua
Expand Down Expand Up @@ -283,4 +285,3 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

38 changes: 38 additions & 0 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,44 @@ function M.setup()
vim.notify('hurl: no HTTP method found in the current line', vim.log.levels.INFO)
end
end, { nargs = '*', range = true })

-- Show debug info
utils.create_cmd('HurlDebugInfo', function()
-- Get the log file path
local log_file_path = utils.get_log_file_path()

-- Create a popup with the log file path
local lines = { 'Hurl.nvim Info:', 'Log file path: ' .. log_file_path }
local width = 0
for _, line in ipairs(lines) do
width = math.max(width, #line)
end
local height = #lines
local opts = {
relative = 'editor',
width = width + 4,
height = height + 2,
row = (vim.o.lines - height) / 2 - 1,
col = (vim.o.columns - width) / 2,
style = 'minimal',
border = 'rounded',
}
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
vim.api.nvim_open_win(bufnr, true, opts)

-- Bind 'q' to close the window
vim.api.nvim_buf_set_keymap(
bufnr,
'n',
'q',
'<cmd>close<CR>',
{ noremap = true, silent = true }
)
end, {
nargs = '*',
range = true,
})
end

return M
6 changes: 6 additions & 0 deletions lua/hurl/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ local log = require('hurl.vlog')

local util = {}

--- Get the log file path
---@return string
util.get_log_file_path = function()
return log.get_log_file()
end

--- Log info
---@vararg any
util.log_info = function(...)
Expand Down
6 changes: 5 additions & 1 deletion lua/hurl/vlog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ local log = {}

local unpack = unpack or table.unpack

log.get_log_file = function()
return string.format('%s/%s.log', vim.fn.stdpath('state'), default_config.plugin)
end

log.new = function(config, standalone)
config = vim.tbl_deep_extend('force', default_config, config)

local outfile = string.format('%s/%s.log', vim.fn.stdpath('cache'), config.plugin)
local outfile = log.get_log_file()

local obj
if standalone then
Expand Down

0 comments on commit 321305e

Please sign in to comment.