generated from nvimdev/nvim-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use split instead of quickfix
- Loading branch information
Showing
7 changed files
with
124 additions
and
51 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
local Split = require('nui.split') | ||
local event = require('nui.utils.autocmd').event | ||
|
||
local split = Split({ | ||
relative = 'editor', | ||
position = 'bottom', | ||
size = '30%', | ||
}) | ||
|
||
local utils = require('hurl.utils') | ||
|
||
local M = {} | ||
|
||
-- Show content in a popup | ||
---@param data table | ||
--- - body string | ||
--- - headers table | ||
---@param type 'json' | 'html' | ||
M.show = function(data, type) | ||
-- mount/open the component | ||
split:mount() | ||
|
||
-- unmount component when cursor leaves buffer | ||
split:on(event.BufLeave, function() | ||
split:unmount() | ||
end) | ||
|
||
-- Add headers to the top | ||
local headers_table = utils.render_header_table(data.headers) | ||
-- Hide header block if empty headers | ||
if headers_table.line == 0 then | ||
utils.log('no headers') | ||
else | ||
if headers_table.line > 0 then | ||
vim.api.nvim_buf_set_lines(split.bufnr, 0, 1, false, headers_table.headers) | ||
end | ||
end | ||
|
||
local content = utils.format(data.body, type) | ||
if not content then | ||
return | ||
end | ||
|
||
-- Set content to highlight | ||
vim.api.nvim_buf_set_option(split.bufnr, 'filetype', type) | ||
|
||
-- Add content to the bottom | ||
vim.api.nvim_buf_set_lines(split.bufnr, headers_table.line, -1, false, content) | ||
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